POS Technical Documents
How To Control A Cash Drawer Open With Receipt Printer
Cash drawers that have a cord, like a telephone cord, are to be plugged into receipt printers that have a port for this cord, which is pretty much all receipt printers. Regular computer printers will not have this port.
By "receipt printer" I do not mean any printer that you may be using to print receipts. Receipt printers are specifically designed to print receipts, will usually print only 40 characters per line, print from rolls of paper, and most importantly for our purposes here, will have the "phone" socket to plug in the cash drawer cable.
It is the receipt printer that sends the signal to the cash drawer for it to open. This means that you must send a code to the printer that is specific to the PRINTER to tell it to open the cash drawer. Look on this page "Cash drawer codes" to find the "open cash drawer" codes for specific printers.
Of course for a printer to open a cash drawer it has to be working. If your printer is not printing receipts when it is told to do so, it will not open the cash drawer either even if the proper control code is sent. Make sure that your printer is working.
When you send data to a printer the printer's first inclination is to print it. After all this is what printers do. However in many cases you want to tell the printer to do something, to change a font, underline, open the cash drawer, etc. To let the printer know that it is receiving instructions instead of text to print you send a "control code" to the printer which usually begins with the ASCII character 27 (in decimal) or 1B (in hexadecimal). When the printer receives the character 27 says to itself.
First a little background. Text information is exchanged with printers in what is called ASCII code. This means that when you send a string of text to a printer that the text is converted to ASCII code and then it is the code that is actually transmitted. For example if you wanted to send DALE to a printer it would actually be sent as the ASCII codes 68, 65, 76, 69. Every letter, number, puncuation mark, and symbol has a ASCII code assigned to it. Plus there are other things that are also included. In total there are 256 ASCII codes. (I do know that there is more to ASCII codes than that but for the purpose here that is enough information. So please do not send to me a 9 page email explaining extended ASCII codes et. al. because I already know about that stuff and it would just confuse the issue anyway, thanks.)
To see this work try this. Go to your word processing software. Hold down the [ALT] key and on the numeric key pad at the right of your keyboard type 72 then release the [ALT] key. Do the same thing with the numbers 69, 76, 76, and then 79. Kind of neat, isn't it.
Computers will automatically convert strings of text to ASCII to send it to the printer. This means that if you know the ASCII code you want to send to the printer you must first convert it to a string of text. When your computer then is told to send the string of text to the printer it will convert it back to ASCII code first. Boy, how pointless is that, but that is the way it works.
Here is the BASIC code for doing this.
Let's assume that the control code you must send to your printer to have it open your cash drawer is 27,112,0,50,250.
First you must convert it into a string using this BASIC code...
POPOPEN$ = CHR$(27) + CHR$(112) + CHR$(0) + CHR$(50) + CHR$(250)
Now all you have to do to open your cash drawer (assuming that your printer and cash drawer are properly connected and turned on) is to send the string to the printer using...
LPRINT POPOPEN$
If this does not work then you can test your program code by changing the control code to 65, 66, 67, 68, 69. This is not intended to try to open the cash drawer but will instead print ABCDE on your printer. If ABCDE is not printed then either your printer is not connected properly, or your computer code for creating the string and then sending it to the printer is incorrect.
To test your printer setup, load your word processing software, type in some text, and then print it. Event though it is a receipt printer this test will print if your printer is properly set up and Windows is configured to your printer. If ABCDE is printed but when you send your "pop open" code your drawer does not open then either your cash drawer is not set up correctly or the "pop open" code you are using is incorrect.
It is also possible (another programmer, another program, magic) to store the ASCII string with the codes you need to a computer file. Then all you have to do is to read the file into a string variable and then print the string to your printer.
If the program you are writing will be required to be able to make several different printers open a cash drawer then you have to either have a way for the user to enter in the proper "open cash drawer" code for a specific printer or you will have to have all possible codes in your software and the user will then be able to select the printer.