Sending USB commands with Python

Adam W. AWasilenko at gmail.com
Wed Aug 29 19:45:10 EDT 2012


On Wednesday, August 29, 2012 6:56:16 PM UTC-4, Dennis Lee Bieber wrote:
>
> 	BUT you do give a possible clue. Is the OP using a 3.x Python where
> 
> strings are Unicode -- in which case the above may need to be explicitly
> 
> declared as a "byte string" rather than text (unicode) string.
> 

Huzzah!  I am indeed using 3.x, and slapping on an .encode('utf-8') made my printer try to spit paper at me! Progress.

Also, astute observation about the endpoint needing to be an input, with the following modification I get:

>>> ep.write('\x1BA'.encode('utf-8'))
2
>>> ep = usb.util.find_descriptor(
    intf,
    custom_match = \
    lambda e: \
        usb.util.endpoint_direction(e.bEndpointAddress) == \
        usb.util.ENDPOINT_IN
)
>>> ep.read(1)
array('B', [163])
>>> 

Anyone want to venture a guess on how I should interpret that?  It seems the [163] is the byte data the manual is talking about, but why is there a 'B' there?  If I put paper in it and try again I get: array('B', [3])

Thanks for all your help guys, just about ready to stared coding the fun part!



More information about the Python-list mailing list