1

我正在尝试将 num lock 发送到充当 HID 键盘的自定义硬件。如果在 USB 上收到数字锁定键,我已经绑定了一个 LED 来发光。它适用于外部键盘的数字锁定按键。但我无法通过 pyusb (0x01) 手动发送 num lock 键

这是负责发送它的代码部分:

  dev = usb.core.find(idVendor=0xXXXX, idProduct=0xXXXX)

  try:
    dev.set_configuration()
  except usb.core.USBError as e:
    print e
  #endpoint = dev[0][(0,0)][0]

  # get an endpoint instance
  cfg = dev.get_active_configuration()
  intf = cfg[(0,0)]

  print intf

  ep = usb.util.find_descriptor(
      intf,
      # match the first OUT endpoint
      custom_match = \
      lambda e: \
          usb.util.endpoint_direction(e.bEndpointAddress) == \
          usb.util.ENDPOINT_OUT)

  assert ep is not None

  # write the data
  ep.write('\x01')

我的输出是:

    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 :    0x1
     iInterface         :    0x0
      ENDPOINT 0x81: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :   0x18
Traceback (most recent call last):
  File "./main.py", line 43, in <module>
    assert ep is not None
AssertionError

由于它可以通过外部键盘实现,我想权限没有问题,或者操作系统可以访问它,但外部进程不能访问它。我在 Mac 上。有人可以帮我吗?

谢谢。

4

1 回答 1

3

Your hardware hasn't fully implemented the USB HID keyboard protocol — it doesn't have an OUT endpoint, so your script is bailing out when it fails to find one.

If you're on a Mac, you may want to inspect the device using Apple's "USB Prober" developer utility, which is part of the "Hardware Tools for Xcode" package. (You can download it from http://developer.apple.com.)

于 2014-09-10T02:09:34.297 回答