1

HID キーボードとして機能するカスタム ハードウェアに Num Lock を送信しようとしています。Num Lock キーが USB で受信された場合に点灯するように LED を結び付けました。外部キーボードからのnumlockキープレスでは正常に機能します。しかし、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

Since it is doable from an external keyboard I guess there are no issues with permission or maybe it is accessible by the OS but not by an external process. I am on Mac. Can someone help me out here.

Thanks.

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 に答える