1

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])

しかし、ルート権限で実行すると、壊れたパイプが発生します。Hidapi の send_feature_report で使用したパラメーターを、PyUSB の ctrl_transfer から実際に使用する方法にマップする方法はあまり明確ではありません。

このマッピングをどのように行うべきかについての助けはありますか?

ありがとう !!!

4

1 に答える 1

1

dev.ctrl_transfer コマンドのパラメーターが間違っているようです。

実際のところ、dev.ctrl_transfer は、メッセージの方向、長さ、制御メッセージの内容など、いくつかのパラメーターを設定します (すべて、このリンクで詳しく説明されています: http://www.beyondlogic.org/usbnutshell/usb6. shtml#SetupPacket )

そのため、デバイスの機能とやりたいことのパラメーターを設定する必要があります。私のコードと私のデバイスの例として、次のコマンドがあります。

dev.ctrl_transfer(0x21, 0x09, 0x200, 0x00, command)
于 2016-02-29T10:23:19.690 に答える