python - pyusb 无法访问 OUT 端点

标签 python macos usb pyusb

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

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

  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上。有人可以帮我吗?

谢谢。

最佳答案

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

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

关于python - pyusb 无法访问 OUT 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25755494/

相关文章:

python - 将项目列表列表转换为 pandas 中的虚拟对象

macos - 清理 docker 镜像的重复版本

macos - 无论事件流创建选项如何,都会设置 FSEvents 文件标志

c# - 如何从通过 USB 连接的相机读取文件

c - 如何使用 USB 端口将数据从 Arduino Uno 发送到 PC

python - matplotlib 动画绘图不会使用 blit 更新轴上的标签

python - Numpy.unique 行为(扁平化不一致?)

node.js - 有没有一种简单的方法通过 NodeJS 将数据发送到 USB?

Python 数据库 API : how to handle different paramstyles?

php - 如何在 OSX、PHP 5.5.30 上安装 "pthreads"