usb - How to send hid data to device using python / pywinusb? -
i'm trying use pywinusb send output report pic18f4550. device can receive data, , i've tested c# application, worked fine. also, can read data device pywinusb fine, have problem trying send data.
here's code i'm running:
from pywinusb import hid filter = hid.hiddevicefilter(vendor_id = 0x0777, product_id = 0x0077) devices = filter.get_devices() if devices: device = devices[0] print "success" device.open() out_report = device.find_output_reports()[0] buffer= [0x00]*65 buffer[0]=0x0 buffer[1]=0x01 buffer[2]=0x00 buffer[3]=0x01 out_report.set_raw_data(buffer) out_report.send() dev.close()
it produces error:
success traceback (most recent call last): file "c:\users\7user\desktop\usb pic18\out.py", line 24, in <module> out_report.send() file "build\bdist.win32\egg\pywinusb\hid\core.py", line 1451, in send self.__prepare_raw_data() file "build\bdist.win32\egg\pywinusb\hid\core.py", line 1406, in __prepare_raw_data byref(self.__raw_data), self.__raw_report_size) ) file "build\bdist.win32\egg\pywinusb\hid\winapi.py", line 382, in __init__ raise helpers.hiderror("hidp error: %s" % self.error_message_dict[error_code]) hiderror: hidp error: data index not found
here code , works msp430f chip running ti's datapipe usb stack. hid input , output endpoints act custom data pipe allowing me send 64 bytes in format want exception of first byte being id number (defined ti) decimal 63 , second byte being number of pertinent or useful bytes in packet (64 byte max packet) first 2 bytes described above. took me while figure out because of lack of documentation. few examples come pywinusb hard learn @ best. anyways here code. working micro should you.
filter = hid.hiddevicefilter(vendor_id = 0x2048, product_id = 0x0302) hid_device = filter.get_devices() device = hid_device[0] device.open() print(hid_device) target_usage = hid.get_full_usage_id(0x00, 0x3f) device.set_raw_data_handler(sample_handler) print(target_usage) report = device.find_output_reports() print(report) print(report[0]) buffer = [0xff]*64 buffer[0] = 63 print(buffer) report[0].set_raw_data(buffer) report[0].send()
one area may screwing here:
out_report = device.find_output_reports()[0]
try using "out_report = device.find_output_reports()" without "[0]" @ end. use
out_report[0].set_raw_data(buffer)
and finally
out_report[0].send()
hope helps out.
Comments
Post a Comment