PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 398: How to kick open the cash drawer of a point of sale system?
Written by kksou   
Monday, 24 December 2007
Problem

This is in response to duez1981's post titled 'php-gtk2 point of sale system'.

He is writing a point-of-sale (POS) system using PHP-GTK2, and he wants to know how to kick open the cash drawer as shown below.

How to kick open the cash drawer of a point of sale system?


Solution
  • For a standard cash drawer, there's a physical cable that runs from the cash drawer and plugs into the receipt printer.
  • To open the drawer, you issue a command to the printer. The printer will send a signal to the cash drawer that kicks open the drawer.
  • For a standard epson receipt printer such as the Epson TM-T88III receipt printer, the command is:
    fwrite($handle, chr(27). chr(112). chr(0). chr(100). chr(250));
  • For other receipt printers, you should be able to find the command in their user's manual. (Try the above code first. Most probably it will work. Receipt printers have been in existence for a long time. They have more or less adopted the same standard.)

Note: To print to a receipt printer, please refer to the article How to interface to receipt printer in a point of sale system?


Sample Code
1   
2   
3   
4   
<?php
$handle = fopen("PRN", "w"); // note 1
fwrite($handle, 'text to printer'); // note 2
fwrite($handle, chr(27).chr(112).chr(0).chr(100).chr(250)); // note 3
  • Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
  • Registration is free and immediate.
  • Have some doubt about the registration? Please read this forum article.
Explanation
  1. Establish the connection with the receipt printer through PRN. Pkease refer to How to interface to receipt printer in a point of sale system? for more explanations.
  2. Writes to the receipt printer through the file handle.
  3. Kicks open the cash drawer.
  4. Disconnect the printer.

Related Links

User reviews   Average user ratings:    5.0   (from 8 users)
  1. logam sunwares
    July 29, 2008 1:11am

  2. gtualek
    August 02, 2009 12:11am

  3. sakda
    December 29, 2009 8:22pm
    i want open cash drawer by php code

    i need to open cash drawer by php code
    can i? ....

  4. sakda
    February 07, 2010 7:01pm
    can open cashdrawer by usb printer ????

    i have usb printer how can i kick cashdrawer open ???

  5. sakda
    February 15, 2010 9:09pm
    how to fix text to left or right when print to the printer

    i need to adjust the text on the printer to left or right on the paper what the code to command please help ....
    thanks advance

  6. kksou
    February 15, 2010 11:27pm

    Hi Sakda,

    Every printer is different. You have to dig out your printer manual and check what's the code to set the left or right margin.

    Regards,
    /kksou

  7. sakda
    May 27, 2010 6:29am
    print reverse feed

    i need to reverse feed the receipt printer (EPSON - TMU950) by use code
    chr(27).chr(45).chr(48) but not work ...
    anyone help or suggest me ? pls.
    M.Thanks >>>>

  8. parinya
    August 09, 2010 12:23am

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2009. kksou.com. All Rights Reserved