【发布时间】:2016-05-11 19:32:22
【问题描述】:
我正在使用 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 中的实际使用方式,目前还不是很清楚。
对如何制作此映射有任何帮助吗?
谢谢!!!
【问题讨论】:
标签: python cython hid pyusb hidapi