如何让USB设备注册为HID?

如何让USB设备注册为HID?

我有一个硬件设备,我想通过 HID 库用 C 语言与它进行通信。但该设备并未显示为 HID。有没有办法做到这一点(也许有 udev 规则)?

$ dmesg
usb 1-2: new full-speed USB device number 7 using xhci_hcd
usb 1-2: New USB device found, idVendor=104d, idProduct=3001
usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-2: Product: ESP301 Motion Control 
usb 1-2: Manufacturer: NEWPORT Corp.    
usb 1-2: SerialNumber: 0000000000000000

$ lsusb -v
Bus 001 Device 007: ID 104d:3001 Newport Corporation 
Device Descriptor:
bLength                18
bDescriptorType         1
bcdUSB               1.10
bDeviceClass          255 Vendor Specific Class
bDeviceSubClass         0 
bDeviceProtocol         0 
bMaxPacketSize0         8
idVendor           0x104d Newport Corporation
idProduct          0x3001 
bcdDevice            1.01
iManufacturer           1 NEWPORT Corp.    
iProduct                2 ESP301 Motion Control 
iSerial                 3 0000000000000000
bNumConfigurations      1
Configuration Descriptor:
 bLength                 9
 bDescriptorType         2
 wTotalLength           39
 bNumInterfaces          1
 bConfigurationValue     2
 iConfiguration          0 
 bmAttributes         0xa0
 (Bus Powered)
 Remote Wakeup
 MaxPower              100mA
 Interface Descriptor:
 bLength                 9
 bDescriptorType         4
 bInterfaceNumber        0
 bAlternateSetting       0
 bNumEndpoints           3
 bInterfaceClass       255 Vendor Specific Class
 bInterfaceSubClass      0 
 bInterfaceProtocol      0 
 iInterface              0 
 Endpoint Descriptor:
  bLength                 7
  bDescriptorType         5
  bEndpointAddress     0x81  EP 1 IN
  bmAttributes            2
  Transfer Type            Bulk
  Synch Type               None
  Usage Type               Data
  wMaxPacketSize     0x0040  1x 64 bytes
  bInterval               0
 Endpoint Descriptor:
  bLength                 7
  bDescriptorType         5
  bEndpointAddress     0x01  EP 1 OUT
  bmAttributes            2
  Transfer Type            Bulk
  Synch Type               None
  Usage Type               Data
  wMaxPacketSize     0x0040  1x 64 bytes
  bInterval               0
 Endpoint Descriptor:
  bLength                 7
  bDescriptorType         5
  bEndpointAddress     0x83  EP 3 IN
  bmAttributes            3
  Transfer Type            Interrupt
  Synch Type               None
  Usage Type               Data
  wMaxPacketSize     0x0002  1x 2 bytes
  bInterval               1
Device Status:     0x0001
Self Powered

答案1

HID 本身并不是真正的设备类型,而是用于与各种设备类型交互的标准协议(甚至不依赖于 USB,它还通过蓝牙、I2C 和可能的其他较低级别的通信协议使用)。不过,设备本身必须支持该协议,否则它将无法理解您的软件对其所说的内容。

在您的例子中,相关设备提供了一个标识为供应商特定类 (VSC) 的单一端点,这是一种奇特的说法,表明设计人员认为它不适合任何其他标准 USB 设备类型。某些此类设备可能具有可以发送给它们的特殊命令,以将其切换到不同的模式,其中可能包括将其切换到 HID 模式的命令,并且应在设备的文档中进行介绍。

但实际上,您可以轻松地使用 libusb 使用任何正常命令集直接与设备对话,并跳过 HID 的开销。

相关内容