Python Forum
Thread Rating:
  • 4 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
general pywinusb help
#1
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
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()
Reply
#2
Could you provide the full traceback saying that it only accepts ints?
Reply
#3
I'd also like to understand what set_raw_data_handler does. I thought it was used to read the data from a USB device. In the example folder of PyWinUSB, raw_data.py seems to use the function sample_handler() and set_raw_data_handler() function to pull data off the USB device. It works beautifully because I can see the raw data from my touch panel in the console. However, I want to put this data in a LIST (rather than printing it to the console), but I cannot figure out how to do it because these functions are passing functions which is very difficult for me to follow.
Any help is appreciated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Change HID bytes using pywinusb.hid Stealthrt 0 649 Jul-06-2023, 03:36 PM
Last Post: Stealthrt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020