Pyserial:无法配置端口:(5,'输入/输出错误)

Posted

技术标签:

【中文标题】Pyserial:无法配置端口:(5,\'输入/输出错误)【英文标题】:Pyserial: could not configure port: (5, 'Input/output error)Pyserial:无法配置端口:(5,'输入/输出错误) 【发布时间】:2012-04-16 20:54:29 【问题描述】:

过去两天我一直在尝试让以下两行 Python 代码运行,但没有取得多大成功:

import serial
ser = serial.Serial(0)

每次运行时,我都会收到以下错误:

Traceback (most recent call last):
  File "./test.py", line 4, in <module>
    ser = serial.Serial(0)
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 260, in __init__
    self.open()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 280, in open
    self._reconfigurePort()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 308, in _reconfigurePort
    raise SerialException("Could not configure port: %s" % msg)
serial.serialutil.SerialException: Could not configure port: (5, 'Input/output error')

我正在运行 Ubuntu 11.10 64 位,使用 Pyserial 2.5 (python-serial 2.5-2.1) 和 Python 2.7 (python 2.7.2-7ubuntu2),我的用户是拨出组的成员。

我也在工作中运行 Ubuntu 11.10 64 位,使用相同版本的 Python 和 Pyserial,问题似乎没有出现在那里。欢迎任何建议 - 我很困惑......

谢谢, 多纳

【问题讨论】:

【参考方案1】:

如果端口不可用,则会引发此异常。在 Linux 上,您可以简单地指定要使用的端口的确切名称,例如

ser = serial.Serial('/dev/ttyACM0')

【讨论】:

感谢您的快速回复。在我的系统上,格式是 /dev/ttyS#,其中 # 在 [0,31] 中。我已经尝试了 ser = serial.Serial('/dev/ttyS27') 和其他一些数字,但我仍然遇到同样的错误。 请注意,设备可能在那里,但没有连接到任何东西。这不是 pyserial 的特殊行为,您可以运行 cat /dev/ttyS0 来查看相同的内容。是什么让您认为至少连接了一个串行端口?是什么让你认为那是/dev/ttyS0 啊哈!这正是问题所在!几天前我才开始玩 Pyserial(我一直在尝试设置一个虚拟端口)。我从来没有想过我需要物理连接。实时调频。我的错。感谢您的所有帮助! ^,我在 Ubuntu 14.04 和 15.04 上遇到了同样的问题。你需要什么样的物理连接?

以上是关于Pyserial:无法配置端口:(5,'输入/输出错误)的主要内容,如果未能解决你的问题,请参考以下文章

linux-pyserial:无法打开端口 /dev/ttyAMA0 没有这样的文件或目录

无法多次写入同一端口(pyserial)

pySerial 运行命令列出端口

使用pyserial测试usb到串口到usb没有输出

不能多次写入同一个端口(pyserial)

无法使用 python 和 pyserial 打开 /dev/ttyusb0