【问题标题】:Decoding output of bluetooth barcode scanner蓝牙条码扫描器的解码输出
【发布时间】:2014-05-19 10:53:25
【问题描述】:

我有一个条形码扫描仪,它正在向我发送原始输出。我想弄清楚那个输出是什么。

我收到一个字节数组。如果我直接将它们显示为字符串:

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;
    }
}

我明白了:

(4}�����A���L�*��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

现在,如果我将显示代码更改为以下内容:

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);

我明白了:

1628405212513714915817024765139151223217614142

但条码下的实际数字是:

0003001095504

那么我怎样才能让它正确阅读呢?

编辑

如果我显示字节,我会得到:

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)

【问题讨论】:

  • 嗨,Tom,我可以问你启动 mmInStream 的代码吗?我正在努力实现同样的目标
  • 哇,我不知道代码现在在哪里:-[]

标签: java android bluetooth barcode barcode-scanner


【解决方案1】:

确保您在蓝牙设备上启用了“SPP”。

/** For this data to be *right* you must enable SPP mode on the barcode scanner. */
numberToDisplay = new String(buffer, 0 , bytes);

【讨论】:

    猜你喜欢
    • 2021-10-08
    • 1970-01-01
    • 2019-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多