-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5df72ab
Showing
19 changed files
with
1,907 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
python-escpos | ||
============= | ||
|
||
Ensure the library is installed on ${lib_arch}/${python_ver}/site-packages/escpos | ||
|
||
On CLi you must run: | ||
# python setup.py build | ||
# sudo python setup.py install | ||
|
||
On Linux, ensure you belongs to the proper group so you can have access to the printer. | ||
This can be done, by adding yourself to 'dialout' group, this might require to re-login | ||
so the changes make effect. | ||
|
||
Then, add the following rule to /etc/udev/rules.d/99-escpos.rules | ||
SUBSYSTEM=="usb", ATTRS{idVendor}=="04b8", ATTRS{idProduct}=="0202", MODE="0664", GROUP="dialout" | ||
|
||
and restar udev rules. | ||
# sudo service udev restart | ||
|
||
Enjoy !!! | ||
And please, don't forget to ALWAYS add Epson.cut() at the end of your printing :) | ||
|
||
Manuel F Martinez <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
ESCPOS | ||
====== | ||
|
||
## Description | ||
|
||
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. | ||
|
||
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. | ||
|
||
Text can be justified and fonts can be changed by size, type and weight. | ||
|
||
Also, this module handles some hardware functionalities like, cut paper, cash drawer kicking, printer reset, carriage return and others concerned to the carriage alignment. | ||
|
||
## Dependencies | ||
|
||
In order to start getting access to your printer, you must ensure | ||
you have previously installed the following python modules: | ||
|
||
* pyusb (python-usb) | ||
* PIL (Python Image Library) | ||
|
||
|
||
|
||
------------------------------------------------------------------ | ||
## Define your printer | ||
|
||
### USB printer | ||
|
||
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. | ||
|
||
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: | ||
|
||
xxxx:xxxx | ||
|
||
Example: | ||
|
||
# lsusb | ||
Bus 002 Device 001: ID 04b8:0202 Epson ... | ||
|
||
Write down the the values in question, then issue the following command so you can get the "Interface" number and "End Point" | ||
|
||
# lsusb -vvv -d xxxx:xxxx | grep iInterface | ||
iInterface 0 | ||
# lsusb -vvv -d xxxx:xxxx | grep bEndpointAddress | grep OUT | ||
bEndpointAddress 0x01 EP 1 OUT | ||
The first command will yields the "Interface" number that must be handy to have and the second yields the "Output Endpoint" address. | ||
|
||
#### USB Printer initialization | ||
|
||
Epson = printer.Usb(0x04b8,0x0202) | ||
|
||
#### USB Printer initialization - custom | ||
|
||
By default the "Interface" number is "0" and the "Output Endpoint" address is "0x01", if you | ||
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: | ||
|
||
Generic = printer.Usb(0x1a2b,0x1a2b,0,0x81,0x02) | ||
|
||
### Network printer | ||
|
||
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 | ||
|
||
Epson = printer.Network("192.168.1.99") | ||
|
||
### Serial printer | ||
|
||
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 | ||
|
||
Epson = printer.Serial("/dev/tty0") | ||
|
||
## Define your instance | ||
|
||
The following example demonstrate how to initialize the Epson TM-TI88IV on USB interface | ||
|
||
from escpos import * | ||
""" Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """ | ||
Epson = printer.Usb(0x04b8,0x0202) | ||
# Print text | ||
Epson.text("Hello World\n") | ||
# Print image | ||
Epson.image("logo.gif") | ||
# Print QR Code | ||
Epson.qr("You can readme from your smartphone") | ||
# Print barcode | ||
Epson.barcode('1324354657687','EAN13',64,2,'','') | ||
# Cut paper | ||
Epson.cut() | ||
|
||
## Links | ||
|
||
Please visit project homepage at: <http://repo.bashlinux.com/projects/escpos.html> | ||
|
||
Manuel F Martinez <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__all__ = ["constants","escpos","exceptions","printer"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" ESC/POS Commands (Constants) """ | ||
|
||
# Feed control sequences | ||
CTL_LF = '\x0a' # Print and line feed | ||
CTL_FF = '\x0c' # Form feed | ||
CTL_CR = '\x0d' # Carriage return | ||
CTL_HT = '\x09' # Horizontal tab | ||
CTL_VT = '\x0b' # Vertical tab | ||
# Printer hardware | ||
HW_INIT = '\x1b\x40' # Clear data in buffer and reset modes | ||
HW_SELECT = '\x1b\x3d\x01' # Printer select | ||
HW_RESET = '\x1b\x3f\x0a\x00' # Reset printer hardware | ||
# Cash Drawer | ||
CD_KICK_2 = '\x1b\x70\x00' # Sends a pulse to pin 2 [] | ||
CD_KICK_5 = '\x1b\x70\x01' # Sends a pulse to pin 5 [] | ||
# Paper | ||
PAPER_FULL_CUT = '\x1d\x56\x00' # Full cut paper | ||
PAPER_PART_CUT = '\x1d\x56\x01' # Partial cut paper | ||
# Text format | ||
TXT_NORMAL = '\x1b\x21\x00' # Normal text | ||
TXT_2HEIGHT = '\x1b\x21\x10' # Double height text | ||
TXT_2WIDTH = '\x1b\x21\x20' # Double width text | ||
TXT_UNDERL_OFF = '\x1b\x2d\x00' # Underline font OFF | ||
TXT_UNDERL_ON = '\x1b\x2d\x01' # Underline font 1-dot ON | ||
TXT_UNDERL2_ON = '\x1b\x2d\x02' # Underline font 2-dot ON | ||
TXT_BOLD_OFF = '\x1b\x45\x00' # Bold font OFF | ||
TXT_BOLD_ON = '\x1b\x45\x01' # Bold font ON | ||
TXT_FONT_A = '\x1b\x4d\x00' # Font type A | ||
TXT_FONT_B = '\x1b\x4d\x01' # Font type B | ||
TXT_ALIGN_LT = '\x1b\x61\x00' # Left justification | ||
TXT_ALIGN_CT = '\x1b\x61\x01' # Centering | ||
TXT_ALIGN_RT = '\x1b\x61\x02' # Right justification | ||
# Barcode format | ||
BARCODE_TXT_OFF = '\x1d\x48\x00' # HRI barcode chars OFF | ||
BARCODE_TXT_ABV = '\x1d\x48\x01' # HRI barcode chars above | ||
BARCODE_TXT_BLW = '\x1d\x48\x02' # HRI barcode chars below | ||
BARCODE_TXT_BTH = '\x1d\x48\x03' # HRI barcode chars both above and below | ||
BARCODE_FONT_A = '\x1d\x66\x00' # Font type A for HRI barcode chars | ||
BARCODE_FONT_B = '\x1d\x66\x01' # Font type B for HRI barcode chars | ||
BARCODE_HEIGHT = '\x1d\x68\x64' # Barcode Height [1-255] | ||
BARCODE_WIDTH = '\x1d\x77\x03' # Barcode Width [2-6] | ||
BARCODE_UPC_A = '\x1d\x6b\x00' # Barcode type UPC-A | ||
BARCODE_UPC_E = '\x1d\x6b\x01' # Barcode type UPC-E | ||
BARCODE_EAN13 = '\x1d\x6b\x02' # Barcode type EAN13 | ||
BARCODE_EAN8 = '\x1d\x6b\x03' # Barcode type EAN8 | ||
BARCODE_CODE39 = '\x1d\x6b\x04' # Barcode type CODE39 | ||
BARCODE_ITF = '\x1d\x6b\x05' # Barcode type ITF | ||
BARCODE_NW7 = '\x1d\x6b\x06' # Barcode type NW7 | ||
# Image format | ||
S_RASTER_N = '\x1d\x76\x30\x00' # Set raster image normal size | ||
S_RASTER_2W = '\x1d\x76\x30\x01' # Set raster image double width | ||
S_RASTER_2H = '\x1d\x76\x30\x02' # Set raster image double height | ||
S_RASTER_Q = '\x1d\x76\x30\x03' # Set raster image quadruple |
Oops, something went wrong.