Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_bulk_vendor.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. """
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. """
  7. """
  8. LUFA Bulk Vendor device demo host test script. This script will send and
  9. receive a continuous stream of packets to/from to the device, to show
  10. bidirectional communications.
  11. Requires the pyUSB library (http://sourceforge.net/projects/pyusb/).
  12. """
  13. import sys
  14. from time import sleep
  15. import usb.core
  16. import usb.util
  17. # Bulk Vendor HID device VID and PID
  18. device_vid = 0x03EB
  19. device_pid = 0x206C
  20. device_in_ep = 3
  21. device_out_ep = 4
  22. def get_vendor_device_handle():
  23. dev_handle = usb.core.find(idVendor=device_vid, idProduct=device_pid)
  24. return dev_handle
  25. def write(device, packet):
  26. device.write(usb.util.ENDPOINT_OUT | device_out_ep, packet, 0, 1000)
  27. print("Sent Packet: {0}".format(packet))
  28. def read(device):
  29. packet = device.read(usb.util.ENDPOINT_IN | device_in_ep, 64, 0, 1000)
  30. print("Received Packet: {0}".format(''.join([chr(x) for x in packet])))
  31. return packet
  32. def main():
  33. vendor_device = get_vendor_device_handle()
  34. if vendor_device is None:
  35. print("No valid Vendor device found.")
  36. sys.exit(1)
  37. vendor_device.set_configuration()
  38. print("Connected to device 0x%04X/0x%04X - %s [%s]" %
  39. (vendor_device.idVendor, vendor_device.idProduct,
  40. usb.util.get_string(vendor_device, 255, vendor_device.iProduct),
  41. usb.util.get_string(vendor_device, 255, vendor_device.iManufacturer)))
  42. x = 0
  43. while 1:
  44. x = x + 1 % 255
  45. write(vendor_device, "TEST PACKET %d" % x)
  46. read(vendor_device)
  47. sleep(1)
  48. if __name__ == '__main__':
  49. main()