linux-usb.php 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /* Change to the correct path if you copy this example! */
  3. require_once(dirname(__FILE__) . "/../../Escpos.php");
  4. /**
  5. * On Linux, use the usblp module to make your printer available as a device
  6. * file. This is generally the default behaviour if you don't install any
  7. * vendor drivers.
  8. *
  9. * Once this is done, use a FilePrintConnector to open the device.
  10. *
  11. * Troubleshooting: On Debian, you must be in the lp group to access this file.
  12. * dmesg to see what happens when you plug in your printer to make sure no
  13. * other drivers are unloading the module.
  14. */
  15. try {
  16. // Enter the device file for your USB printer here
  17. $connector = null;
  18. //$connector = new FilePrintConnector("/dev/usb/lp0");
  19. //$connector = new FilePrintConnector("/dev/usb/lp1");
  20. //$connector = new FilePrintConnector("/dev/usb/lp2");
  21. /* Print a "Hello world" receipt" */
  22. $printer = new Escpos($connector);
  23. $printer -> text("Hello World!\n");
  24. $printer -> cut();
  25. /* Close printer */
  26. $printer -> close();
  27. } catch(Exception $e) {
  28. echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
  29. }