UPDATE
I managed to send the data properly. For anyone who ran into the same problem, I used the following code:
data=[0x00, 0x04, 0x04, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
result=dev.ctrl_transfer(0x21, 0x9, wValue=0x200, wIndex=0x00, data_or_wLength=data)
(This is based on the answer posted here: link)
But I don't understand in detail, why I have to use
bmRequestType=0x21
bRequest=0x9
wValue=0x200
What is the explanation?
Initial request:
I'm desperately trying to send a simple report to a HID-device using PyUSB.
Using "SimpleHIDwrite" I confirmed that the device works just as expected. I want to send this data:
report ID: 00
data: [00, 04, 04, FF, FF, FF, 00, 00]
Sending data using SimpleHIDwrite
I'm quite new to Python and USB and I can't figure out how to do this using dev.ctrl_transfer or dev.write.
Also, there are some posts about sending data to HID devices, but I couldn't figure out how to solve my problem. How can I fix it?
Here are some more details:
# Based on https://github.com/walac/pyusb/blob/master/docs/tutorial.rst
import usb.core
import usb.util
# Find our device
# dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001)
dev = usb.core.find(idVendor=0x1781, idProduct=0x8c0)
# Was it found?
if dev is None:
raise ValueError('Device not found')
dev.set_configuration()
cfg = dev[0]
intf = cfg[(0,0)]
ep = intf[0]
# dev.write(ep.bEndpointAddress, [0x00, 0x00,0x04,0x04,0xFF,0xFF,0xFF,0x00, 0x00], 1000)
# dev.ctrl_transfer(bmRequestType, bRequest, wValue=0, wIndex=0, data_or_wLength=None, timeout=None)
print("print ep")
print(ep)
print("print cfg")
print(cfg)
print("print intf")
print(intf)
And the result of the script above is this:
print ep
ENDPOINT 0x81: Interrupt IN ==========================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x81 IN
bmAttributes : 0x3 Interrupt
wMaxPacketSize : 0x8 (8 bytes)
bInterval : 0xa
print cfg
CONFIGURATION 1: 100 mA ==================================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x2 Configuration
wTotalLength : 0x22 (34 bytes)
bNumInterfaces : 0x1
bConfigurationValue : 0x1
iConfiguration : 0x0
bmAttributes : 0x80 Bus Powered
bMaxPower : 0x32 (100 mA)
INTERFACE 0: Human Interface Device ====================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x4 Interface
bInterfaceNumber : 0x0
bAlternateSetting : 0x0
bNumEndpoints : 0x1
bInterfaceClass : 0x3 Human Interface Device
bInterfaceSubClass : 0x0
bInterfaceProtocol : 0x0
iInterface : 0x0
ENDPOINT 0x81: Interrupt IN ==========================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x81 IN
bmAttributes : 0x3 Interrupt
wMaxPacketSize : 0x8 (8 bytes)
bInterval : 0xa
print intf
INTERFACE 0: Human Interface Device ====================
bLength : 0x9 (9 bytes)
bDescriptorType : 0x4 Interface
bInterfaceNumber : 0x0
bAlternateSetting : 0x0
bNumEndpoints : 0x1
bInterfaceClass : 0x3 Human Interface Device
bInterfaceSubClass : 0x0
bInterfaceProtocol : 0x0
iInterface : 0x0
ENDPOINT 0x81: Interrupt IN ==========================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x81 IN
bmAttributes : 0x3 Interrupt
wMaxPacketSize : 0x8 (8 bytes)
bInterval : 0xa
Process finished with exit code 0
See Question&Answers more detail:
os