This is a simple script to test if the com port is working or not.
from serial import Serial from serial.serialutil import SerialException try: with Serial(port='COM4', baudrate=9600, parity='N', stopbits=1, bytesize=8, timeout=8) as console: if console.isOpen(): print("{} is working".format(console.port)) except SerialException: print("The com port could be in used or not exists.")
The SerialException
will invoke PermissionError
if the current com port you try to open with this script is in used.
If the SerialException
invokes FileNotFoundError
then it is highly the com port you requested with the script is not installed, check your device manager to make sure the com port number is correct.