我正在尝试将num lock发送到充当HID键盘的自定义硬件 . 如果在USB上接收到num lock键,我已经将LED连接起来发光 . 它适用于外部键盘的numlock keypress . 但我无法通过pyusb手动发送num lock键(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上 . 有人可以帮助我吗?
谢谢 .
1 回答
您的硬件尚未完全实现USB HID键盘协议 - 它没有OUT endpoints ,因此当脚本找不到时,您的脚本正在挽救 .
如果你're on a Mac, you may want to inspect the device using Apple' s "USB Prober"开发人员实用程序,它是"Hardware Tools for Xcode"包的一部分 . (您可以从http://developer.apple.com下载 . )