I'm trying to test pySerial to read from COM5, I've looked up some sample code online, I've installed pySerial using pip command but I get the folliwing error:
c:\Serial Test>link.py
Traceback (most recent call last):
File "C:\Serial Test\link.py", line 9, in <module>
timeout=0)
File "C:\Python36\lib\site-packages\serial\serialwin32.py", line 31, in __init__
super(Serial, self).__init__(*args, **kwargs)
File "C:\Python36\lib\site-packages\serial\serialutil.py", line 240, in __init__
self.open()
File "C:\Python36\lib\site-packages\serial\serialwin32.py", line 62, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM5': FileNotFoundError(2, 'Impossibile trovare il file specificato.', None, 2)
This is the code I'm trying to run as a test purpose:
import serial
ser = serial.Serial(
port='COM5',\
baudrate=9600,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
timeout=0)
print("connected to: " + ser.portstr);
count=0
while count <100:
line=ser.readline()
print (line)
count+=1
ser.close()
My purpose her is just being able to listen to COM5 without error, then I'll add some code to elaborate the data, but for now I'm stuck at very beginning.