customer-display.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * This demo interacts with an Aures OCD-300 customer display,
  4. * showing its support for ESC/POS text encodings.
  5. */
  6. require __DIR__ . '/../vendor/autoload.php';
  7. use Mike42\Escpos\PrintConnectors\FilePrintConnector;
  8. use Mike42\Escpos\CapabilityProfile;
  9. use Mike42\Escpos\Printer;
  10. use Mike42\Escpos\Devices\AuresCustomerDisplay;
  11. /*
  12. * Device appears as a serial port.
  13. *
  14. * stat /dev/ttyACM0
  15. * sudo usermod -a -G dialout [username]
  16. */
  17. $connector = new FilePrintConnector("/dev/ttyACM0");
  18. // Profile and display
  19. $profile = CapabilityProfile::load("OCD-300");
  20. $display = new AuresCustomerDisplay($connector, $profile);
  21. // Make a really long test string
  22. include(__DIR__ . "/resources/character-encoding-test-strings.inc");
  23. $input = "";
  24. foreach ($inputsOk as $str) {
  25. $input .= $str;
  26. }
  27. // Wrap at a fixed width (as ASCII...), and show the user
  28. // what's about to be sent to the printer
  29. $wrapped = wordwrap($input, 20);
  30. echo($wrapped);
  31. // Roll out each line with 0.5s delay
  32. foreach (explode("\n", $wrapped) as $line) {
  33. $display -> feed();
  34. $display -> text($line);
  35. usleep(500000);
  36. }
  37. // Finish by showing "Hello World"
  38. $display -> clear();
  39. $display -> text("Hello World\n");
  40. // Dont forget to close the device
  41. $display -> close();