I am using pywinusb to send/get data from Custom HID device. I can successfully send data but cant get it. Any suggestions? I tried to debug using Microsoft Message Analyzer and can see the data there but not in the script. Product/Vendor Ids, report id etc are correct.
Here the code,
from pywinusb import hid
from time import sleep
devicefilter = hid.HidDeviceFilter(vendor_id=0x0483, product_id=0x572A)
devices = devicefilter.get_devices()
print ("devices:", devices)
hid_device = devices[0]
print ("hid_device:", hid_device)
hid_device.open()
out_report = hid_device.find_output_reports()
in_report = hid_device.find_input_reports()
print("out_report:", out_report)
print("out_report[0]:",out_report[0])
print("in_report:", in_report)
print("in_report[0]:",in_report[0])
txBuffer = [0x55] * 64
txBuffer[0] = 0x01 # Report ID
rxBuffer = [0x00] * 64
rxBuffer[0] = 0x02 # Report ID
print(txBuffer)
print(rxBuffer)
out_report[0].set_raw_data(txBuffer)
in_report[0].set_raw_data(rxBuffer)
while 1:
out_report[0].send()
rxBuffer = in_report[0].get()
print("rxBuffer:", rxBuffer)
sleep(1)
hid_device.close()
I'm no expert on this my self but I have a similar sounding application Here is what I do. I don't explicitly create an input report but rather attach an input report handler to the usb receive buffer.
import pywinusb.hid as hid
# handler called when a report is received
def rx_handler(data):
print 'recv: ', data
def scan_hiddevice():
""" Scans for and returns the HID device. """
devices = hid.HidDeviceFilter( vendor_id = vendor_id).get_devices()
if not devices:
print "scan_hiddevice: No device connected."
return None
else:
device = devices[0]
#print("scan_hiddevice: found %s", device )
return device
return None
def setup_hiddevice():
"""Creates a new HID device, opens it and attaches a receive data handler"""
hid_device = scan_hiddevice()
hid_device.open()
hid_device.set_raw_data_handler(rx_handler)
return hid_device
def main(verbose=True):
hid_device = setup_hiddevice()
while (True):
#wait for data
I hope this can be of some use.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.