我正在尝试测试pySerial以从COM5中读取内容,我在线查找了一些示例代码,我已经使用pip命令安装了pySerial,但出现了以下错误提示:
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)
这是我要作为测试目的运行的代码:
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()
我的目的是使她能够正确无误地收听COM5,然后我将添加一些代码来详细说明数据,但现在我还是刚开始。