无法在 Pyserial 中打开串行连接:“termios.error: (22, “无效参数”)”
我在执行以下代码时遇到问题:
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()
这昨天有效,但我不知道我更改了什么。现在我收到以下错误消息:
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 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')
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我遇到了同样的问题,尽管我使用的是 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.
港口还在吗?我的意思是
/dev/tty.FireFly-16CB-SPP
。今天它可能有一个新名字......Is the port still there? I meen
/dev/tty.FireFly-16CB-SPP
. It could have a new name today...试试这个:
你不必调用 open() ,除非你手动更改了端口的配置,例如:
完成后不要忘记 cles 端口
Try this :
you dont have to call open() unless you changed the configuration of the port manually eg:
and don't forget to cles the port when you are done with it
重新安装Python并降级到2.6,这解决了一切。
Reinstalled Python and downgraded to 2.6 which solved everything.
我有同样的问题。
只需运行 pySerial 示例 (http://sourceforge.net/projects/pyserial/develop) 中的 miniterm.py 即可。
它在 shell 中运行良好: python miniterm -p ttyUSB0 -D
但是当尝试将其加载到 Eclipse 中时。并从那里运行调试。
它给了我:
I have the same problem.
Just run the miniterm.py from pySerial examples (http://sourceforge.net/projects/pyserial/develop) .
It ran fine from shell: python miniterm -p ttyUSB0 -D
but when tried to load it into Eclipse. and run debug from there.
it gave me:
我在 OSX 上遇到了这个问题,问题最终是不支持波特率。将波特率更改为更常见的波特率并且成功了!
I had this problem on OSX, and the problem ended up being the baud rate was not supported. Changed the baud rate to something more common and it worked!