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.