gpt4 book ai didi

macos - 列出 Mac OS X 和 Python 3 中的串行端口

转载 作者:行者123 更新时间:2023-12-02 03:09:10 25 4
gpt4 key购买 nike

我在列出可用串行端口时遇到问题,我确实需要帮助调试它。在 Python 2.7.5 中,COM 端口正确列出,而 PySerial 在 Python 3.3.5 中返回空列表。

我在互联网上发现了另一个孤独的灵魂也有同样的问题(没有答案),但这个问题似乎根本不受欢迎 - 也许是我的系统问题?

我使用的是 Mac OS X 10.9.2 并通过 homebrew 安装了 python 和 python3。我刚才更新了一切。 PySerial 在 pip 和 pip3 中的版本均为 2.7。

输出:

Python 2.7.5 (default, Nov  4 2013, 18:04:45) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from serial.tools import list_ports
>>> list_ports.comports()
[['/dev/cu.Bluetooth-Incoming-Port', 'n/a', 'n/a'], ['/dev/cu.Bluetooth-Modem', 'n/a', 'n/a']]

Python 3.3.5 (default, Mar 10 2014, 13:25:50)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from serial.tools import list_ports
>>> list_ports.comports()
[]

最佳答案

目前我正在采用以下方法。 PySerial 工具已损坏。

>>> import glob
>>> glob.glob('/dev/tty.*')
['/dev/tty.Bluetooth-Incoming-Port', '/dev/tty.Bluetooth-Modem']

关于macos - 列出 Mac OS X 和 Python 3 中的串行端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22467683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com