Sending USB commands with Python

Adam W. AWasilenko at gmail.com
Wed Aug 29 17:21:30 EDT 2012


On Wednesday, August 29, 2012 4:09:49 PM UTC-4, Dennis Lee Bieber wrote:
>
> 	Don't the commands require an <esc> character? "\x1BA" (or
>    "\x1B\x41")
> 
> 	OTOH, if the <esc> is issued behind the scenes,

I'm not sure which esc char it is asking for, I don't think libusb is providing its own, and it seems like the one you suggested isn't what it wants either..

>  ... and you do not need to issue some sort of read()
> the "2" you are seeing is the "number of bytes written";
> 
> you need to issue a read request to retrieve the returned printer
> 
> status.
> 

You are correct about the 2 being the number of bytes written.  However when I issue a read command I get:

>>> ep.write('\x1BA')
4
>>> ep.read(1)
Traceback (most recent call last):
  File "<pyshell#75>", line 1, in <module>
    ep.read(1)
  File "C:\Python32\lib\site-packages\usb\core.py", line 301, in read
    return self.device.read(self.bEndpointAddress, size, self.interface, timeout)
  File "C:\Python32\lib\site-packages\usb\core.py", line 654, in read
    self.__get_timeout(timeout)
  File "C:\Python32\lib\site-packages\usb\backend\libusb01.py", line 483, in bulk_read
    timeout)
  File "C:\Python32\lib\site-packages\usb\backend\libusb01.py", line 568, in __read
    timeout
  File "C:\Python32\lib\site-packages\usb\backend\libusb01.py", line 384, in _check
    raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_setup_async] invalid endpoint 0x02\n'

Avoiding the read command all together I should be able to write "<esc> E" and have it feed some paper, which it is not doing, so obviously there is more to uncover.  That said I feel this endeavor has evolved and is no longer pertinent to the Python group so I will let you guys off the hook on this (although responses/suggestions are still welcome).

Thanks for all your help!



More information about the Python-list mailing list