1
votes

I am using ESC/POS Print Driver for PHP (https://github.com/mike42/escpos-php/) for thermal printing ,

I have successfully took my first print with following code :

require __DIR__ . '/autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;

$connector = new NetworkPrintConnector("192.xxx.x.xxx");
$printer = new Printer($connector);
    $printer -> text("this is my first print");
    $printer -> feed();
    $printer -> feed();
    $printer -> cut();
    $printer -> close();

Now, I want that if printer is not working then an error should display to user (basic troubleshoot like Plug is off, power disconnected, out of paper.)

Please suggest me an option to do this.

Thanks in Advance

1

1 Answers

2
votes

You can use a try{ } catch { } to find issues with the initialization of NetworkPrintConnector. This will catch some show-stopper issues, such as a printer that is powered off or inaccessible over the network.

For a printer error like "cover open" or "out of paper", the exact way to find the status varies between printer manufacturers. No method is availble in escpos-php at the time of writing for getting the printer status.

If you are have a networked Epson printer, then you can use the Auto-Status-Back (ASB) feature on the embedded print server, which involves sending a UDP datagram and parsing the response: example.