Sending USB commands with Python

Adam W. AWasilenko at gmail.com
Thu Aug 30 08:51:56 EDT 2012


On Thursday, August 30, 2012 12:55:14 AM UTC-4, Dennis Lee Bieber wrote:
>
> 	How many bytes did it claim to send?
> 
11, which is what I expected.  But I changed the byte value to 16 (because I was having trouble getting single digit hex values working in the command) and sent this command:
>>> for x in range(0,500):
	ep.write(b'\x16\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF')

it respond with 500 17's and prints a black bar!  So it looks like whatever concern you had with using encode was coming to fruition.

> 
> 	That's the easy one -- \x in a string introduces an 8-bit byte value
> 
> -- so only two hex digits well be read. The "A" is interpreted as
> 
> regular text.

Interesting, so what if I only wanted to send 4bits as a hex value?  Also can I somehow throw in some binary alongside of hex?  At some point in my program I'm going to need to send some commands preferably in hex along with the binary image data.



More information about the Python-list mailing list