【问题标题】:Python PyUSB HID Feature ReportPython PyUSB HID 功能报告
【发布时间】: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


    【解决方案1】:

    你在 dev.ctrl_transfer 命令中的参数看起来不对。

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

    因此,您必须设置设备功能中的参数以及您想要做什么。例如在我的代码和我的设备中,我有这个命令:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 2015-08-28
      • 2021-03-30
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2014-11-27
      相关资源
      最近更新 更多