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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10181576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:49:26  来源:igfitidea点击:

Pyserial: could not configure port: (5, 'Input/output error)

pythonlinuxubuntupyserial

提问by Donagh

I've been trying to get the following two lines of Python code to run for the past two days, without much success:

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

import serial
ser = serial.Serial(0)

Each time I run it, I get the following error:

每次运行它时,都会出现以下错误:

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')

I'm running Ubuntu 11.10 64-bit, with Pyserial 2.5 (python-serial 2.5-2.1) and Python 2.7 (python 2.7.2-7ubuntu2) and my user is a member of the dialout group.

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

I run Ubuntu 11.10 64-bit at work too, with the same versions of Python and Pyserial, and the problem doesn't seem to occur there. Any suggestions are welcome - I'm pretty flummoxed...

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

Thanks, Donagh

谢谢,多纳

采纳答案by phihag

This exception is thrown if the port is not available. On Linux, you can simply specify the exact name of the port to use, like

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

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