commit
11452034a3
|
@ -1,6 +1,18 @@
|
||||||
*********
|
*********
|
||||||
Changelog
|
Changelog
|
||||||
*********
|
*********
|
||||||
|
2016-08-02 - Version 2.1.2 - "Death and Gravity"
|
||||||
|
------------------------------------------------
|
||||||
|
|
||||||
|
changes
|
||||||
|
^^^^^^^
|
||||||
|
- fix File-printer: flush after every call of _raw()
|
||||||
|
- fix lists in documentation
|
||||||
|
- fix CODE128: by adding the control character to the barcode-selection-sequence the barcode became unusable
|
||||||
|
|
||||||
|
contributors
|
||||||
|
^^^^^^^^^^^^
|
||||||
|
- Patrick Kanzler
|
||||||
|
|
||||||
2016-08-02 - Version 2.1.1 - "Contents May Differ"
|
2016-08-02 - Version 2.1.1 - "Contents May Differ"
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
|
@ -18,6 +18,7 @@ Content
|
||||||
user/raspi
|
user/raspi
|
||||||
user/todo
|
user/todo
|
||||||
user/usage
|
user/usage
|
||||||
|
user/barcode
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 1
|
:maxdepth: 1
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
Printing Barcodes
|
||||||
|
-----------------
|
||||||
|
:Last Reviewed: 2016-07-31
|
||||||
|
|
||||||
|
Most ESC/POS-printers implement barcode-printing.
|
||||||
|
The barcode-commandset is implemented in the barcode-method.
|
||||||
|
For a list of compatible barcodes you should check the manual of your printer.
|
||||||
|
As a rule of thumb: even older Epson-models support most 1D-barcodes.
|
||||||
|
To be sure just try some implementations and have a look at the notices below.
|
||||||
|
|
||||||
|
barcode-method
|
||||||
|
~~~~~~~~~~~~~~
|
||||||
|
The barcode-method is rather low-level and orients itself on the implementation of ESC/POS.
|
||||||
|
In the future this class could be supplemented by a high-level class that helps the user generating the payload.
|
||||||
|
|
||||||
|
.. py:currentmodule:: escpos.escpos
|
||||||
|
|
||||||
|
.. automethod:: Escpos.barcode
|
||||||
|
:noindex:
|
||||||
|
|
||||||
|
CODE128
|
||||||
|
~~~~~~~
|
||||||
|
Code128 barcodes need a certain format.
|
||||||
|
For now the user has to make sure that the payload is correct.
|
||||||
|
For alphanumeric CODE128 you have to preface your payload with `{B`.
|
||||||
|
|
||||||
|
.. code-block:: Python
|
||||||
|
|
||||||
|
from escpos.printer import Dummy, Serial
|
||||||
|
p = Serial()
|
||||||
|
# print CODE128 012ABCDabcd
|
||||||
|
p.barcode("{B012ABCDabcd", "CODE128", function_type="B")
|
||||||
|
|
||||||
|
A very good description on CODE128 is also on `Wikipedia <https://en.wikipedia.org/wiki/Code_128>`_.
|
|
@ -88,6 +88,7 @@ set("align", "font", "type", width, height, invert, smooth, flip)
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Set text properties.
|
Set text properties.
|
||||||
|
|
||||||
* ``align`` set horizontal position for text, the possible values are:
|
* ``align`` set horizontal position for text, the possible values are:
|
||||||
|
|
||||||
* CENTER
|
* CENTER
|
||||||
|
@ -106,6 +107,7 @@ cut("mode")
|
||||||
^^^^^^^^^^^
|
^^^^^^^^^^^
|
||||||
|
|
||||||
Cut paper.
|
Cut paper.
|
||||||
|
|
||||||
* ``mode`` set a full or partial cut. *Default:* full
|
* ``mode`` set a full or partial cut. *Default:* full
|
||||||
|
|
||||||
**Partial cut is not implemented in all printers.**
|
**Partial cut is not implemented in all printers.**
|
||||||
|
@ -132,6 +134,7 @@ control("align")
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Carrier feed and tabs.
|
Carrier feed and tabs.
|
||||||
|
|
||||||
* ``align`` is a string which takes any of the following values:
|
* ``align`` is a string which takes any of the following values:
|
||||||
|
|
||||||
* LF *for Line Feed*
|
* LF *for Line Feed*
|
||||||
|
|
|
@ -32,6 +32,7 @@ Network("host", port)
|
||||||
^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Based on socket
|
Based on socket
|
||||||
|
|
||||||
* ``host`` is an alphanumeric host name, could be either DNS host name or IP address.
|
* ``host`` is an alphanumeric host name, could be either DNS host name or IP address.
|
||||||
* ``port`` to write to (default = 9100)
|
* ``port`` to write to (default = 9100)
|
||||||
|
|
||||||
|
@ -40,7 +41,8 @@ Problems with a network-attached printer can have numerous causes. Make sure tha
|
||||||
Often you can check the IP address by triggering the self-test of the device. As a next step try to send text
|
Often you can check the IP address by triggering the self-test of the device. As a next step try to send text
|
||||||
manually to the device. You could use for example:
|
manually to the device. You could use for example:
|
||||||
|
|
||||||
::
|
.. ::
|
||||||
|
|
||||||
echo "OK\n" | nc IPADDRESS 9100
|
echo "OK\n" | nc IPADDRESS 9100
|
||||||
# the port number is often 9100
|
# the port number is often 9100
|
||||||
|
|
||||||
|
@ -50,4 +52,5 @@ File("file\_name")
|
||||||
^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Printcap printers
|
Printcap printers
|
||||||
|
|
||||||
* ``file_name`` is the full path to the device file name
|
* ``file_name`` is the full path to the device file name
|
||||||
|
|
|
@ -168,10 +168,7 @@ BARCODE_TYPE_B = {
|
||||||
'NW7': _SET_BARCODE_TYPE(71),
|
'NW7': _SET_BARCODE_TYPE(71),
|
||||||
'CODABAR': _SET_BARCODE_TYPE(71), # Same as NW7
|
'CODABAR': _SET_BARCODE_TYPE(71), # Same as NW7
|
||||||
'CODE93': _SET_BARCODE_TYPE(72),
|
'CODE93': _SET_BARCODE_TYPE(72),
|
||||||
# These are all the same barcode, but using different charcter sets
|
'CODE128': _SET_BARCODE_TYPE(73),
|
||||||
'CODE128A': _SET_BARCODE_TYPE(73) + b'{A', # CODE128 character set A
|
|
||||||
'CODE128B': _SET_BARCODE_TYPE(73) + b'{B', # CODE128 character set B
|
|
||||||
'CODE128C': _SET_BARCODE_TYPE(73) + b'{C', # CODE128 character set C
|
|
||||||
'GS1-128': _SET_BARCODE_TYPE(74),
|
'GS1-128': _SET_BARCODE_TYPE(74),
|
||||||
'GS1 DATABAR OMNIDIRECTIONAL': _SET_BARCODE_TYPE(75),
|
'GS1 DATABAR OMNIDIRECTIONAL': _SET_BARCODE_TYPE(75),
|
||||||
'GS1 DATABAR TRUNCATED': _SET_BARCODE_TYPE(76),
|
'GS1 DATABAR TRUNCATED': _SET_BARCODE_TYPE(76),
|
||||||
|
|
|
@ -229,13 +229,15 @@ class File(Escpos):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, devfile="/dev/usb/lp0", *args, **kwargs):
|
def __init__(self, devfile="/dev/usb/lp0", auto_flush=True, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
:param devfile : Device file under dev filesystem
|
:param devfile : Device file under dev filesystem
|
||||||
|
:param auto_flush: automatically call flush after every call of _raw()
|
||||||
"""
|
"""
|
||||||
Escpos.__init__(self, *args, **kwargs)
|
Escpos.__init__(self, *args, **kwargs)
|
||||||
self.devfile = devfile
|
self.devfile = devfile
|
||||||
|
self.auto_flush = auto_flush
|
||||||
self.open()
|
self.open()
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
|
@ -256,6 +258,8 @@ class File(Escpos):
|
||||||
:type msg: bytes
|
:type msg: bytes
|
||||||
"""
|
"""
|
||||||
self.device.write(msg)
|
self.device.write(msg)
|
||||||
|
if self.auto_flush:
|
||||||
|
self.flush()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
""" Close system file """
|
""" Close system file """
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""tests for the File printer
|
||||||
|
|
||||||
|
:author: `Patrick Kanzler <patrick.kanzler@fablab.fau.de>`_
|
||||||
|
:organization: `python-escpos <https://github.com/python-escpos>`_
|
||||||
|
:copyright: Copyright (c) 2016 `python-escpos <https://github.com/python-escpos>`_
|
||||||
|
:license: GNU GPL v3
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
|
import mock
|
||||||
|
from hypothesis import given
|
||||||
|
from hypothesis.strategies import text
|
||||||
|
|
||||||
|
import escpos.printer as printer
|
||||||
|
|
||||||
|
if six.PY3:
|
||||||
|
mock_open_call = 'builtins.open'
|
||||||
|
else:
|
||||||
|
mock_open_call = '__builtin__.open'
|
||||||
|
|
||||||
|
@given(path=text())
|
||||||
|
@mock.patch(mock_open_call)
|
||||||
|
@mock.patch('escpos.escpos.Escpos.__init__')
|
||||||
|
def test_load_file_printer(mock_escpos, mock_open, path):
|
||||||
|
"""test the loading of the file-printer"""
|
||||||
|
printer.File(devfile=path)
|
||||||
|
assert mock_escpos.called
|
||||||
|
mock_open.assert_called_with(path, "wb")
|
||||||
|
|
||||||
|
|
||||||
|
@given(txt=text())
|
||||||
|
@mock.patch.object(printer.File, 'device')
|
||||||
|
@mock.patch(mock_open_call)
|
||||||
|
@mock.patch('escpos.escpos.Escpos.__init__')
|
||||||
|
def test_auto_flush(mock_escpos, mock_open, mock_device, txt):
|
||||||
|
"""test auto_flush in file-printer"""
|
||||||
|
p = printer.File(auto_flush=False)
|
||||||
|
# inject the mocked device-object
|
||||||
|
p.device = mock_device
|
||||||
|
p._raw(txt)
|
||||||
|
assert not mock_device.flush.called
|
||||||
|
mock_device.reset_mock()
|
||||||
|
p = printer.File(auto_flush=True)
|
||||||
|
# inject the mocked device-object
|
||||||
|
p.device = mock_device
|
||||||
|
p._raw(txt)
|
||||||
|
assert mock_device.flush.called
|
||||||
|
|
||||||
|
|
||||||
|
@given(txt=text())
|
||||||
|
@mock.patch.object(printer.File, 'device')
|
||||||
|
@mock.patch(mock_open_call)
|
||||||
|
def test_flush_on_close(mock_open, mock_device, txt):
|
||||||
|
"""test flush on close in file-printer"""
|
||||||
|
p = printer.File(auto_flush=False)
|
||||||
|
# inject the mocked device-object
|
||||||
|
p.device = mock_device
|
||||||
|
p._raw(txt)
|
||||||
|
assert not mock_device.flush.called
|
||||||
|
p.close()
|
||||||
|
assert mock_device.flush.called
|
||||||
|
assert mock_device.close.called
|
Loading…
Reference in New Issue