创建串行端口的Python错误

问题描述 投票:1回答:1

我在运行python脚本时遇到问题。 python脚本读取一个串行端口。运行脚本时出现以下错误

File "C:\Python26\lib\site-packages\serial\serialwin32.py", line 268, in flushInput
 if not self.hComPort: raise portNotOpenError
 ValueError: Attempting to use a port that is not open

我创建串行端口的python脚本是

ser = serial.Serial(11, 115200,timeout=1)
ser.setWriteTimeout(1)
print ser.portstr
ser.flushInput()
ser.flushOutput()

我在ser.flushInput()中遇到错误

任何人都可以让我知道为什么会产生此错误以及如何解决此问题吗?

python pyserial
1个回答
0
投票

尝试使用此程序让程序检查端口是否打开。

if ser.isOpen():
    print("Port: " + ser.portstr + " is open.\n")
© www.soinside.com 2019 - 2024. All rights reserved.