PySerial报告“资源繁忙”,看似未使用的串行端口

问题描述 投票:0回答:1

我正在尝试使用PySerial打开与USB设备的串行连接,并使用以下代码出现以下错误:

import serial
ser = serial.Serial('/dev/tty.usbserial-EN270425')
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
OSError: [Errno 16] Resource busy: '/dev/tty.usbserial-EN270425'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    ser = serial.Serial('/dev/tty.usbserial-EN270425')
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/serial/serialutil.py", line 240, in __init__
    self.open()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 16] could not open port /dev/tty.usbserial-EN270425: [Errno 16] Resource busy: '/dev/tty.usbserial-EN270425'

我已经检查过是否有使用资源通过lsof | grep "/dev/tty.usbserial-EN270425",没有返回值。

我能够连接到另一台计算机上的端口,唯一的区别是操作系统和python版本。 CAN连接的计算机正在运行Mac OS Mojave和Python 3.6,CANNOT连接的计算机正在运行Mac OS Catalina和Python 3.8。有人对我从这里前进的方向有任何想法吗?

python macos serial-port usb pyserial
1个回答
0
投票

我有同样的问题。问题不在于python或您的代码,而是USB串行设备的驱动程序,因此请确保已安装正确的驱动程序。

在我的情况下,这是FTDI串行电缆。我通过从here安装官方FTDI驱动程序来解决此问题。询问时,请确保允许在“系统偏好设置”中进行访问。我还必须重新启动USB并断开/重新连接几次,然后才能使用。

驱动程序一旦工作,与OP相同的代码就应该工作

© www.soinside.com 2019 - 2024. All rights reserved.