philpem.me.uk code :: libptouch  

libptouch

A couple of years ago, I bought a Brother PT-1000 label printer, with the intention of printing labels for my electronics component boxes. This turned out to be a reasonably good idea, except for one fact: it was a pain in the neck to make labels for several hundred components by hand!

I later replaced the PT-1000 with a PT-2450DX, which is a desktop label printer with a wider print head, auto-cutter... and a USB connection which allows it to be connected to a desktop PC. Problem is, Brother didn't (and still don't) produce a working Linux driver for it. There's a CUPS driver which sort-of works, but it has severe rendering issues which make text look awful and utterly obliterate barcodes (thus making it rather useless for my project).

So I figured I'd reverse-engineer the protocol and write my own driver. This went pretty well -- my Beagle 480 USB sniffer caught all the basic protocol information (turns out it's just the USB Printer Class protocol, which is supported by the Linux kernel) and the Windows "print to file" option proved useful for dumping the actual print data.

It turns out the protocol is very similar to the "PT-CBP" protocol used by the other PT-series printers. The basics of this are documented on Undocumented Printing, while NKA Design have a complete Command Reference manual available for download. The CRM proved to be very useful for decoding the printer status codes.

libptouch accepts Libgd-format image data as input, then converts this into P-Touch control codes, which are sent directly to the printer.

ptdecode

The source tree includes another useful tool: ptdecode. This reads P-Touch control codes from a file, decodes them and displays them on the screen. Image data is combined back into full labels, and displayed in a graphical window. This tool proved very useful for debugging libptouch -- specifically, it saved me wasting an immeasurable amount of label tape on test prints!

Demo applications

There is only one demo app included with libptouch -- it prints a small label for a component box. You'll need either the "Arial" font (from Microsoft's TrueType Core Fonts package) or Ray Larabie's "Blue Highway" font (though I'd advise replacing this with Expressway; the latter is a much more polished font).

Supported printers

At the moment, only the PT-2430DX is known to work with libptouch. Other printers which use the same control protocol (basically any printer listed on the Undocumented Printing site which has a 180DPI print head and a 16-byte packet format) may also work, however they have not been tested.

The PT-PC is not, and will never be supported: it uses a very unusual control protocol which only allows bitmapped graphics to be printed on the central 3.5mm (!) of a label. This makes the PT-PC rather useless for printing PC-generated labels...

If anyone would like to help add support for other P-touch printers to liblpfk, please contact me via the link on the left.

Download

Other links