I'm trying to print a QR Code with my Epson TM-T88IV serial printer using php. However, my php file installed on a server and I'm able to call it succesfully from a html file. I'm using a library called ESCPOS-PHP (https://github.com/mike42/escpos-php) and the computer is running Windows XP Professional. Here's my php snippet (there's more in the middle, but not needed for the printing action):
<?php
require __DIR__. '/escpos-php-master/Escpos.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
[...]
try {
$connector = new WindowsPrintConnector("EPSON TM-T88IV Receipt");
$printer = new Escpos($connector);
$printer -> text("Hello World!\n");
$printer -> cut();
// Close printer
$printer -> close();
} catch(Exception $e) {
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
}
?>
Seems like I just can't connect to the printer. I also tried with
$connector = new FilePrintConnector("/dev/ttyS0");
$printer = new Printer($connector);
Which is supposed to be the way with serial printer (I'm not sure what I should put instead of "/dev/ttsyS0"). Maybe I shouldn't try to trigger it via the server ? I'm doing it because I can't modify his POS system (Maitre D) and I need an easy way to print QR code on bills. If you know any workaroung, any advice would be appreciated ! Thanks
Author of escpos-php here.
The escpos-php README suggests that you should try to send data to your printer on the command-line first, because it will allow you to determine how you are going to print before attempting to use the driver.
For example, if you intended to set up your printer on COM1, you can try to type:
echo "Hello world" > COM1
Which corresponds with:
<?php
$connector = new FilePrintConnector("COM1");
$printer = new Escpos($connector);
$printer -> text("Hello World\n");
The WindowsPrintConnector is for connecting to Windows shared printers. This example has some helpful commands to make sure you can print before you open PHP. Eg,
echo "Hello world" > foo.txt
net use "\\computername\Receipt Printer" /user:Bob secret
copy testfile "\\computername\Receipt Printer"
del testfile
This corresponds with:
<?php
$connector = new WindowsPrintConnector("smb://bob:secret@computername/Receipt Printer");
$printer = new Escpos($connector);
$printer -> text("Hello World\n");
In any case, two gotchas: