Typica: Software for Coffee Roasting Operations

Batch Tag Printing

Some of the more recent changes to the New Batch window in Typica exist to make it easier for someone to write a tag to accompany a batch of coffee in a way that uniquely identifies the batch. It's always been possible to do this with just the machine ID (if using more than one coffee roasting machine) and the time stamp, but the file ID is a shorter number and easier to write down. Still, sometimes people get lazy about writing things down and someone less experienced might abbreviate the documentation to the point that it's no longer possible to tell exactly what the roasted coffee is without doing some comparison testing against known possibilities. Wouldn't it be nice if it were possible to get rid of this manual data transcription entirely?

Considering that, I started thinking about just letting Typica print batch tags. I didn't want these to print from a printer that I already had since it would be awkward to work with a full 8.5 by 11 inch sheet of paper clipped to the side of a bucket, the laser printer in the roasting area is too slow to warm up, and it would add up to a pretty big waste of paper over time. Instead, I picked up a cheap thermal receipt printer that could take the same paper that's already used in my cash registers and credit card terminal.

Since I do most of my programming on a laptop running Linux, I plugged the printer in once it arrived and found that it showed up as /dev/usb/lp0. Great! Since the printer advertises that it understands the ESC/POS command set, I could just write bytes directly to the printer. There are several great posts about programmatically dealing with printers like this over on Mike's Blog so I'm not going to go into a lot of technical detail here.

While a full sheet of paper is too large to conveniently use as a batch tag on the size of buckets that I use, a receipt with just a few lines of text to identify a batch is a bit too small to conveniently handle, so I thought I'd add a bar code to the tag. There are lots of possibilities for future software development where it would be very convenient to be able to just scan a bar code instead of needing to type things in or find appropriate records in a list. Unfortunately, while all of the documentation for the printer that I can find indicates that it understands commands for several types of bar codes, sending the appropriate bytes to the printer didn't result in bar codes coming out of the printer.

At this point, I decided to try installing the printer driver. This would let me use whatever the printing system is, just with pages that are only 58mm wide. For a machine readable code, I found a bit of JavaScript that produces a QR code in SVG which can be injected into a web view. It's license compatible with Typica and only required a couple of very minor modifications to be compatible with Typica's scripting environment.

This seemed to work well, but I soon discovered another problem. Sometimes the printer would, instead of printing the entire tag, just fail part way through the QR code. It turned out that this was related to the size of the code requested. At 190 pixels square, it worked fine. Any larger and it would fail too often.

Early on, I thought that I wanted to make it possible to configure Typica to print these tags automatically, but since my printer doesn't have a cutter and my larger batches are split between two buckets which would each need a tag, I decided that it was better to keep printing as a manual operation. The problem with this is that even on a computer dedicated to coffee roasting it's likely that the receipt printer wouldn't be the system default printer. Going to the File menu, selecting Print (or hitting Control+P), selecting the right printer, and hitting the print button for every single batch would get tedious quickly, so I decided to add another set of controls under the tag preview.

With a list of all of the available printers and a print button, I could bypass the usual print dialog and remember a default printer just for these batch tags. That worked, but I quickly discovered that if I bypass the print dialog, margin settings that had been saved there no longer applied. With such a small width available to work with, I couldn't spare any on excessively wide system default margins, so one more small tweak to Typica to do the drawing in full page mode when printing directly to a named printer like that got me the results that I was looking for.

Feature Preview Video

Once things seemed to be working reliably on Linux, I tried it on Windows and discovered that everything was working fine there as well. After trying it in production for a few days I feel comfortable with putting this feature into the next release of Typica which I hope to have out soon.

Now I can hear you asking, "what if I have a printer that uses paper wider than 58mm and I want to use that instead?" I've separated out the CSS that's used to control layout on the tags into its own file and tried to make it easy to see how this could be edited to better fit wider printers. That's reloaded every time a new New Batch window is opened and there's a tag available for test printing even before entering any data so it's easy to try things out until you find a style you like.