>我正在使用JSSC从串行端口读取值。一旦我写入串行端口,就会调用以下回调。 在该回调中,我可以从事件中获取值,并且从串行端口本身都包含不同的值。 我想知道串行端口值和串行事件值之间的区别 事件是否包含来自串行端口的值?
public class PortReader implements SerialPortEventListener {
SerialPort serialPort;
public PortReader(SerialPort serialPort) {
this.serialPort = serialPort;
}
@Override
public void serialEvent(SerialPortEvent event) {
System.out.println("started");
if (event.isRXCHAR() && event.getEventValue() > 0) {
try {
String receivedData = serialPort.readString(event.getEventValue());
System.out.println("Received response: " + receivedData);
receivedData = serialPort.readString();
System.out.println("Received response: " + receivedData);
} catch (SerialPortException ex) {
System.out.println("Error in receiving string from COM-port: " + ex);
}
}
}
}
根据JSSC的文档,事件值是JSSC特定的,而事件携带的数据来自串行端口。