0
字符串Serial_Input必須包含與此A45F45A7(8字節)類似的序列號卡RFID(MIFARE)。有時當我將卡接近arduino的RFID閱讀器時,字符串就像這個A45F45(截斷),錯過任何字符。有更好的解決方案,而循環? (更優雅高效)使用Arduino IDE串行監視器,該卡的序列號是正確的。使用JAVA和jssc lib從Arduino串行端口讀取字符串
public static void connectionToCom(SerialPort serialPort, ComboBox<String> cbxComPort, TextArea txaMessages) throws SerialPortException
{
int baudrate = 9600; int databits = 8; int stopbits = 1; int parity = 0;
serialPort.openPort() ;
serialPort.setParams(baudrate, databits, stopbits, parity) ;
String Serial_Input = null;
try {
while (true)
{
if (serialPort.readString() != null)
{
Serial_Input = serialPort.readString(8);
System.out.println("Card Serial: " + Serial_Input + "\n");
//serialPort.closePort();
}
}
}
catch (SerialPortException ex){
txaMessages.appendText(ex.toString());
}
}