Skip to content

Commit 5df72ab

Browse files
committed
first commit
0 parents  commit 5df72ab

19 files changed

+1907
-0
lines changed

COPYING

+674
Large diffs are not rendered by default.

INSTALL

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
python-escpos
2+
=============
3+
4+
Ensure the library is installed on ${lib_arch}/${python_ver}/site-packages/escpos
5+
6+
On CLi you must run:
7+
# python setup.py build
8+
# sudo python setup.py install
9+
10+
On Linux, ensure you belongs to the proper group so you can have access to the printer.
11+
This can be done, by adding yourself to 'dialout' group, this might require to re-login
12+
so the changes make effect.
13+
14+
Then, add the following rule to /etc/udev/rules.d/99-escpos.rules
15+
SUBSYSTEM=="usb", ATTRS{idVendor}=="04b8", ATTRS{idProduct}=="0202", MODE="0664", GROUP="dialout"
16+
17+
and restar udev rules.
18+
# sudo service udev restart
19+
20+
Enjoy !!!
21+
And please, don't forget to ALWAYS add Epson.cut() at the end of your printing :)
22+
23+
Manuel F Martinez <[email protected]>

README.md

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+

build/lib/escpos/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__all__ = ["constants","escpos","exceptions","printer"]

build/lib/escpos/constants.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
""" ESC/POS Commands (Constants) """
2+
3+
# Feed control sequences
4+
CTL_LF = '\x0a' # Print and line feed
5+
CTL_FF = '\x0c' # Form feed
6+
CTL_CR = '\x0d' # Carriage return
7+
CTL_HT = '\x09' # Horizontal tab
8+
CTL_VT = '\x0b' # Vertical tab
9+
# Printer hardware
10+
HW_INIT = '\x1b\x40' # Clear data in buffer and reset modes
11+
HW_SELECT = '\x1b\x3d\x01' # Printer select
12+
HW_RESET = '\x1b\x3f\x0a\x00' # Reset printer hardware
13+
# Cash Drawer
14+
CD_KICK_2 = '\x1b\x70\x00' # Sends a pulse to pin 2 []
15+
CD_KICK_5 = '\x1b\x70\x01' # Sends a pulse to pin 5 []
16+
# Paper
17+
PAPER_FULL_CUT = '\x1d\x56\x00' # Full cut paper
18+
PAPER_PART_CUT = '\x1d\x56\x01' # Partial cut paper
19+
# Text format
20+
TXT_NORMAL = '\x1b\x21\x00' # Normal text
21+
TXT_2HEIGHT = '\x1b\x21\x10' # Double height text
22+
TXT_2WIDTH = '\x1b\x21\x20' # Double width text
23+
TXT_UNDERL_OFF = '\x1b\x2d\x00' # Underline font OFF
24+
TXT_UNDERL_ON = '\x1b\x2d\x01' # Underline font 1-dot ON
25+
TXT_UNDERL2_ON = '\x1b\x2d\x02' # Underline font 2-dot ON
26+
TXT_BOLD_OFF = '\x1b\x45\x00' # Bold font OFF
27+
TXT_BOLD_ON = '\x1b\x45\x01' # Bold font ON
28+
TXT_FONT_A = '\x1b\x4d\x00' # Font type A
29+
TXT_FONT_B = '\x1b\x4d\x01' # Font type B
30+
TXT_ALIGN_LT = '\x1b\x61\x00' # Left justification
31+
TXT_ALIGN_CT = '\x1b\x61\x01' # Centering
32+
TXT_ALIGN_RT = '\x1b\x61\x02' # Right justification
33+
# Barcode format
34+
BARCODE_TXT_OFF = '\x1d\x48\x00' # HRI barcode chars OFF
35+
BARCODE_TXT_ABV = '\x1d\x48\x01' # HRI barcode chars above
36+
BARCODE_TXT_BLW = '\x1d\x48\x02' # HRI barcode chars below
37+
BARCODE_TXT_BTH = '\x1d\x48\x03' # HRI barcode chars both above and below
38+
BARCODE_FONT_A = '\x1d\x66\x00' # Font type A for HRI barcode chars
39+
BARCODE_FONT_B = '\x1d\x66\x01' # Font type B for HRI barcode chars
40+
BARCODE_HEIGHT = '\x1d\x68\x64' # Barcode Height [1-255]
41+
BARCODE_WIDTH = '\x1d\x77\x03' # Barcode Width [2-6]
42+
BARCODE_UPC_A = '\x1d\x6b\x00' # Barcode type UPC-A
43+
BARCODE_UPC_E = '\x1d\x6b\x01' # Barcode type UPC-E
44+
BARCODE_EAN13 = '\x1d\x6b\x02' # Barcode type EAN13
45+
BARCODE_EAN8 = '\x1d\x6b\x03' # Barcode type EAN8
46+
BARCODE_CODE39 = '\x1d\x6b\x04' # Barcode type CODE39
47+
BARCODE_ITF = '\x1d\x6b\x05' # Barcode type ITF
48+
BARCODE_NW7 = '\x1d\x6b\x06' # Barcode type NW7
49+
# Image format
50+
S_RASTER_N = '\x1d\x76\x30\x00' # Set raster image normal size
51+
S_RASTER_2W = '\x1d\x76\x30\x01' # Set raster image double width
52+
S_RASTER_2H = '\x1d\x76\x30\x02' # Set raster image double height
53+
S_RASTER_Q = '\x1d\x76\x30\x03' # Set raster image quadruple

0 commit comments

Comments
 (0)