我正在尝试使用 python 和 hidapi 模块控制 USB HID 设备(用于气象站的 RF 收发器加密狗),但我无法打开该设备,也无法在使用
hid.enumerate
时显示。
我能够使用 pyusb 找到并连接到设备并查看描述符我注意到接口类是 0x03 (HID),但设备类也是 0x03 而不是 0x00(在接口处指定),因为我有阅读它应该是。
此设备是否不符合 HID 规范。这可能是 hidapi 找不到设备的原因吗?否则,据我所知,该设备的行为就像一个普通的 HID 设备,我能够使用 pyusb 和控制传输从接口读取 HID 描述符。
有没有办法让 hidapi 连接到设备并忽略错误的设备类(如果这是问题所在)?如果可能的话,我宁愿使用更专业的 hidapi 而不是使用 pyusb。
DEVICE ID 6666:5555 on Bus 001 Address 001 =================
bLength : 0x12 (18 bytes)
bDescriptorType : 0x1 Device
bcdUSB : 0x200 USB 2.0
bDeviceClass : 0x3
bDeviceSubClass : 0x0
bDeviceProtocol : 0xff
bMaxPacketSize0 : 0x40 (64 bytes)
idVendor : 0x6666
idProduct : 0x5555
bcdDevice : 0x100 Device 1.0
iManufacturer : 0x1 LA CROSSE TECHNOLOGY
iProduct : 0x2 Weather Direct Light Wireless Device
iSerialNumber : 0x3 0123456
bNumConfigurations : 0x1
CONFIGURATION 1: 30 mA ===================================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x2 Configuration
wTotalLength : 0x22 (34 bytes)
bNumInterfaces : 0x1
bConfigurationValue : 0x1
iConfiguration : 0x0
bmAttributes : 0x80 Bus Powered
bMaxPower : 0xf (30 mA)
INTERFACE 0: Human Interface Device ====================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x4 Interface
bInterfaceNumber : 0x0
bAlternateSetting : 0x0
bNumEndpoints : 0x1
bInterfaceClass : 0x3 Human Interface Device
bInterfaceSubClass : 0x0
bInterfaceProtocol : 0x0
iInterface : 0x0
ENDPOINT 0x81: Interrupt IN ==========================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x81 IN
bmAttributes : 0x3 Interrupt
wMaxPacketSize : 0x40 (64 bytes)
bInterval : 0x20
According to the HID spec and USB Defined Class Codes list -
bDeviceClass
确实不应该是 0x3
:
注意设备描述符中的 bDeviceClass 和 bDeviceSubClass 字段 不应用于将设备标识为属于 HID 类。而是使用接口描述符中的 bInterfaceClass 和 bInterfaceSubClass 字段。
这确实会导致操作系统对该设备的错误解释。我可以假设的唯一解决方法是自定义驱动程序,它将包装此设备并修补其 USB 设备描述符。这是此类驱动程序的示例:https://github.com/microsoft/Windows-driver-samples/tree/main/hid/hidusbfx2