|
| 1 | +ESCPOS |
| 2 | +====== |
| 3 | + |
| 4 | +## Description |
| 5 | + |
| 6 | +Python ESC/POS is a library which lets the user have access to all those printers handled by ESC/POS commands, as defined by Epson, from a Python application. |
| 7 | + |
| 8 | +The standard usage is send raw text to the printer, but in also helps the user to enhance the experience with those printers by facilitating the bar code printing in many different standards,as well as manipulating images so they can be printed as brand logo or any other usage images migh have. |
| 9 | + |
| 10 | +Text can be justified and fonts can be changed by size, type and weight. |
| 11 | + |
| 12 | +Also, this module handles some hardware functionalities like, cut paper, cash drawer kicking, printer reset, carriage return and others concerned to the carriage alignment. |
| 13 | + |
| 14 | +## Dependencies |
| 15 | + |
| 16 | +In order to start getting access to your printer, you must ensure |
| 17 | +you have previously installed the following python modules: |
| 18 | + |
| 19 | + * pyusb (python-usb) |
| 20 | + * PIL (Python Image Library) |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +------------------------------------------------------------------ |
| 25 | +## Define your printer |
| 26 | + |
| 27 | +### USB printer |
| 28 | + |
| 29 | +Before start creating your Python ESC/POS printer instance, you must see at your system for the printer parameters. This is done with the 'lsusb' command. |
| 30 | + |
| 31 | +First run the command to look for the "Vendor ID" and "Product ID", then write down the values, these values are displayed just before the name of the device with the following format: |
| 32 | + |
| 33 | + xxxx:xxxx |
| 34 | + |
| 35 | +Example: |
| 36 | + |
| 37 | + # lsusb |
| 38 | + Bus 002 Device 001: ID 04b8:0202 Epson ... |
| 39 | + |
| 40 | +Write down the the values in question, then issue the following command so you can get the "Interface" number and "End Point" |
| 41 | + |
| 42 | + # lsusb -vvv -d xxxx:xxxx | grep iInterface |
| 43 | + iInterface 0 |
| 44 | + # lsusb -vvv -d xxxx:xxxx | grep bEndpointAddress | grep OUT |
| 45 | + bEndpointAddress 0x01 EP 1 OUT |
| 46 | + |
| 47 | +The first command will yields the "Interface" number that must be handy to have and the second yields the "Output Endpoint" address. |
| 48 | + |
| 49 | +#### USB Printer initialization |
| 50 | + |
| 51 | + Epson = printer.Usb(0x04b8,0x0202) |
| 52 | + |
| 53 | +#### USB Printer initialization - custom |
| 54 | + |
| 55 | +By default the "Interface" number is "0" and the "Output Endpoint" address is "0x01", if you |
| 56 | +have other values then you can define with your instance. So, assuming that we have another printer where in_ep is on 0x81 and out_ep=0x02, then the printer definition should looks like: |
| 57 | + |
| 58 | + Generic = printer.Usb(0x1a2b,0x1a2b,0,0x81,0x02) |
| 59 | + |
| 60 | +### Network printer |
| 61 | + |
| 62 | +You only need the IP of your printer, either because it is getting its IP by DHCP or you set it manually. Network Printer initialization |
| 63 | + |
| 64 | + Epson = printer.Network("192.168.1.99") |
| 65 | + |
| 66 | +### Serial printer |
| 67 | + |
| 68 | +Must of the default values set by the DIP switches for the serial printers, have been set as default on the serial printer class, so the only thing you need to know is which serial port the printer is hooked up. Serial printer initialization |
| 69 | + |
| 70 | + Epson = printer.Serial("/dev/tty0") |
| 71 | + |
| 72 | +## Define your instance |
| 73 | + |
| 74 | +The following example demonstrate how to initialize the Epson TM-TI88IV on USB interface |
| 75 | + |
| 76 | + from escpos import * |
| 77 | + """ Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """ |
| 78 | + Epson = printer.Usb(0x04b8,0x0202) |
| 79 | + # Print text |
| 80 | + Epson.text("Hello World\n") |
| 81 | + # Print image |
| 82 | + Epson.image("logo.gif") |
| 83 | + # Print QR Code |
| 84 | + Epson.qr("You can readme from your smartphone") |
| 85 | + # Print barcode |
| 86 | + Epson.barcode('1324354657687','EAN13',64,2,'','') |
| 87 | + # Cut paper |
| 88 | + Epson.cut() |
| 89 | + |
| 90 | +## Links |
| 91 | + |
| 92 | +Please visit project homepage at: <http://repo.bashlinux.com/projects/escpos.html> |
| 93 | + |
| 94 | +Manuel F Martinez <[email protected]> |
| 95 | + |
0 commit comments