0

I am trying to create a program to send n bytes to HID device and then reading them from the device. I m using a hexadecimal list, for eg.[0x00,0x01,0x02...0x0n] as the data to be sent and recieved. My problem is that even though the data is sent successfully. It is not read, There is no received data printed.

Here's my code if that helps

import hid
import time
try:
    print("Opening the device")

    h = hid.device()
    h.open(0x1234, 0x5678)  # TREZOR VendorID/ProductID

    print("Manufacturer: %s" % h.get_manufacturer_string())
    print("Product: %s" % h.get_product_string())
    print("Serial No: %s" % h.get_serial_number_string())

    # enable non-blocking mode
    h.set_nonblocking(1)

    # write some data to the device
    print("Write the data")
    h.write([0x00]*64)
    print("Data written successfully")

    # wait
    time.sleep(0.05)

    # read back the answer
    print("Read the data")
    while True:
        d = h.read(64)
        if d:
            print(d)
        else:
            break

    print("Closing the device")
    h.close()

except IOError as ex:
    print(ex)
    print("You probably don't have the hard-coded device.")
    print("Update the h.open() line in this script with the one")
    print("from the enumeration list output above and try again.")

print("Done")

Ive been stuck on the reading function for 3 days. I tried changing the number of bytes read at a time but even that failed. Your Help would be greatly appreciated.

prathetic
  • 1
  • 1
  • This is what I would do: turn blocking mode on and see how far the program gets. When you set non blocking mode the write and read calls typically return immediately and so the data may not have been written or read. I would also capture a Wireshark trace to see exactly what data is flowing on the wire. – aja May 11 '23 at 11:23
  • This results in an infinite loop. the data I'm sending is a hexadec list which is a sequence of hex values of colours 'R','G','B'. each with one second delay – prathetic May 13 '23 at 07:42
  • This solution isnt working as the code enters an infinite loop while reading. – prathetic May 18 '23 at 06:19

0 Answers0