hid_test.py 566 B

1234567891011121314151617
  1. # Install python3 HID package https://pypi.org/project/hid/
  2. import hid
  3. USB_VID = 0xcafe
  4. print("Openning HID device with VID = 0x%X" % USB_VID)
  5. for dict in hid.enumerate(USB_VID):
  6. print(dict)
  7. dev = hid.Device(dict['vendor_id'], dict['product_id'])
  8. if dev:
  9. while True:
  10. # Get input from console and encode to UTF8 for array of chars.
  11. str_out = input("Send text to HID Device : ").encode('utf-8')
  12. dev.write(str_out)
  13. str_in = dev.read(64)
  14. print("Received from HID Device:", str_in, '\n')