无法打开串口Python

时间:2016-04-08 14:54:19

标签: python

我在使用Python代码在Windows 7中打开串行USB端口时遇到问题。

TeraTerm和Docklight能够毫无问题地打开端口。

当我尝试打开端口时,会出现以下错误

SerialException:无法配置端口,出错了。原始消息:WindowsError(31,'连接到系统的设备无法正常运行。')

我需要知道我是否正在使用正确的串行库。也许有一个可以打开它而不会弄乱操作系统。

以下代码返回上面的错误

ser = serial.Serial()
ser.port = 'COM5'

ser.open()

整条信息如下:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 2883, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-13-882203061f11>", line 4, in <module>
    ser.open()
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 78, in open
    self._reconfigure_port()
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 220, in _reconfigure_port
    raise SerialException("Cannot configure port, something went wrong. Original message: %r" % ctypes.WinError())
SerialException: Cannot configure port, something went wrong. Original message: WindowsError(31, 'A device attached to the system is not functioning.')

感谢您的支持

1 个答案:

答案 0 :(得分:0)

这不是pyserial错误,这个lib做的是充当&#39; bridge&#39;使用ctypes在你的python代码和来自kernel32 lib的windows本机代码之间。

我的猜测是你的fimware或设备驱动程序有问题但是很好......不管怎样,WINAPI Serial api也是一个小小的错误。