我正在尝试使用 java 将十六进制数据写入我的串行端口,但现在我无法将十六进制数据转换为字节数组。
这是显示错误消息的代码:
static byte[] bytearray = {0x02, 0x08, 0x16, 0x0, 0x00, 0x33, 0xC6, 0x1B};
这是写入串口的代码:
try {
outputStream = serialPort.getOutputStream();
// Write the stream of data conforming to PC to reader protocol
outputStream.write(bytearray);
outputStream.flush();
System.out.println("The following bytes are being written");
for(int i=0; i<bytearray.length; i++){
System.out.println(bytearray[i]);
System.out.println("Tag will be read when its in the field of the reader");
}
} catch (IOException e) {}
我能知道我该如何解决这个问题。目前我正在使用 javax.comm 插件。谢谢你。