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

旧巷老猫 提交于 2019-12-10 14:49:33

问题


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

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.

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...

Thanks, Donagh


回答1:


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

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


来源:https://stackoverflow.com/questions/10181576/pyserial-could-not-configure-port-5-input-output-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!