您好,我与这款动物RFID标签阅读器的沟通存在一些问题。 我正在使用Rasperry Pi,Java和PI4J。 我根据文档向读者发送命令:http://www.priority1design.com.au/rfidrw-e-usb.pdf
我尝试打开/关闭LED,获取固件版本和许多其他命令。我仍然得到答案0x00(命令不明白。)
这是我的主要方法:
public static void main(String[] args) {
final Serial serial = SerialFactory.createInstance();
try {
serial.open(Serial.DEFAULT_COM_PORT, 9600);
serial.addListener(new SerialDataListener() {
@Override
public void dataReceived(SerialDataEvent event) {
try {
String data = event.getData();
byte[] array = data.getBytes("US-ASCII");
String s = "";
System.out.println("Read: ");
for (int i = 0; i < array.length; i++) {
s = s + String.format("%02X ", array[i]);
}
System.out.println(s);
} catch (UnsupportedEncodingException ex) {
}
}
});
//byte [] data = "VER".getBytes("US-ASCII");
String data = "VER";
//byte [] data = {(byte) 0x56,(byte) 0x45,(byte) 0x52};
serial.write(data);
//serial.write("\r");
Thread.sleep(3000);
System.out.println("done");
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
serial.close();
}
}
你知道问题出在哪里吗? 谢谢你的所有答案。
答案 0 :(得分:0)
我不知道这是否有帮助,但是当我查看pi4j Serial example page
时它暗示了这一点,我想知道你是否尝试过禁用COM端口作为控制台?
// !! ATTENTION !!
// By default, the serial port is configured as a console port
// for interacting with the Linux OS shell. If you want to use
// the serial port in a software program, you must disable the
// OS from using this port. Please see this blog article by
// Clayton Smith for step-by-step instructions on how to disable
// the OS console for this port:
// http://www.irrational.net/2012/04/19/using-the-raspberry-pis-serial-port/
似乎还存在一个用于从控制台https://github.com/lurch/rpi-serial-console
切换端口的实用程序