usbhid.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:rivalcfg 作者: flozz 项目源码 文件源码
def open_device(vendor_id, product_id, interface_number):
    """Opens and returns the HID device (file-like object). Raise IOError if
    the device or interface is not available.

    Arguments:
    vendor_id -- the mouse vendor id (e.g. 0x1038)
    product_id -- the mouse product id (e.g. 0x1710)
    interface_number -- the interface number (e.g. 0x00)
    """
    # Dry run
    if debug.DEBUG and debug.DRY and is_device_plugged(vendor_id, product_id):
        device = BytesIO()  # Moke the device
        device.send_feature_report = device.write
        return device

    # Real device
    for interface in hid.enumerate(vendor_id, product_id):
        if interface["interface_number"] != interface_number:
            continue
        device = hid.device()
        device.open_path(interface["path"])
        return device

    raise IOError("Unable to find the requested device: %04X:%04X:%02X" % (
        vendor_id, product_id, interface_number))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号