Python Forum
Cannot attach to com port with Pyserial
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot attach to com port with Pyserial
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  is there a way to mention port range or search for port dynamically with qConnection Creepy 0 1,449 Sep-09-2021, 03:15 PM
Last Post: Creepy
  Is it possible to attach to an open existing Browser? tommytx 7 2,982 Apr-27-2020, 12:40 AM
Last Post: tommytx
  Problem with updating file to attach/pynput jameseroni 7 4,402 Nov-02-2018, 03:47 AM
Last Post: jameseroni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020