recover after serialException
Brought to you by:
cliechti
I'm using pySerial successfully to connect to a USB port and talk to a custom device. The difficulty I'm having is if I should happen to lose my connection (the cable is pulled out from the port) once the connection is re-established I can not clear everything and reconnect, I have to clear everything, unplug the cable and then plug it back in. Nothing software related seems to help and I continue to get this message:
serial.serialutil.SerialException: could not open port COM5: [Error 2] The system cannot find the file specified.
until I unplug and plug it back in.
Thanks,
Stephen
I think that is a problem with the OS, that keeps the old device active while it is still in use by a program, even if the hardware is removed. When the hardware is re-attached, it may event get assigned a different COM port.
The only solution I have is trying to close the serial port in case of an error, so that the device is no longer in use when the cable is plugged in again.