无法在 Pyserial 中打开串行连接:"termios.error: (22, 'Invalid argument') " [英] Can't open serial connection in Pyserial: "termios.error: (22, 'Invalid argument') "
问题描述
我在执行以下代码时遇到问题:
I'm having problem executing the following code:
import serial
ser = serial.Serial(
port='/dev/tty.FireFly-16CB-SPP',
baudrate=115200,
#parity=serial.PARITY_ODD,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
ser.open()
ser.isOpen()
昨天成功了,我不知道我改变了什么.现在我收到以下错误消息:
This worked yesterday, and I don't know what I changed. Now I get the following error message:
Traceback (most recent call last):
File "main.py", line 32, in <module>
bytesize=serial.EIGHTBITS
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/serial/serialutil.py", line 260, in __init__
self.open()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/serial/serialposix.py", line 280, in open
self._reconfigurePort()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/serial/serialposix.py", line 409, in _reconfigurePort
termios.tcsetattr(self.fd, TERMIOS.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
termios.error: (22, 'Invalid argument')
我是 Python 的完全初学者,无法解读上面的错误消息.我试过重新安装 Pyserial,但这并没有解决错误.怎么了?
I'm a complete beginner to Python, and can't decipher the error message above. I've tried reinstalling Pyserial, but that didn't fix the error. What is wrong?
推荐答案
我遇到了同样的问题,虽然我使用的是一个 5 端口 USB 集线器,其中插入了 3 个不同的 USB,但结果发现集线器不是提供足够的电力.一旦我得到了一个外部供电的 USB(一个不仅仅是从我的计算机端口上拔掉线路的),它就可以正常工作.
I had the same issue, though I was using a 5 port USB hub with 3 different USBs all plugged into it, and it turned out the hub wasn't providing enough power. Once I got an externally powered USB (one that wasn't just pulling off the line from my computer's port) it worked just fine.
这篇关于无法在 Pyserial 中打开串行连接:"termios.error: (22, 'Invalid argument') "的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!