首页 > 解决方案 > 通过 USB 与 python 通信

问题描述

所以,我有一根 USB 转串口线。它的串行部分连接到 Raspberry Pi 4,我希望它的 USB 部分连接到我的 Windows 笔记本电脑,以便它们可以使用 python 相互通信。Windows 可以检测到端口上的设备,但它无法读取任何通过的数据。

我目前正在尝试将 libusb1 与 python 一起使用:

vendorId = 0x25A7
prodctId = 0xFA67

import usb1
with usb1.USBContext() as context:
    handle = context.openByVendorIDAndProductID(
        vendorId,
        prodctId,
        skip_on_error=True,
    )
    if handle is None:
        print("Device not present, or user is not allowed to access device.")
    with handle.claimInterface(INTERFACE):
        # Do stuff
        pass

但是使用此代码,它会给出 libusb 无法识别设备的错误。 usb1.USBErrorNotSupported: LIBUSB_ERROR_NOT_SUPPORTED [-12]

有没有办法让它与 libusb 兼容?还是有其他更好的方法来解决这个问题?

标签: pythonlibusb

解决方案


推荐阅读