Cash drawer

Programming an accounting software is a dull job, so hard to find any kind of challenge. There was however one interesting problem. The software was recording transactions from customers and printing bills, very simple. The printer was a small cashier style printer connected to cash drawer with RJ11 connector.

Everytime the bill is printed the cash drawer is opened automatically. It is a standard behavior of a cashier printer and can be enabled in driver settings. One of the program features was to make a function that opens the cash drawer without printing any bill.

The tricky part is that the cash drawer is connected only to the printer and not the computer itself. So the opening command must come from the printer. By looking into printer's documentation I found series of commands required for generating pulse to open the drawer.

As you can see the command contains five ASCII characters:

16 + 20 + 1 + 0 + 3

In .NET there is a helper object called RawPrinterHelper provided by Microsoft which can be used for sending raw commands to the printer. The code can be found on this website. I added the code into the project and ended up making this function:

private void OpenDrawer()
   var command = 
   Char.ConvertFromUtf32(16) +
   Char.ConvertFromUtf32(20) +
   Char.ConvertFromUtf32(1) +
   Char.ConvertFromUtf32(0) +

   RawPrinterHelper.SendStringToPrinter(printer.PrinterSettings.PrinterName, command);

Calling OpenDrawer() does really open the drawer without printing any paper.