首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python特性报告

Python特性报告
EN

Stack Overflow用户
提问于 2016-02-02 20:10:01
回答 1查看 4.7K关注 0票数 1

我正在使用MacOSX10.10.5中的python访问USB设备,执行以下操作:

代码语言:javascript
复制
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上)。

代码语言:javascript
复制
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权限执行时,我会得到一个中断的管道。目前还不清楚如何将我在Hidapi的send_feature_report中使用的参数映射到ctrl_transfer在PyUSB中实际使用的参数。

对于如何进行这种映射有帮助吗?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2016-02-29 10:23:19

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

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

所以你必须设置你的设备的功能参数和你想要做的事情。例如,在我的代码和我的设备中,我有以下命令:

代码语言:javascript
复制
dev.ctrl_transfer(0x21, 0x09, 0x200, 0x00, command)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35162889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档