blob: a42930fb5de535f281c20118409d61f05ff8d4c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# Install python3 HID package https://pypi.org/project/hid/
import hid
USB_VID = 0xcafe
print("Openning HID device with VID = 0x%X" % USB_VID)
for dict in hid.enumerate(USB_VID):
print(dict)
dev = hid.Device(dict['vendor_id'], dict['product_id'])
if dev:
while True:
# Get input from console and encode to UTF8 for array of chars.
# hid generic inout is single report therefore by HIDAPI requirement
# it must be preceeded with 0x00 as dummy reportID
str_out = b'\x00'
str_out += input("Send text to HID Device : ").encode('utf-8')
dev.write(str_out)
str_in = dev.read(64)
print("Received from HID Device:", str_in, '\n')
|