Serial connection lost

diego

Member
Licensed User
Longtime User
Hi, I'm using Serial2 to connect via USB, sometimes I lost the connection (for example unplugging USB cable), but B4PPC "thinks" that the port is still open, so I get strange behaviour, communication is broken but no Error-Event is fired.

Any suggestion to handle this?

(I'm using Desktop Serial2.dll)
 
Last edited:

diego

Member
Licensed User
Longtime User
That's right, the port is open because of the virtual COM port.
I'll try the ping workaround, great idea! :sign0060:

To break and reconnect would it be enough like this?

B4X:
Serial.PortOpen = False
Serial.PortOpen = True
 

agraham

Expert
Licensed User
Longtime User
I recommend using my SerialEx library instead of Serial2 which has several issues as documented in the Overview topic of the SerialEx help.

Have you checked what happens to CTS and DSR when you unplug the USB adaptor? Note that SerialEx can raise events when the pin states change so you might be able to detect when the connection goes down this way.
 

diego

Member
Licensed User
Longtime User
Thank you Andrew, better solution, I hope!

My serial device is an Arduino Uno, so I don't know the state of DB9 pins, since serial-to-usb is already in the board.
 

diego

Member
Licensed User
Longtime User
I tried SerialEx library, no event is raised when USB is unplugged, I set serial.EnableOnError = True and serial.EnableOnPinChanged = True
and msgbox in Serial_OnError and Serial_OnPinChanged, and in debug mode, CTS and DSR are "false" and OnErrorReason and OnPinChangedReason are "0".
 
Top