I am currently writing a system in PHP that requires interface with a USB thermal receipt printer for a friend upon form submission. Currently I have read about interfacing with devices containing a parallel port but there has not been much detail on how I can use PHP to interface with a USB thermal receipt printer.
So far I have designed the receipt consisting of data that has been posted from the form. The next step would be to reproduce it on the thermal printer.
$handle = fopen("PRN", "w"); // note 1
fwrite($handle, 'text to printer'); // note 2
fclose($handle); // note 3
- Establish the connection with the receipt printer through PRN.
- Writes to the receipt printer through the file handle.
- Disconnect the printer.
Well if you are using PHP on a Win32 platform there is the Printers PECL module which can be installed. So you can use the printer using the existing driver setup.
Depending on the printer in use it may be possible to use it directly if you know the command language, EPL/ZPL/etc., set the printer to raw mode and post the commands.
You can access the USB bus from PHP directly, if you setup the USB as a serial port and then use the Direct IO Functions library
dio. Remembering to set serial options using the
mode command before commencement.