Oct-15-2016, 08:27 PM
hey I'm trying to get pywinusb to work with a usb device that i've created and i'm having a hard time understanding some things. first off I saw an example using device.set_raw_data_handler(sample_handler) that, from what I understood, lets me send any type of data(int, char...) after finding sample_handler on the creator github and running the program. I tested it by writing a 'a' and I get an error telling me that it only accepts int is there a way to fix this? if not I can still just send int but i just think that char might help me out a bit.
Also I am trying to read data from the device, since I want to 'interact' to my usb device via python/terminal. but I can't figure out how to read data, as long as I can get the raw data that is being sent I can 'convert/process' it later on and since everything is going to be concurrent I don't think I'll have any problems especially since I don't need anything in real time.
here is my code, I know its a bit of a mess but I think its easy to understand what I'm trying to do
Also I am trying to read data from the device, since I want to 'interact' to my usb device via python/terminal. but I can't figure out how to read data, as long as I can get the raw data that is being sent I can 'convert/process' it later on and since everything is going to be concurrent I don't think I'll have any problems especially since I don't need anything in real time.
here is my code, I know its a bit of a mess but I think its easy to understand what I'm trying to do
import pywinusb.hid as hid ## usb device VId = 0x0001 PId = 0x0001 #def sample_handler(data): # print("Raw data: {0}".format(data)) print('searching for device') filter = hid.HidDeviceFilter(vendor_id = VId, product_id = PId) hid_device = filter.get_devices() device = hid_device[0] device.open() ## Setup communication ## # datapipe allowing 64 byte data of any format # target_usage = hid.get_full_usage_id(0x00, 0x40) #device.set_raw_data_handler(sample_handler) print(target_usage) print('1') report = device.find_output_reports() print(report) print(report[0]) print('2') buffer = [0xFF]*65 buffer[0] = 65 print('3') print(buffer) print('4') report[0].set_raw_data(buffer) report[0].send() print('5') def writer(x): buffer[0]=x report[0].set_raw_data(buffer) report.send()