I have a barcode scanner which is sending me raw output. I am trying to figure out what that output is.
I receive an array of bytes. If I display them directly as a string:
byte[] buffer = new byte[1024]; // buffer store for the stream
int bytes; // bytes returned from read()
// Keep listening to the InputStream until an exception occurs
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
mDisplayer.display(new String(buffer));
} catch (IOException e) {
break;
}
}
I get this:
(4}�����A���L�*��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
Now if I change the display code to the following:
String numberToDisplay = "";
// Read from the InputStream
bytes = mmInStream.read(buffer);
for (int i=0; i<bytes; i++ ) {
numberToDisplay = numberToDisplay.concat(Integer.toString((int)buffer[i] & 0xff));
}
mDisplayer.display(numberToDisplay);
I get this:
1628405212513714915817024765139151223217614142
But the actual number under the barcode is:
0003001095504
So how can I get it to read it properly?
EDIT:
If I display the bytes I get this:
00010000 (10)
00011100 (1C)
00101000 (28)
00110100 (34)
01111101 (7D)
10001001 (89)
10010101 (95)
10011110 (9E)
10101010 (AA)
11110111 (F7)
01000001 (41)
10001011 (8B)
10010111 (97)
11011111 (DF)
00010101 (15)
01001100 (4C)
10001101 (8D)
00101010 (2A)
Make sure you enabled "SPP" on the Bluetooth Device.
/** For this data to be *right* you must enable SPP mode on the barcode scanner. */
numberToDisplay = new String(buffer, 0 , bytes);