Merge pull request #1 from python-escpos/master

update branch to 1.0.9
This commit is contained in:
ldos 2016-04-28 12:14:38 +02:00
commit f1af76d335
20 changed files with 1351 additions and 66 deletions

View File

@ -22,3 +22,27 @@ CHANGELOG
- Added charcode tables
- Fixed Horizontal Tab
- Fixed code tabulators
* 2015-04-21 - Version 1.0.5
- Merge pull request #45 from Krispy2009/master
. Raising the right error when wrong charcode is used
. Sent by Kristi <Krispy2009@gmail.com>
* 2015-07-06 - Version 1.0.6
- Merge pull request #53 from ldos/master
. Extended params for serial printers
. Sent by ldos <cafeteria.ldosalzira@gmail.com>
* 2015-08-22 - Version 1.0.7
- Issue #57: Fixed transparent images
* 2015-10-27 - Version 1.0.8
- Merge pull request #59 from zouppen/master
. Support for images vertically longer than 256 pixels
. Sent by Joel Lehtonen <joel.lehtonen@koodilehto.fi>
- Updated README
* 2016-01-24 - Version 1.0.9
- fix constant definition for PC1252
- move documentation to Sphinx

74
README
View File

@ -4,16 +4,7 @@ ESCPOS
Python library to manipulate ESC/POS Printers.
------------------------------------------------------------------
1. 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)
------------------------------------------------------------------
2. Description
1. 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,
@ -33,57 +24,22 @@ paper, carrier return, printer reset and others concerned to the
carriage alignment.
------------------------------------------------------------------
3. Define your printer
Before start create 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:
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"
lsusb -vvv -d xxxx:xxxx | grep iInterface
lsusb -vvv -d xxxx:xxxx | grep bEndpointAddress | grep OUT
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.
------------------------------------------------------------------
4. Define your instance
The following example shows how to initialize the Epson TM-TI88IV
*** NOTE: Always finish the sequence with Epson.cut() otherwise
you will endup with weird chars being printed.
from escpos import *
""" Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """
Epson = escpos.Escpos(0x04b8,0x0202)
Epson.text("Hello World")
Epson.image("logo.gif")
Epson.barcode
Epson.barcode('1324354657687','EAN13',64,2,'','')
Epson.cut()
------------------------------------------------------------------
5. Links
2. Documentation
Please visit project documentation at:
https://github.com/manpaz/python-escpos/wiki
https://python-escpos.readthedocs.org/en/latest
------------------------------------------------------------------
3. Donations
There are some different prints I'd like to acquire, but unfortunately
not all, even used, are cheaper and easy to get.
If you want to help funding money to get more printers or just want to
donate because you like the project, please be in touch and I'll be
sending my PayPal info so you can donate.
Thank you!
Manuel F Martinez <manpaz@bashlinux.com>

1
doc/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
_build

177
doc/Makefile Normal file
View File

@ -0,0 +1,177 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
endif
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " xml to make Docutils-native XML files"
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/python-escpos.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/python-escpos.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/python-escpos"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/python-escpos"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
latexpdfja:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
xml:
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
pseudoxml:
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."

46
doc/api.rst Normal file
View File

@ -0,0 +1,46 @@
escpos package
==============
Submodules
----------
escpos.constants module
-----------------------
.. automodule:: escpos.constants
:members:
:undoc-members:
:show-inheritance:
escpos.escpos module
--------------------
.. automodule:: escpos.escpos
:members:
:undoc-members:
:show-inheritance:
escpos.exceptions module
------------------------
.. automodule:: escpos.exceptions
:members:
:undoc-members:
:show-inheritance:
escpos.printer module
---------------------
.. automodule:: escpos.printer
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: escpos
:members:
:undoc-members:
:show-inheritance:

264
doc/conf.py Normal file
View File

@ -0,0 +1,264 @@
# -*- coding: utf-8 -*-
#
# python-escpos documentation build configuration file, created by
# sphinx-quickstart on Sat Dec 26 14:28:42 2015.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys
import os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('..'))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'python-escpos'
copyright = u'2015, Manuel F Martinez and others'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.0.8'
# The full version, including alpha/beta/rc tags.
release = '1.0.8'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all
# documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
#keep_warnings = False
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
#html_extra_path = []
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'python-escposdoc'
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'python-escpos.tex', u'python-escpos Documentation',
u'Manuel F Martinez and others', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output ---------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'python-escpos', u'python-escpos Documentation',
[u'Manuel F Martinez and others'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output -------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'python-escpos', u'python-escpos Documentation',
u'Manuel F Martinez and others', 'python-escpos', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False

56
doc/index.rst Normal file
View File

@ -0,0 +1,56 @@
.. python-escpos documentation master file, created by
sphinx-quickstart on Sat Dec 26 14:28:42 2015.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to python-escpos's documentation!
=========================================
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 functionalists like, cut paper, cash drawer kicking, printer reset, carriage return and others concerned to the carriage alignment.
------------
There are some different printers I'd like to acquire, unfortunately
not all, even used, are cheaper and easy to get.
If you want to help funding money to get more printers or just want to
donate because you like the project, please be in touch and I'll be
sending my PayPal info so you can donate.
Thank you!
User Documentation:
-------------------
.. toctree::
:maxdepth: 1
user/dependencies
user/installation
user/methods
user/printers
user/raspi
user/todo
user/usage
API:
----
.. toctree::
:maxdepth: 1
api
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

242
doc/make.bat Normal file
View File

@ -0,0 +1,242 @@
@ECHO OFF
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set BUILDDIR=_build
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
set I18NSPHINXOPTS=%SPHINXOPTS% .
if NOT "%PAPER%" == "" (
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
)
if "%1" == "" goto help
if "%1" == "help" (
:help
echo.Please use `make ^<target^>` where ^<target^> is one of
echo. html to make standalone HTML files
echo. dirhtml to make HTML files named index.html in directories
echo. singlehtml to make a single large HTML file
echo. pickle to make pickle files
echo. json to make JSON files
echo. htmlhelp to make HTML files and a HTML help project
echo. qthelp to make HTML files and a qthelp project
echo. devhelp to make HTML files and a Devhelp project
echo. epub to make an epub
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
echo. text to make text files
echo. man to make manual pages
echo. texinfo to make Texinfo files
echo. gettext to make PO message catalogs
echo. changes to make an overview over all changed/added/deprecated items
echo. xml to make Docutils-native XML files
echo. pseudoxml to make pseudoxml-XML files for display purposes
echo. linkcheck to check all external links for integrity
echo. doctest to run all doctests embedded in the documentation if enabled
goto end
)
if "%1" == "clean" (
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
del /q /s %BUILDDIR%\*
goto end
)
%SPHINXBUILD% 2> nul
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
if "%1" == "html" (
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
goto end
)
if "%1" == "dirhtml" (
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
goto end
)
if "%1" == "singlehtml" (
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
goto end
)
if "%1" == "pickle" (
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the pickle files.
goto end
)
if "%1" == "json" (
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the JSON files.
goto end
)
if "%1" == "htmlhelp" (
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run HTML Help Workshop with the ^
.hhp project file in %BUILDDIR%/htmlhelp.
goto end
)
if "%1" == "qthelp" (
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run "qcollectiongenerator" with the ^
.qhcp project file in %BUILDDIR%/qthelp, like this:
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\python-escpos.qhcp
echo.To view the help file:
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\python-escpos.ghc
goto end
)
if "%1" == "devhelp" (
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished.
goto end
)
if "%1" == "epub" (
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The epub file is in %BUILDDIR%/epub.
goto end
)
if "%1" == "latex" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
if errorlevel 1 exit /b 1
echo.
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "latexpdf" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
cd %BUILDDIR%/latex
make all-pdf
cd %BUILDDIR%/..
echo.
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "latexpdfja" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
cd %BUILDDIR%/latex
make all-pdf-ja
cd %BUILDDIR%/..
echo.
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "text" (
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The text files are in %BUILDDIR%/text.
goto end
)
if "%1" == "man" (
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The manual pages are in %BUILDDIR%/man.
goto end
)
if "%1" == "texinfo" (
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
goto end
)
if "%1" == "gettext" (
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
goto end
)
if "%1" == "changes" (
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
if errorlevel 1 exit /b 1
echo.
echo.The overview file is in %BUILDDIR%/changes.
goto end
)
if "%1" == "linkcheck" (
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
if errorlevel 1 exit /b 1
echo.
echo.Link check complete; look for any errors in the above output ^
or in %BUILDDIR%/linkcheck/output.txt.
goto end
)
if "%1" == "doctest" (
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
if errorlevel 1 exit /b 1
echo.
echo.Testing of doctests in the sources finished, look at the ^
results in %BUILDDIR%/doctest/output.txt.
goto end
)
if "%1" == "xml" (
%SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The XML files are in %BUILDDIR%/xml.
goto end
)
if "%1" == "pseudoxml" (
%SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
goto end
)
:end

4
doc/requirements.txt Normal file
View File

@ -0,0 +1,4 @@
pyusb
Pillow>=2.0
qrcode>=4.0
pyserial

57
doc/user/dependencies.rst Normal file
View File

@ -0,0 +1,57 @@
************
Dependencies
************
Fedora
------
Fortunately everything is on Fedora repositories.
::
# yum install python-imaging pyserial pyusb python-qrcode
Ubuntu
------
Ultimately, this instructions also apply to Raspbian, in case you are
interested to install python-escpos on your Raspberry with Raspbian.
Install the packages available on distro repositories.
::
# apt-get install python-imaging pyserial
The packages which are not available at Ubuntu repositories need to be
installed manually.
pyusb
^^^^^
This is the python binding to libusb-1.0
* Get the latest tarball from `sourceforge <http://sourceforge.net/projects/pyusb/files/PyUSB%201.0/>`__
* Build and install it
::
# tar zxvf pyusb-1.*.tar.gz
# cd pyusb-1.*
# python setup.py build
# sudo python setup.py install
python-qrcode
^^^^^^^^^^^^^
This is the python module to generate QR Codes
* Checkout the latest code from `github <https://github.com/lincolnloop/python-qrcode>`__
* Build and install it
::
# git clone https://github.com/lincolnloop/python-qrcode
# cd python-qrcode
# python setup.py build
# sudo python setup.py install

40
doc/user/installation.rst Normal file
View File

@ -0,0 +1,40 @@
************
Installation
************
System preparation
------------------
1. Install the required
`dependencies <https://github.com/manpaz/python-escpos/wiki/Dependencies>`__
2. Get the *Product ID* and *Vendor ID* from the lsusb command
``# lsusb Bus 002 Device 001: ID 1a2b:1a2b Device name``
3. Create a udev rule to let users belonging to *dialout* group use the
printer. You can create the file
``/etc/udev/rules.d/99-escpos.rules`` and add the following:
``SUBSYSTEM=="usb", ATTRS{idVendor}=="1a2b", ATTRS{idProduct}=="1a2b", MODE="0664", GROUP="dialout"``
Replace *idVendor* and *idProduct* hex numbers with the ones that you
got from the previous step. Note that you can either, add yourself to
"dialout" group, or use another group you already belongs instead
"dialout" and set it in the ``GROUP`` parameter in the above rule.
4. Restart udev ``# sudo service udev restart`` In some new systems it
is done with ``# sudo udevadm control --reload``
Install
-------
* Clone python-escpos from github
* Change directory to python-escpos and install the package
::
# cd python-escpos
# python setup.py build
# sudo python setup.py install
* Enjoy !!!

118
doc/user/methods.rst Normal file
View File

@ -0,0 +1,118 @@
*******
Methods
*******
.. note:: **TODO** Merge this page into the API-description.
Escpos class
------------
Escpos inherits its methods to the printers. the following methods are
defined:
image("image\_name.ext")
^^^^^^^^^^^^^^^^^^^^^^^^
Prints an image. Its adjust the size in order to print it.
* ``image_name.ext`` is the complete file name and location of any image type (jpg, gif, png, bmp)
Raises ``ImageSizeError`` exception.
qr("text")
^^^^^^^^^^
Prints a QR code. The size has been adjusted to Version 4, so it can be
enough small to be printed but also enough big to be read by a smart
phone.
* ``text`` Any text that needs to be QR encoded. It could be a slogan,
salutation, url, etc.
barcode("code", "barcode\_type", width, height, "position", "font")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Prints a barcode.
* ``code`` is an alphanumeric code to be printed as bar code
* ``barcode_type`` must be one of the following type of codes:
* UPC-A
* UPC-E
* EAN13
* EAN8
* CODE39
* ITF
* NW7
* ``width`` is a numeric value in the range between (1,255) *Default:* 64
* ``height`` is a numeric value in the range between (2,6) *Default:* 3
* ``position`` is where to place the code around the bars, could be one of the following values:
* ABOVE
* BELOW
* BOTH
* OFF > *Default:* BELOW
* ``font`` is one of the 2 type of fonts, values could be:
* A
* B > *Default:* A Raises ``BarcodeTypeError``, ``BarcodeSizeError``, ``BarcodeCodeError`` exceptions.
text("text")
^^^^^^^^^^^^
Prints raw text. Raises ``TextError`` exception.
set("align", "font", "type", width, height)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Set text properties.
* ``align`` set horizontal position for text, the possible values are:
* CENTER
* LEFT
* RIGHT > > *Default:* left
* ``font`` type could be ``A`` or ``B``. *Default:* A
* ``type`` type could be ``B`` (Bold), ``U`` (Underline) or ``normal``. *Default:* normal
* ``width`` is a numeric value, 1 is for regular size, and 2 is twice the standard size. *Default*: 1
* ``height`` is a numeric value, 1 is for regular size and 2 is twice the standard size. *Default*: 1
cut("mode")
^^^^^^^^^^^
Cut paper.
* ``mode`` set a full or partial cut. *Default:* full
**Partial cut is not implemented in all printers.**
cashdraw(pin)
^^^^^^^^^^^^^
Sends a pulse to the cash drawer in the specified pin.
* ``pin`` is a numeric value which defines the pin to be used to send the pulse, it could be 2 or 5. Raises ``CashDrawerError()``
hw("operation")
^^^^^^^^^^^^^^^
Hardware operations.
* ``operation`` is any of the following options:
* INIT
* SELECT
* RESET
control("align")
^^^^^^^^^^^^^^^^
Carrier feed and tabs.
* ``align`` is a string which takes any of the following values:
* LF *for Line Feed*
* FF *for Form Feed*
* CR *for Carriage Return*
* HT *for Horizontal Tab*
* VT *for Vertical Tab*

42
doc/user/printers.rst Normal file
View File

@ -0,0 +1,42 @@
********
Printers
********
.. note:: **TODO** Merge this page into the API-description.
There 3 different type of printers:
USB(idVendor, idProduct, interface, in\_ep, out\_ep)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Based on pyusb and libusb-1.0
* ``idVendor`` is the Vendor ID
* ``idProduct`` is the Product ID
* ``interface`` is the USB device interface (default = 0)
* ``in_ep`` is the input end point (default = 0x82)
* ``out_ep`` is the output end point (default = 0x01)
Serial("devfile", baudrate, bytesize, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Based on pyserial, default values are based on the defaults set by
DIP\_SWITCH\_1 on the documentation(hardware side).
* ``devfile`` is an alphanumeric device file name under /dev filesystem (default = /ev/ttyS0)
* ``baudrate`` is the Baud rate for serial transmission (default = 9600)
* ``bytesize`` sets the serial buffer size (default = 8)
* ``timeout`` defines Read/Write timeout (default = 1)
Network("host", port)
^^^^^^^^^^^^^^^^^^^^^
Based on socket
* ``host`` is an alphanumeric host name, could be either DNS host name or IP address.
* ``port`` to write to (default = 9100)
File("file\_name")
^^^^^^^^^^^^^^^^^^
Printcap printers
* ``file_name`` is the full path to the device file name

68
doc/user/raspi.rst Normal file
View File

@ -0,0 +1,68 @@
************
Raspberry Pi
************
This instructions were tested on Raspbian.
Unless you have done any distro with libusb-1.0 on the Raspberry Pi, the
following instructions should works fine on your raspberry distro.
Dependencies
------------
First, install the packages available on Raspbian.
::
# apt-get install python-imaging python-serial python-setuptools
PyUSB
^^^^^
PyUSB 1.0 is not available on Ubuntu, so you have to download and
install it manually
1. Download the latest tarball from
`Sourceforge <http://sourceforge.net/projects/pyusb/files/>`__
2. Decompress the zip file
3. Install the library
::
# wget ...
# unzip pyusb*.zip
# cd pyusb*
# python setup.py build
# sudo python setup.py install
python-qrcode
^^^^^^^^^^^^^
1. Checkout the code from github
2. Install the library
::
# git clone https://github.com/lincolnloop/python-qrcode
# cd python-qrcode
# python setup.py build
# sudo python setup.py install
Installation
------------
If you have installed pyusb for libusb-1.0 then you need to:
1. Download the latest file
2. Decompress the file
3. Install the library
::
# git clone https://github.com/manpaz/python-escpos.git
# cd python-escpos
# python setup.py build
# sudo python setup.py install
Now you can attach your printer and and test it with the example code in
the project's `home <https://github.com/manpaz/python-escpos>`__

35
doc/user/todo.rst Normal file
View File

@ -0,0 +1,35 @@
****
TODO
****
Introduction
------------
python-escpos is the initial idea, from here we can start to build a
robust library to get most of the ESC/POS printers working with this
library.
Eventually, this library must be able to cover almost all the defined
models detailed in the ESC/POS Command Specification Manual.
Details
-------
What things are planned to work on?
Testing
~~~~~~~
* Test on many printers as possible (USB, Serial, Network)
Design
~~~~~~
* Add all those sequences which are not common, but part of the ESC/POS
Command Specifications.
* Port to Python 3
* Windows compatibility (hidapi instead libusb?)
* PDF417 support

138
doc/user/usage.rst Normal file
View File

@ -0,0 +1,138 @@
*****
Usage
*****
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)
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 USB Printer initialization**
::
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")
Other printers
^^^^^^^^^^^^^^
Some printers under /dev can't be used or initialized with any of the
methods described above. Usually, those are printers used by printcap,
however, if you know the device name, you could try the initialize
passing the device node name.
::
Epson = printer.File("/dev/usb/lp1")
The default is "/dev/usb/lp0", so if the printer is located on that
node, then you don't necessary need to pass the node name.
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()
How to update your code for USB printers
----------------------------------------
Old code
::
Epson = escpos.Escpos(0x04b8,0x0202,0)
New code
::
Epson = printer.Usb(0x04b8,0x0202)
Nothe that "0" which is the interface number is no longer needed.

View File

@ -42,7 +42,7 @@ CHARCODE_PC865 = '\x1b\x74\x05' # Nordic
CHARCODE_WEU = '\x1b\x74\x06' # Simplified Kanji, Hirakana
CHARCODE_GREEK = '\x1b\x74\x07' # Simplified Kanji
CHARCODE_HEBREW = '\x1b\x74\x08' # Simplified Kanji
CHARCODE_PC1252 = '\x1b\x74\x11' # Western European Windows Code Set
CHARCODE_PC1252 = '\x1b\x74\x10' # Western European Windows Code Set
CHARCODE_PC866 = '\x1b\x74\x12' # Cirillic #2
CHARCODE_PC852 = '\x1b\x74\x13' # Latin 2
CHARCODE_PC858 = '\x1b\x74\x14' # Euro

View File

@ -41,7 +41,7 @@ class Escpos:
buffer = ""
self._raw(S_RASTER_N)
buffer = "%02X%02X%02X%02X" % (((size[0]/size[1])/8), 0, size[1], 0)
buffer = "%02X%02X%02X%02X" % (((size[0]/size[1])/8), 0, size[1]&0xff, size[1]>>8)
self._raw(buffer.decode('hex'))
buffer = ""
@ -68,7 +68,7 @@ class Escpos:
if im.size[0] > 512:
print ("WARNING: Image is wider than 512 and could be truncated at print time ")
if im.size[1] > 255:
if im.size[1] > 0xffff:
raise ImageSizeError()
im_border = self._check_image_size(im.size[0])
@ -107,7 +107,15 @@ class Escpos:
def image(self,path_img):
""" Open image file """
im_open = Image.open(path_img)
im = im_open.convert("RGB")
# Remove the alpha channel on transparent images
if im_open.mode == 'RGBA':
im_open.load()
im = Image.new("RGB", im_open.size, (255, 255, 255))
im.paste(im_open, mask=im_open.split()[3])
else:
im = im_open.convert("RGB")
# Convert the RGB image in printable image
self._convert_image(im)
@ -119,6 +127,7 @@ class Escpos:
qr_code.make(fit=True)
qr_img = qr_code.make_image()
im = qr_img._img.convert("RGB")
# Convert the RGB image in printable image
self._convert_image(im)

View File

@ -40,11 +40,19 @@ class Usb(Escpos):
if self.device is None:
print "Cable isn't plugged in"
if self.device.is_kernel_driver_active(0):
check_driver = None
try:
check_driver = self.device.is_kernel_driver_active(0)
except NotImplementedError:
pass
if check_driver is None or check_driver:
try:
self.device.detach_kernel_driver(0)
except usb.core.USBError as e:
print "Could not detatch kernel driver: %s" % str(e)
if check_driver is not None:
print "Could not detatch kernel driver: %s" % str(e)
try:
self.device.set_configuration()

View File

@ -4,7 +4,7 @@ from distutils.core import setup
setup(
name='escpos',
version='1.0-4',
version='1.0.9',
url='https://github.com/manpaz/python-escpos',
download_url='https://github.com/manpaz/python-escpos.git',
description='Python library to manipulate ESC/POS Printers',