Python Forum
Cannot attach to com port with Pyserial - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Cannot attach to com port with Pyserial (/thread-6300.html)



Cannot attach to com port with Pyserial - sabdulqadir - Nov-15-2017

I am using a microcontroller to send some data to a PC using Virtual Com Port (USB interface). I am using pyserial to receive the data on the PC. I am having issues with the com port. Sometimes, I am able to connect to it, but other times I am not (even if I restart my PC). Would anyone here be able to advice?
My code to attach to serial port:
while True:
    try:
        ser_handler = ser.Serial(port= "com4", baudrate=115200, bytesize=ser.EIGHTBITS, parity=ser.PARITY_NONE, stopbits=ser.STOPBITS_ONE, timeout=None, xonxoff=False, rtscts=False, write_timeout=None, dsrdtr=False, inter_byte_timeout=None, exclusive=None)
        break
    except ser.SerialException as excp:
        print('Serial Exception')
        print (excp.args)
        time.sleep(2)
    else:
        print('Some other error')
        time.sleep(2)
The error I get:
Error:
Serial Exception ("Cannot configure port, something went wrong. Original message: OSError(22, 'The parameter is incorrect.', None, 87)",)
I know it has something to do with the release of com port. Any help would be appreciated.
Thanks,
AQ