397. How to interface to receipt printer in a point of sale system?

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 link to a receipt printer as shown below.

How to interface to receipt printer in a point of sale system?


Solution

  • A standard receipt printer such as the Epson TM-T88III receipt printer uses the parallel port.
  • To print to the parallel-port receipt printer, you print through port PRN (exactly the same as printing from DOS prompt).
  • From within PHP-GTK2, you need to first establish the connection with the printer by using
    $handle = fopen("PRN", "w");
  • Thereafter, to print anything to the printer, you just "write" to it like the file handle: fwrite($handle, 'text to printer');
  • There are newer receipt printer that uses USB. I believe you should be able to print to such printers through PRN too.

Sample Code

1   
2   
3   
4   
5   
<?php
$handle = fopen("PRN", "w"); // note 1
fwrite($handle, 'text to printer'); // note 2
fclose($handle); // note 3
?>

Output

 

Explanation

  1. Establish the connection with the receipt printer through PRN.
  2. Writes to the receipt printer through the file handle.
  3. Disconnect the printer.

Related Links

Add comment


Security code
Refresh