Printer Connection error on escpos-php

7.7k views Asked by At

From This link(Printing to POS printer from PHP) i started I have use php sample code. my question is my printer is set to default then why i have to connect to printer. anyway i am getting error on connecting printer. as my printer name is in fig1 and to access printer i have to type \Sah-it\ARP-808K in run as shown in fig2. i have tried:

1.

$connector = new FilePrintConnector("\\Sah-it\ARP-808K");
$printer = new Printer($connector);

2.

$profile = CapabilityProfile::load("simple");
$connector = new WindowsPrintConnector("smb://Sah-it/ARP-808Kr");
$printer = new Printer($connector, $profile);

3.

$connector = new NetworkPrintConnector("\\Sah-it\ARP-808K");
$printer = new Printer($connector);

all gives me connection error. Kindly help me to connect printer. Thanks

Fig1:

enter image description here

Fig2:

enter image description here

1

There are 1 answers

10
Kitson88 On

I've personally not used ESC/POS Print Driver for PHP library but the documentation does state the use in a fairly detailed way. Judging by your images, you have a printer shared from a server called \\Sah-it\ARP-808K. To connect (guessing the printer is an Epson), it's advised you do the following:

    use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
    use Mike42\Escpos\CapabilityProfile;
    $profile = CapabilityProfile::load("simple");
    $connector = new WindowsPrintConnector("smb://Sah-it/ARP-808K");
    $printer = new Printer($connector, $profile);

Note: Suitable for Epson TM-series printers so check documentation to ensure your printer is supported

If your having issues with the above via hostname, then check your PHP servers DNS configuration as it may not be able to resolve Sah-it. In this instance I would suggest trying to connect via IP to the printer (if networked) or to your print-server's IP using the following:

use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
use Mike42\Escpos\Printer;
$connector = new NetworkPrintConnector("10.x.x.x", 9100); //Printer/Server IP
$printer = new Printer($connector);
try {
    // ... Print stuff
} finally {
    $printer -> close();
}

if you have further issues then add your printer make and model, confirm your Webserver can resolve \\Sah-it and add any relevant errors which may help.