Python Forum
Byte array is sorted when sending via USB
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Byte array is sorted when sending via USB
#1
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
Reply
#2
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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  extract only text strip byte array Pir8Radio 7 2,791 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
  Failing to print sorted files tester_V 4 1,188 Nov-12-2022, 06:49 PM
Last Post: tester_V
  sending byte in code? korenron 2 1,087 Oct-30-2022, 01:14 PM
Last Post: korenron
  set and sorted, not working how expected! wtr 2 1,255 Jan-07-2022, 04:53 PM
Last Post: bowlofred
  How to make elements return sorted? notsoexperienced 4 3,166 Sep-24-2020, 09:00 AM
Last Post: perfringo
  'utf-8' codec can't decode byte 0xe2 in position 122031: invalid continuation byte tienttt 12 11,356 Sep-18-2020, 10:10 PM
Last Post: tienttt
  convert array of numbers to byte array adetheheat 3 2,732 Aug-13-2020, 05:09 PM
Last Post: bowlofred
  Why is my original list also sorted? Pedroski55 1 1,582 Jul-15-2020, 09:25 PM
Last Post: Yoriz
  Outputting Sorted Text files Help charlieroberrts 1 1,687 Jul-05-2020, 08:37 PM
Last Post: menator01
  Convert even byte array to odd medatib531 1 2,174 Mar-17-2020, 02:48 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020