您好,我在与此动物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();
}
}
您知道问题出在哪里吗?
感谢所有答案。
最佳答案
我不知道这是否有帮助,但是当我看着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切换端口的实用程序