【问题标题】:pyserial can't find device using serial.tools.list_ports.grep()pyserial 使用 serial.tools.list_ports.grep() 找不到设备
【发布时间】:2018-07-15 05:41:54
【问题描述】:

我有一个 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 提供。

【问题讨论】:

    标签: python windows pyserial


    【解决方案1】:

    不确定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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-19
      • 2023-03-11
      相关资源
      最近更新 更多