Python Forum

Full Version: Byte array is sorted when sending via USB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm new to the forum and new to Python as well

I'm using Python 3.7.0 and Pywinusb 0.4.2 to send raw data to an HID device.

import pywinusb.hid as hid

def readData(data):
    print(data)

device = hid.HidDeviceFilter(vendor_id=0xXXXX, product_id=0xXXXX).get_devices()[0]
if not device:
    print ("No device found")
else:
    print(device)
    device.open()
    report = device.find_output_reports()
    print(report)
    print(report[0])
    buffer=[0x00]*65 #USB packet size
    buffer[0]=0x00 #report id
    buffer[1]=0x0A
    buffer[2]=0x2F
    buffer[3]=0x02
    buffer[4]=0x03
    buffer[5]=0x01
    report[0].set_raw_data(buffer)
    report[0].send()
    device.set_raw_data_handler(readData)
    device.close()
The HID device receives the data, I already confirmed this.

My problem is that somewhere the byte array gets sorted from minor to major. I already confirmed this as well

Any ideas ?


Thank you

David DLC
You are using a list which is mutable. Try to send this: buffer = b'\x00\x0A\x2F\x02\x03\x01'
You should see struct module.