pyusb无法访问OUT端点 [英] OUT Endpoint not accessible by pyusb

查看:238
本文介绍了pyusb无法访问OUT端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将num lock发送到充当HID键盘的自定义硬件.如果在USB上收到Num Lock键,我会绑上一个LED发光.对于外部键盘上的numlock键按下,它可以正常工作.但是我无法通过pyusb(0x01)手动发送num lock键

I am trying to send num lock to my custom hardware acting as a HID Keyboard. I have tied up an LED to glow if the num lock key is received on the USB. It works fine for numlock keypress from external keyboard. But I am unable to send the num lock key manually through pyusb (0x01)

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

This is the part of the code responsible for sending it:

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

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.

谢谢.

推荐答案

您的硬件尚未完全实现USB HID键盘协议-它没有OUT端点,因此当脚本找不到时,您的脚本将退出工作一个.

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.

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

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.)

这篇关于pyusb无法访问OUT端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆