-
Notifications
You must be signed in to change notification settings - Fork 856
/
linux-usb.php
33 lines (30 loc) · 1.15 KB
/
linux-usb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/* Change to the correct path if you copy this example! */
require __DIR__ . '/../../vendor/autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
/**
* On Linux, use the usblp module to make your printer available as a device
* file. This is generally the default behaviour if you don't install any
* vendor drivers.
*
* Once this is done, use a FilePrintConnector to open the device.
*
* Troubleshooting: On Debian, you must be in the lp group to access this file.
* dmesg to see what happens when you plug in your printer to make sure no
* other drivers are unloading the module.
*/
try {
// Enter the device file for your USB printer here
$connector = new FilePrintConnector("/dev/usb/lp0");
//$connector = new FilePrintConnector("/dev/usb/lp1");
//$connector = new FilePrintConnector("/dev/usb/lp2");
/* Print a "Hello world" receipt" */
$printer = new Printer($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";
}