Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28036 > unrolled thread
| Started by | "Adam W." <AWasilenko@gmail.com> |
|---|---|
| First post | 2012-08-28 17:04 -0700 |
| Last post | 2012-08-29 17:57 -0400 |
| Articles | 10 — 5 participants |
Back to article view | Back to comp.lang.python
Sending USB commands with Python "Adam W." <AWasilenko@gmail.com> - 2012-08-28 17:04 -0700
Re: Sending USB commands with Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-28 22:54 -0400
Re: Sending USB commands with Python hamilton <hamilton@nothere.com> - 2012-08-28 21:03 -0600
Re: Sending USB commands with Python alex23 <wuwei23@gmail.com> - 2012-08-28 22:04 -0700
Re: Sending USB commands with Python hamilton <hamilton@nothere.com> - 2012-08-28 23:18 -0600
Re: Sending USB commands with Python Tim Roberts <timr@probo.com> - 2012-08-28 23:45 -0700
Re: Sending USB commands with Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-29 16:09 -0400
Re: Sending USB commands with Python "Adam W." <AWasilenko@gmail.com> - 2012-08-29 14:21 -0700
Re: Sending USB commands with Python Tim Roberts <timr@probo.com> - 2012-08-30 20:55 -0700
Re: Sending USB commands with Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-29 17:57 -0400
| From | "Adam W." <AWasilenko@gmail.com> |
|---|---|
| Date | 2012-08-28 17:04 -0700 |
| Subject | Sending USB commands with Python |
| Message-ID | <ff6f931d-e5ad-40ee-aa4d-f2bbd1303046@googlegroups.com> |
So I'm trying to get as low level as I can with my Dymo label printer, and this method described the PDF http://sites.dymo.com/Documents/LW450_Series_Technical_Reference.pdf seems to be it. I'm unfamiliar with dealing with the USB interface and would greatly appreciate it if someone could tell me how to send and receive these commands with Python. Perhaps if you were feeling generous and wanted to write a bit of sample code, sending the "Get Printer Status" command and receiving the response (page 17 of the PDF) would be perfect to get me on my way. Thanks, Adam
[toc] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-08-28 22:54 -0400 |
| Message-ID | <mailman.3918.1346208855.4697.python-list@python.org> |
| In reply to | #28036 |
On Tue, 28 Aug 2012 17:04:49 -0700 (PDT), "Adam W."
<AWasilenko@gmail.com> declaimed the following in
gmane.comp.python.general:
> So I'm trying to get as low level as I can with my Dymo label printer, and this method described the PDF http://sites.dymo.com/Documents/LW450_Series_Technical_Reference.pdf seems to be it.
>
> I'm unfamiliar with dealing with the USB interface and would greatly appreciate it if someone could tell me how to send and receive these commands with Python. Perhaps if you were feeling generous and wanted to write a bit of sample code, sending the "Get Printer Status" command and receiving the response (page 17 of the PDF) would be perfect to get me on my way.
>
1) what OS?
2) does the printer appear as a serial port by the OS? Or as a
printer device?
If it appears as a serial port, you may want to obtain the pyserial
(or whatever the name is this year) package. For USB, you may need one
of the variant USB packages (pywinusb, pyusb, etc.) With luck you won't
need to use admin privileges to access the port as a raw device vs
having to go through an OS driver...
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | hamilton <hamilton@nothere.com> |
|---|---|
| Date | 2012-08-28 21:03 -0600 |
| Message-ID | <k1k0qf$deh$1@dont-email.me> |
| In reply to | #28040 |
On 8/28/2012 8:54 PM, Dennis Lee Bieber wrote: > 2) does the printer appear as a serial port by the OS? Or as a > printer device? The OP posted the link to the manual. If your not going to at least look it over, ......... USB Printer Interface The LabelWriter 450 series printers all communicate with the host computer using a full-speed USB 2.0 interface. This interface also operates with USB Version 1.1 or later. The printers implement the standard USB Printer Class Device interface for communications (see http://www.usb.org/developers/devclass/). hamilton PS: Page 14
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2012-08-28 22:04 -0700 |
| Message-ID | <370e4ff0-80bd-44fb-8b93-00e44f53587c@ou2g2000pbc.googlegroups.com> |
| In reply to | #28041 |
On Aug 29, 1:03 pm, hamilton <hamil...@nothere.com> wrote: > The OP posted the link to the manual. > If your not going to at least look it over, ......... Speaking for myself, I _don't_ go out of my way to read extra material to help someone with a problem here. If it's worth mentioning, mention it in the question.
[toc] | [prev] | [next] | [standalone]
| From | hamilton <hamilton@nothere.com> |
|---|---|
| Date | 2012-08-28 23:18 -0600 |
| Message-ID | <k1k8md$dak$1@dont-email.me> |
| In reply to | #28045 |
On 8/28/2012 11:04 PM, alex23 wrote: > On Aug 29, 1:03 pm, hamilton <hamil...@nothere.com> wrote: >> The OP posted the link to the manual. >> If your not going to at least look it over, ......... > > Speaking for myself, I _don't_ go out of my way to read extra material But, you will give advice that has no value. Anything you post here from now on will be suspect. hamilton
[toc] | [prev] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2012-08-28 23:45 -0700 |
| Message-ID | <d8er38h4ns0obmhevo4v12u0qk2rhufeu8@4ax.com> |
| In reply to | #28036 |
"Adam W." <AWasilenko@gmail.com> wrote: > >So I'm trying to get as low level as I can with my Dymo label printer, >and this method described the PDF >http://sites.dymo.com/Documents/LW450_Series_Technical_Reference.pdf >seems to be it. > >I'm unfamiliar with dealing with the USB interface and would greatly >appreciate it if someone could tell me how to send and receive these >commands with Python. Perhaps if you were feeling generous and >wanted to write a bit of sample code, sending the "Get Printer >Status" command and receiving the response (page 17 of the PDF) >would be perfect to get me on my way. Well, it's more than "a bit of sample code". You would essentially be writing a device driver. Which operating system are you using? If you are on Windows, then the operating system has already loaded a printer driver for this device. You can't talk to the USB pipes without uninstalling that driver. It would be just about as easy for you to learn to use GDI to write to the printer like a normal application, and that way the code would work on the NEXT generation of printer, too. The libusb or libusbx libraries can be used to talk to USB devices. There is a Python binding. On Windows, you still need to have a driver, but the libusbx instructions can help you find an install one. -- Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc.
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-08-29 16:09 -0400 |
| Message-ID | <mailman.3942.1346270988.4697.python-list@python.org> |
| In reply to | #28048 |
On Wed, 29 Aug 2012 05:47:00 -0700 (PDT), "Adam W."
<AWasilenko@gmail.com> declaimed the following in
gmane.comp.python.general:
>
> Trying to do the status thing mentioned before, in the interpreter I did:
>
> >>> ep.write('A')
> 2
>
Don't the commands require an <esc> character? "\x1BA" (or
"\x1B\x41")
OTOH, if the <esc> is issued behind the scenes,
> And the manual says 2 is not a valid option... So something isn't adding up.
... and you do not need to issue some sort of read(), page 17 of the
printer manual you linked would translate to
not ready, top of form, not out of paper, not jammed, not in error
Granted, page 10 implies that the printer will never show "not
ready"
However -- reading the pyUSB source code
-=-=-=-=-
def write(self, data, timeout = None):
r"""Write data to the endpoint.
The parameter data contains the data to be sent to the endpoint
and
timeout is the time limit of the operation. The transfer type
and
endpoint address are automatically inferred.
The method returns the number of bytes written.
For details, see the Device.write() method.
"""
return self.device.write(self.bEndpointAddress, data,
self.interface, timeout)
-=-=-=-=-
indicates that the "2" you are seeing is the "number of bytes written";
you need to issue a read request to retrieve the returned printer
status.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | "Adam W." <AWasilenko@gmail.com> |
|---|---|
| Date | 2012-08-29 14:21 -0700 |
| Message-ID | <mailman.3943.1346275293.4697.python-list@python.org> |
| In reply to | #28071 |
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!
[toc] | [prev] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2012-08-30 20:55 -0700 |
| Message-ID | <pcd04892upqu710bjna9sn43ogplq7lgb9@4ax.com> |
| In reply to | #28072 |
"Adam W." <AWasilenko@gmail.com> wrote:
>
>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)
>usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_setup_async] invalid endpoint 0x02\n'
USB endponts only go in one direction. There will be one endpoint for
outoging data, and one endpoint for incoming data.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-08-29 17:57 -0400 |
| Message-ID | <mailman.3945.1346277475.4697.python-list@python.org> |
| In reply to | #28071 |
On Wed, 29 Aug 2012 14:21:30 -0700 (PDT), "Adam W."
<AWasilenko@gmail.com> declaimed the following in
gmane.comp.python.general:
> 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
That's interesting -- as if each byte you send is expanding into a
pair of bytes.
> >>> 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).
>
Your original code shows you matching to an "OUT" endpoint... Could
you need an "IN" to read the return values?
Unfortunately it will be a few weeks before Amazon ships "USB
Complete" so most of the setup hassle is currently just noise to me.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web