项目作者: gdsports

项目描述 :
USB Printer driver for USB Host Shield 2.0 Library
高级语言: C++
项目地址: git://github.com/gdsports/USBPrinter_uhs2.git
创建时间: 2019-06-29T02:32:36Z
项目社区:https://github.com/gdsports/USBPrinter_uhs2

开源协议:MIT License

下载


USBPrinter driver for USB Host Shield 2.0 Library

This driver is designed to work for small USB thermal printers. Do not expect
this to work for laser or inkjet printers because they require complex software
support.

This has been tested with USB Host Shield Library 2.0 with one required patch
and the ESC POS Printer library on a Uno.

https://github.com/felis/USB_Host_Shield_2.0

Required patch not merged yet

https://github.com/felis/USB_Host_Shield_2.0/pull/473

https://github.com/gdsports/ESC_POS_Printer

Sample program that prints “Hello Printer” in large letters.

  1. #include "USBPrinter.h" // https://github.com/gdsports/USBPrinter_uhs2
  2. #include "ESC_POS_Printer.h" // https://github.com/gdsports/ESC_POS_Printer
  3. class PrinterOper : public USBPrinterAsyncOper
  4. {
  5. public:
  6. uint8_t OnInit(USBPrinter *pPrinter);
  7. };
  8. uint8_t PrinterOper::OnInit(USBPrinter *pPrinter)
  9. {
  10. Serial.println(F("USB Printer OnInit"));
  11. Serial.print(F("Bidirectional="));
  12. Serial.println(pPrinter->isBidirectional());
  13. return 0;
  14. }
  15. USB myusb;
  16. PrinterOper AsyncOper;
  17. USBPrinter uprinter(&myusb, &AsyncOper);
  18. ESC_POS_Printer printer(&uprinter);
  19. void setup() {
  20. Serial.begin(115200);
  21. while (!Serial && millis() < 3000) delay(1);
  22. if (myusb.Init()) {
  23. Serial.println(F("USB host failed to initialize"));
  24. while (1) delay(1);
  25. }
  26. Serial.println(F("USB Host init OK"));
  27. }
  28. void loop() {
  29. myusb.Task();
  30. // Make sure USB printer found and ready
  31. if (uprinter.isReady()) {
  32. printer.begin();
  33. Serial.println(F("Init ESC POS printer"));
  34. printer.setSize('L'); // L for large
  35. printer.println(F("Hello Printer"));
  36. printer.feed(2);
  37. // Do this one time to avoid wasting paper
  38. while (1) delay(1);
  39. }
  40. }

The ESC POS library send printer ESC/POS commands for different font sizes,
graphics mode, etc. It is based on the Adafruit Thermal printer library but
modified to work with USB thermal receipt printers. Note different thermal
printers from even if from the same manufacturers implement different subsets
of the ESC POS commands. You will have to find the ones that work on your
printer.

The following driver works on SAMD board with USB OTG ports such as Arduino Zero and MKR family.

https://github.com/gdsports/USBPrinter_uhls

The following driver works on Teensy 3.6 boards.

https://github.com/gdsports/USBPrinter_t36