When you think of the small machines that print the sticky labels on packages, you might not expect to find a complex printer with its own programming language (ZPL). However, [Dan Pastusek] was looking around online and found a small label printer on everyone’s favorite online warehouse for a great price that suggested it supported ZPL. Unfortunately, [Dan] had big dreams for creating a Raspberry Pi-based print station and found the drivers packaged for this particular printer were not ARM compatible. Not quite content to leave it there, he began to chip away at the layers until he had a working driver.
ZPL, at its core, is just a language describing ASCII commands transmitted over a serial connection. So while the printer showed up as an endpoint, it wasn’t working as the filters (the part of the driver that knows how to convert from a PNG to ZPL) was x86 only. On Linux, printer drivers also have a PPD file that describes what a printer can handle in paper size and other settings. The PPD file for the little printer gave the first clue. In the ShortNickName field, it identifies itself as HPRT N41, which is a popular HP printer. So this little printer must be a clone of a printer in that family. Notably, they don’t support ZPL. Instead, the HPRT series support TSPL, another printer language developed by TSC.
This presented a problem as the shipping service that provided the labels that [Dan] was using offered labels in three formats: PNG, PDF, and ZPL. Currently, it does seem like there’s a TSPL to ZPL converter out there for use, so rather than write his own, he took a shortcut and wrote a rasterizer instead. Initially, he tried to use some sample code that he found, and while he got something to come out of the printer, it was blank. So the next test was to save the raw TSPL output from a filer and cat directly to the serial port. This worked amazingly. Next, he wrote a converter to take a PNG and convert them into the bitmap format the TSPL has. The converter is in Javascript as it runs as part of the webserver that manages the print station. Could it be faster in a different language? Sure. But a different language wouldn’t make the printer any faster.
With the addition of a wireless barcode scanner, it’s satisfying to see the print station up and running. Here at Hackaday, we’re no stranger to seeing folks take apart printers to peel back the software and physical layers that make them up.
I did one ZPL driver for MSP430 twenty years back.
Was pretty funny to throw graphics from an i2c flash chip to paper.
I use to write a web page that directly sends commands to label printer, not so hard to use ZPL (Zebra) or SBPL (SATO) just really sending commands: move position, rotate, put same string, barcode, maybe the image part is hardest as you have to extend/truncate image to match size that can dived with 8.
Fine
I had a similar challenge and solved by going multiarch on debian!
an i386 printer driver works amazingly good on ARM64
Interestingly, I recently dug into CUPS rasterizing and it should be fairly simple to modify the CUPS “rastertolabel” filter to support TSPL.
As for his dream of a print server, it could probably be pulled off using a ESP32.
This is really funny, today I start working on module to print customs declaration directly to a ZPL printer, and found this article :)
I am currently working on making a shipping appliance in python, with modules to deal with ebay, prestashop and other market places. Currently, in my business, it helps me a lot: I only need 1 minute to print the shipping label, the receipt, take a picture of the packet, and send an email to the customer.
I did this 10 years ago, and using that code for now :)
Simply send the ZPL file to the printer via the port, or if the printer is on network, to the port 6101 on the printer’s IP :D It will interpret and print :D
Yes, I managed to make some labels already using ZPL. The problem is to find a way to generate a preview prior to print the label (the appliance I’ve built has a GUI with big buttons for my big fingers :).
Every piece of code I have found to do so is based on a call to a web site (http://labelary.com). If you know how I could render a ZPL into something else (may it be an image, a PDF, or anything viewable), I’ll be interested :)
That will be a hard part… You need a ZPL interpreter, which i haven’t seen before. I wonder about there are sites like Labelary, as Zebra owns the rights of ZPL…
Either render as emulating printer, or try to save printer memory and cancel print. (Second option cannot produce preview without working printer)
ZPL has command like this:
^IS – Image Save
and
^HY – Upload Graphics
The ^HY command is an extension of the ^HG command. ^HY is used to upload graphic objects from
the printer in any supported format.
Thanks a lot ! You pointed the right information. Thanks a lot !
ZPL is the language of Zebra technologies, for their own printers. It’s well documented. In fact, you can send images in binary format in ZPL. Anyway, nice work!
ZPL is a well documentes language for Zebra Technologies printers. If you simply send the code to the printer (on serial/parallel/or on the network port 6101 , it will interpret and print. The images are binary data… but it know many barcode styles also.
Anyway, nice work!
HPRT has nothing to do with HP (Hewlett Packard) afaik.
The most common control language for printers is Epson Standard Code for Printers or ESC/P, or more precisely for receipt printers it is ESC/POS.[1][2] POS stands for Point-Of-Sale. Coincidentally the commands begin with the ASCII escape character (ESC) 0x1B hex.[3]
1. ESC/P – Variants
https://en.wikipedia.org/wiki/ESC%2FP#Variants
2. FAQ about ESC/POS – Epson Seiko 2002-12 [pdf]
https://web.archive.org/web/20200110095204/http://content.epson.de/fileadmin/content/files/RSD/downloads/escpos.pdf
3. Escape Character, ASCII
https://en.wikipedia.org/wiki/Escape_character#ASCII_escape_character
My curiosity is triggered by them offering ZBI module – Zebra BASIC Interpreter running on printer! Includes PC emulation for development. :-)