Created
September 30, 2013 23:10
-
-
Save LordSputnik/6771632 to your computer and use it in GitHub Desktop.
Python USB Device Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pywinusb.hid as hid | |
import time | |
import datetime | |
v_id = 0x04D8 | |
p_id = 0x0042 | |
all_devices = hid.HidDeviceFilter(vendor_id = v_id).get_devices() | |
target_usage= hid.get_full_usage_id(0xFF00, 0x01) | |
print(all_devices) | |
def sample_handler(data): | |
global my_buffer | |
my_buffer.append("".join(chr(d) for d in data[1:])) | |
device = all_devices[0] | |
device.open() | |
device.set_raw_data_handler(sample_handler) | |
data = [0] * 65 | |
data[1] = 0x82 | |
my_buffer = [] | |
now = datetime.datetime.now() | |
while (datetime.datetime.now() - now).seconds < 1: | |
device.send_output_report(data) | |
total_data = "".join(my_buffer) | |
print(len(total_data) * 8) | |
""" | |
for device in all_devices: | |
device.open() | |
device.set_raw_data_handler(sample_handler) | |
data = [0] * 65 | |
data[1] = 0x80 | |
device.send_output_report(data) | |
data[1] = 0x82 | |
device.send_output_report(data)""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment