Chuang come fromTaiwan
Chuang come fromTaiwan

Reputation: 173

I get garbled message from RS232 to bluetooth

Equipment message :"'14/08/06"

bytes = mmInStream.read(buffer);
char c = 0;
for(int i=0;i<buffer.length;i++)
{
   int value = buffer[i];   
   Log.e(tag,"WORD="+value);                    
   c= (char)value; 


}

finally some word will be garbled (become negative),some word can show that follow ASCII

WORD=34
WORD=39
**WORD=-79
WORD=-76
WORD=-81**
WORD=48
......etc

become => 'ᄆᄡᆵ0ᄌᆵ0ᄋ"ᆲ"ᄆ6...

Upvotes: 0

Views: 79

Answers (1)

Rawa
Rawa

Reputation: 13926

The output is not garbled, it is signed bytes.

A byte in java is a signed byte; Byte.MAX_VALUE = 127, Byte.MIN_VALUE = -128.

WORD=-79 + 128 = 49 in ASCII 1
WORD=-76 + 128 = 52 in ASCII 4
WORD=-81 + 128 = 47 in ASCII /

Upvotes: 1

Related Questions