From: Jonas M. <jo...@pr...> - 2021-01-03 01:45:24
|
On Sat, Jan 2, 2021 at 5:38 PM Richard Folorunso via pyusb-users <pyu...@li...> wrote: > > Good evening! I'm hoping there is a way to speed up my current code as I need it to be just a bit faster to be usable. > > At the start of my program is this line > > global_out = usb.util.find_descriptor(intf,custom_match=lambda e:usb.util.endpoint_direction(e.bEndpointAddress)==usb.util.ENDPOINT_OUT) > > Then this line actually sends the data > > def sendCommand(content): > global_out.write(struct.pack("<I", (len(content)+2))) > global_out.write(content) > > > The issues is this line > > global_out.write(struct.pack("<I", (len(content)+2))) > > > Timing it, python says it takes 0.05 seconds to complete this line. I would need to get it down to 0.016 seconds in order for my program to function as intended. Is there anything I can do to optimize it? > > https://gist.github.com/Bluecoreg/1db99d6afcb15aab85760faa16160d05 Richard, The timing for the transfer to complete is outside our control, it mostly depends on the device. But I noticed that you're sending the length in one transfer, and the content in another... That's unusual, and perhaps the device doesn't handle that well/fast. Didn't you meant to write something like def sendCommand(content): global_out.write(struct.pack('<I', len(content) + 2) + content.encode()) Jonas > _______________________________________________ > pyusb-users mailing list > pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyusb-users |