gpt4 book ai didi

Python PyUSB HID 功能报告

转载 作者:太空宇宙 更新时间:2023-11-03 16:59:03 37 4
gpt4 key购买 nike

我正在 Mac OSX 10.10.5 上使用 python hidapi 访问 USB HID 设备:

import hid
import time

hidraw = hid.device(0x1a67, 0x0004)
hidraw.open(0x1a67, 0x0004)

# Rpt, GnS, Tgt, Size, Index LSB, Index MSB, Data
# Blink 4 pulses
hidraw.send_feature_report([0x00, 0x00, 0x00,0x01, 0x01, 0x00, 0x03])

hidraw.get_feature_report(33,33)
time.sleep(3)

HID 功能报告运行良好,没有任何问题。但是,我正在尝试将此代码移植到 PyUSB 并尝试做同样的事情(在 RaspberryPi 上)

import usb.core
import usb.util

# find our device
dev = usb.core.find(idVendor=0xfffe, idProduct=0x0004)

# was it found?
if dev is None:
raise ValueError('Device not found')

# get an endpoint instance
for interface in dev.get_active_configuration():
if dev.is_kernel_driver_active(interface.bInterfaceNumber):
# Detach kernel drivers and claim through libusb
dev.detach_kernel_driver(interface.bInterfaceNumber)
usb.util.claim_interface(dev, interface.bInterfaceNumber)

# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()

ret = dev.ctrl_transfer(0x00, 0x00, 0x01, 0x01, [0x00, 0x03])

但是当我使用root权限执行时,我得到了一个Broken Pipe。目前还不太清楚如何将我在 Hidapi 的 send_feature_report 中使用的参数映射到 PyUSB 中 ctrl_transfer 中实际使用的参数。

有关如何进行此映射的任何帮助吗?

谢谢!!!

最佳答案

dev.ctrl_transfer 命令中的参数看起来错误。

事实是 dev.ctrl_transfer 将设置几个参数,例如消息的方向、长度和控制消息的内容(一切都在这个链接中得到了很好的解释:http://www.beyondlogic.org/usbnutshell/usb6.shtml#SetupPacket)

因此,您必须根据设备的功能和您想要执行的操作来设置参数。例如,在我的代码和我的设备中,我有以下命令:

dev.ctrl_transfer(0x21, 0x09, 0x200, 0x00, command)

关于Python PyUSB HID 功能报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35162889/

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