python - pyserial 使用 serial.tools.list_ports.grep() 找不到设备
问题描述
我有一个 USB 设备(基于 STM32F4 微控制器),在 USB 描述符中设置了 VID、PID 和产品描述。
VID = 0x0483
PID = 0x5740
Product Description = "ACME thing-a-me-bob"
在 macOS 上,使用serial.tools.list_ports.grep()
可以很好地定位我的设备。例如p = grep("thing-a-me-bob")
或 `p = grep("ACME")
但是在 Windows (Win 10) 上,grep 找不到我的设备。如果我使用grep("")
它,它会列出我的设备(以及所有其他设备),但它只显示:
COM3 - USB Serial Device (COM3)
该设备仅使用 Win 10 附带的标准 Microsoft CDC 驱动程序。然而,我认为简单/标准认为产品描述字符串将从 USB 设备读取并使用(就像标准 macOS 驱动程序一样)。
有没有办法serial.tools.list_ports.grep()
使用标准的 Windows 驱动程序?
注意:grep("0483:5740")
确实找到了我的设备,但这是一组合理常用的 VID:PID 值,由 ST Micro 提供。
解决方案
不知道如何grep()
工作,但你可以像这样连接。
if sys.platform == 'win32':
ports = list(list_ports.comports())
for port in ports:
# query each port and connect if description is found
if 'ACME thing-a-me-bob' in port.description:
s = serial.Serial(port.device)
推荐阅读
- automation - 有没有办法让测试让它的 TestCaseSource 从外部源(如 excel)读取数据?
- node.js - npm 开始显示 index.html 未定义,尽管 index.html 存在
- python - 如何从复杂的验证码中提取数字
- c - 试图用空格分割 C 中的字符串并使用第二个单词
- vba - Powerpoint VBA - 如何在“形状内”存储信息?
- apache-camel - 为什么camel route中bean的一个参数是exchange的body值?
- image-processing - 可以使用morphology.remove_small_objects 去除小噪声吗?
- r - 如何将大量 igraph 组合成一个 igraph - R
- elasticsearch - Elasticsearch 不对双字段进行排序
- visualization - 在 spotfire 中添加新行