所以我正在尝试读取连接到 com 端口的串行设备的数据。 现在我弄清楚了阅读部分,但我想知道的是如何识别连接的设备是我的设备还是其他设备,例如鼠标或键盘。 作为引用,我正在使用 jssc
非常感谢!
下面使用 Jssc 从我的 rfid 阅读器读取 rfid 标签
public static void main(String[] args) {
SerialPort serialPort = new SerialPort("COM1");
try {
serialPort.openPort();//Open serial port
byte[] buffer = serialPort.readBytes(12);
serialPort.closePort();//Close serial port
}
catch (SerialPortException ex) {
System.out.println(ex);
}
}
最佳答案
不确定我是否正确理解您的意图,但您可以使用 AT 命令获取设备信息,例如
serialPort.writeString(String.format("ATI%n"));
发送命令后请务必等待,然后再尝试从设备读取答案。
关于Java串行编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16729224/