【问题标题】:OUT Endpoint not accessible by pyusbpyusb 无法访问 OUT 端点
【发布时间】:2014-11-03 12:23:47
【问题描述】:

我正在尝试将 num lock 发送到充当 HID 键盘的自定义硬件。如果在 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

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

谢谢。

【问题讨论】:

    标签: python macos usb pyusb


    【解决方案1】:

    您的硬件尚未完全实现 USB HID 键盘协议 — 它没有 OUT 端点,因此您的脚本会在找不到端点时退出。

    如果您使用的是 Mac,您可能希望使用 Apple 的“USB Prober”开发实用程序检查设备,该实用程序是“Xcode 硬件工具”软件包的一部分。 (您可以从http://developer.apple.com下载。)

    【讨论】:

    • 好的。我得到了它。它应该是一个控制数据传输。所以我发送dev.ctrl_transfer(0x21,0x09,0x0200,0x0000,0x0001) 来切换数字锁。我得到usb.core.USBError: [Errno 13] Access denied (insufficient permissions)
    • 在 Mac OS X 上,您不能使用 libusb 访问 HID 设备:libusb.org/ticket/89
    猜你喜欢
    • 2011-07-06
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2021-06-16
    • 2021-09-30
    相关资源
    最近更新 更多