gpt4 book ai didi

python - pyusb 无法访问 OUT 端点

转载 作者:行者123 更新时间:2023-12-01 05:02:34 26 4
gpt4 key购买 nike

我正在尝试将数字锁定发送到充当 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com