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