2013-02-27 12:31:18 +00:00
|
|
|
ESCPOS
|
|
|
|
======
|
|
|
|
|
|
|
|
Python library to manipulate ESC/POS Printers.
|
|
|
|
|
2014-03-14 17:01:15 +00:00
|
|
|
Description
|
2013-02-27 12:32:43 +00:00
|
|
|
------------------------------------------------------------------
|
2013-02-27 12:31:18 +00:00
|
|
|
|
|
|
|
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 aligned/justified and fonts can be changed by size,
|
|
|
|
type and weight.
|
|
|
|
|
|
|
|
Also, this module handles some hardware functionalities like, cut
|
|
|
|
paper, carrier return, printer reset and others concerned to the
|
|
|
|
carriage alignment.
|
|
|
|
|
2014-03-14 17:01:15 +00:00
|
|
|
|
|
|
|
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) or Pillow (recommended)
|
|
|
|
|
|
|
|
|
|
|
|
Feature List
|
|
|
|
------------------------------------------------------------------
|
|
|
|
|
|
|
|
* Support for the following interfaces
|
|
|
|
* USB
|
|
|
|
* Serial
|
|
|
|
* Network
|
|
|
|
* File
|
|
|
|
|
|
|
|
* Commands include
|
|
|
|
* Text and image positioning
|
|
|
|
* Text formatting
|
|
|
|
* Opening cash drawers
|
|
|
|
* Full/Partial cuts
|
|
|
|
* Barcodes and QR Codes
|
|
|
|
* Images and image scaling
|
|
|
|
* Chinese character support
|
|
|
|
|
|
|
|
TODO
|
2013-02-27 12:32:43 +00:00
|
|
|
------------------------------------------------------------------
|
2013-02-27 12:31:18 +00:00
|
|
|
|
2014-03-14 17:01:15 +00:00
|
|
|
* Testing
|
|
|
|
* Possibly a virtual printer in the far future
|
|
|
|
* Provide install instructions
|
|
|
|
* Provide API documentation
|
|
|
|
|
|
|
|
USB Quickstart
|
|
|
|
------------------------------------------------------------------
|
|
|
|
|
|
|
|
### Find your printer ###
|
|
|
|
|
2013-02-27 12:31:18 +00:00
|
|
|
Before start create your Python ESC/POS printer instance, you must
|
2014-03-14 17:01:15 +00:00
|
|
|
see at your system for the printer parameters. On Linux this is done with
|
2013-02-27 12:31:18 +00:00
|
|
|
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:
|
|
|
|
|
2013-02-27 12:32:43 +00:00
|
|
|
xxxx:xxxx
|
2013-02-27 12:31:18 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
Bus 002 Device 001: ID 1a2b:1a2b Device name
|
|
|
|
|
|
|
|
Write down the the values in question, then issue the following
|
|
|
|
command so you can get the "Interface" number and "End Point"
|
|
|
|
|
2013-02-27 12:32:43 +00:00
|
|
|
lsusb -vvv -d xxxx:xxxx | grep iInterface
|
|
|
|
lsusb -vvv -d xxxx:xxxx | grep bEndpointAddress | grep OUT
|
2013-02-27 12:31:18 +00:00
|
|
|
|
|
|
|
The first command will yields the "Interface" number that must
|
|
|
|
be handy to have and the second yields the "Output Endpoint"
|
|
|
|
address.
|
|
|
|
|
|
|
|
By default the "Interface" number is "0" and the "Output Endpoint"
|
|
|
|
address is "0x82", if you have other values then you can define
|
|
|
|
with your instance.
|
|
|
|
|
2014-03-14 17:01:15 +00:00
|
|
|
### Define a printer instance and send commands ###
|
2013-02-27 12:31:18 +00:00
|
|
|
|
2014-03-14 15:33:09 +00:00
|
|
|
The following example shows how to initialize a printer over USB.
|
|
|
|
|
|
|
|
*** NOTE: Always finish the sequence with cut otherwise
|
2014-03-14 17:01:15 +00:00
|
|
|
you will end up with weird chars being printed.
|
2013-02-27 12:31:18 +00:00
|
|
|
|
2014-03-13 18:09:10 +00:00
|
|
|
from escpos import printer
|
|
|
|
|
|
|
|
p = printer.Usb(0x04b8, 0x0202)
|
|
|
|
p.text("Hello World")
|
2014-03-13 18:20:57 +00:00
|
|
|
p.image("doge.jpg")
|
2014-03-13 18:09:10 +00:00
|
|
|
p.fullimage("a.really.large.image.png")
|
|
|
|
p.barcode('1324354657687','EAN13',64,2,'','')
|
|
|
|
p.qr('this is a piece of code')
|
|
|
|
p.cut()
|
2013-02-27 12:31:18 +00:00
|
|
|
|
2014-03-14 17:01:15 +00:00
|
|
|
Links
|
2013-02-27 12:32:43 +00:00
|
|
|
------------------------------------------------------------------
|
2013-02-27 12:31:18 +00:00
|
|
|
|
2014-03-14 17:01:15 +00:00
|
|
|
Project homepage originally at:
|
|
|
|
|
2013-02-27 12:31:18 +00:00
|
|
|
http://repo.bashlinux.com/projects/escpos.html
|
|
|
|
|
2014-03-14 17:01:15 +00:00
|
|
|
By Manuel F Martinez <manpaz@bashlinux.com>
|
2013-02-27 12:27:04 +00:00
|
|
|
|
2014-03-14 17:01:15 +00:00
|
|
|
Forked from https://code.google.com/p/python-escpos/
|