Closed VaibhavDhopate closed 8 months ago
Please use the most recent release version (v2.10.3) and report back if this is still an issue.
thank you will check with latest version and will report. we are suspeting frequently open close serial port conenction causing issue did you came accrss any such scenario ? and what is your remondation in such implemntation
@hedgecrw updated jserailcomm version 2.10.3 still it is happing jserailcomm : 2.10.3 platfomr : windows (to resolve this need to reboot/unplug the usb connted device
Circling back to this. Are you using any data listeners in your project? If so, could you post the code for your serialEvent()
callback function?
I'm not sure if its the same case but I will explain it here and you will decide if I have to open a separate issue:
jSerialComm 2.9.3 and 2.10.4
It seems that commands sent to COM(X) are accepted only the first time. If I try to send the same command for a second time ... nothing happens ( no logs from my impl of PaymentDoneListener and motherboard diodes do not blink ) unless I switch the com ports or unplug/plug back the same com port ( but even then, it sends a command just once )
When I switch to Windows 10 it's working each time.
Same with the latest version of jSerialComm 2.10.4
` public class PaymentDoneListenerImpl implements PaymentDoneListener {
private static final Logger LOGGER = LoggerFactory.getLogger(PaymentDoneListenerImpl.class);
private static final int PAYMENT_DONE = 67;
private static final int BUSY = 64;
private final SerialPort serialComPort;
private boolean paymentDone = false;
public PaymentDoneListenerImpl(SerialPort serialComPort) {
this.serialComPort = serialComPort;
}
@Override
public int getListeningEvents() {
return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
}
@Override
public void serialEvent(SerialPortEvent event) {
newDataFromEventIfPossible(event).ifPresent(newData -> {
flagIfBusy(newData);
flagIfPaymentDone(newData);
});
}
public boolean isPaymentDone() {
return paymentDone;
}
public void finishPayment(){
paymentDone = false;
}
private Optional<byte[]> newDataFromEventIfPossible(SerialPortEvent event) {
if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE) {
return Optional.empty();
}
return Optional.of(newData());
}
private byte[] newData() {
byte[] newData = new byte[serialComPort.bytesAvailable()];
LOGGER.info("Read {}, bytes: {}", serialComPort.readBytes(newData, newData.length), Arrays.toString(newData));
return newData;
}
private void flagIfPaymentDone(byte[] newData) {
if (newData[1] == PAYMENT_DONE) {
paymentDone = true;
LOGGER.info("Payment done");
}
}
private void flagIfBusy(byte[] newData) {
if (newData[1] == BUSY) {
paymentDone = false;
LOGGER.info("Busy ...");
}
}
}
`
For those who meet this issue for ch340 chip on Windows 11, it's the built in driver problem of OS, close port just doesn't work, the OS will return error code 31 afterwards until re-plug the port.
Installing official driver provided by chip manufacture finally solved this issue. Keywords: CH341SER.EXE
Great, thanks for the update. This will definitely help others in the future!
USB device randomly close connection takse time approx 5 min to get out from commPort.closePort() -- method and after that subsequent port open request fails after reboot conencted device it again works proeprly, As usb communication is critical piece of funcationality and rebooting device is not feasible in every situation.
jSerialComm verison : 2.9.2 Platform : windows