Added the DLE EOT querying command. (#237)

* Added the DLE EOT querying command.
Added a function to check whether the printer is online or not, as well
as a reading method for USB printers.
* Update AUTHORS
* Add entry to .mailmap
* currently USB only
This commit is contained in:
csoft2k 2017-07-24 13:57:02 +02:00 committed by Patrick Kanzler
parent 662aa30f4b
commit 89dfb6cf86
5 changed files with 32 additions and 0 deletions

View File

@ -8,3 +8,4 @@ Cody (Quantified Code Bot) <cody@quantifiedcode.com> Cody <cody@quantifiedcode.c
Renato Lorenzi <renato.lorenzi@senior.com.br> Renato.Lorenzi <renato.lorenzi@senior.com.br> Renato Lorenzi <renato.lorenzi@senior.com.br> Renato.Lorenzi <renato.lorenzi@senior.com.br>
Ahmed Tahri <nyuubi.10@gmail.com> TAHRI Ahmed <nyuubi.10@gmail.com> Ahmed Tahri <nyuubi.10@gmail.com> TAHRI Ahmed <nyuubi.10@gmail.com>
Michael Elsdörfer <michael@elsdoerfer.com> Michael Elsdörfer <michael@elsdoerfer.info> Michael Elsdörfer <michael@elsdoerfer.com> Michael Elsdörfer <michael@elsdoerfer.info>
csoft2k <csoft2k@hotmail.com>

View File

@ -3,6 +3,7 @@ Asuki Kono
belono belono
Christoph Heuel Christoph Heuel
Cody (Quantified Code Bot) Cody (Quantified Code Bot)
csoft2k
Curtis // mashedkeyboard Curtis // mashedkeyboard
Davis Goglin Davis Goglin
Dean Rispin Dean Rispin

View File

@ -249,3 +249,7 @@ S_RASTER_N = _PRINT_RASTER_IMG(b'\x00') # Set raster image normal size
S_RASTER_2W = _PRINT_RASTER_IMG(b'\x01') # Set raster image double width S_RASTER_2W = _PRINT_RASTER_IMG(b'\x01') # Set raster image double width
S_RASTER_2H = _PRINT_RASTER_IMG(b'\x02') # Set raster image double height S_RASTER_2H = _PRINT_RASTER_IMG(b'\x02') # Set raster image double height
S_RASTER_Q = _PRINT_RASTER_IMG(b'\x03') # Set raster image quadruple S_RASTER_Q = _PRINT_RASTER_IMG(b'\x03') # Set raster image quadruple
# Status Command
RT_STATUS_ONLINE = DLE + EOT + b'\x01';
RT_MASK_ONLINE = 8;

View File

@ -18,6 +18,7 @@ from __future__ import unicode_literals
import qrcode import qrcode
import textwrap import textwrap
import six import six
import time
import barcode import barcode
from barcode.writer import ImageWriter from barcode.writer import ImageWriter
@ -34,6 +35,7 @@ from .constants import CD_KICK_DEC_SEQUENCE, CD_KICK_5, CD_KICK_2, PAPER_FULL_CU
from .constants import HW_RESET, HW_SELECT, HW_INIT from .constants import HW_RESET, HW_SELECT, HW_INIT
from .constants import CTL_VT, CTL_HT, CTL_CR, CTL_FF, CTL_LF, CTL_SET_HT, PANEL_BUTTON_OFF, PANEL_BUTTON_ON from .constants import CTL_VT, CTL_HT, CTL_CR, CTL_FF, CTL_LF, CTL_SET_HT, PANEL_BUTTON_OFF, PANEL_BUTTON_ON
from .constants import TXT_STYLE from .constants import TXT_STYLE
from .constants import RT_STATUS_ONLINE, RT_MASK_ONLINE
from .exceptions import BarcodeTypeError, BarcodeSizeError, TabPosError from .exceptions import BarcodeTypeError, BarcodeSizeError, TabPosError
from .exceptions import CashDrawerError, SetVariableError, BarcodeCodeError from .exceptions import CashDrawerError, SetVariableError, BarcodeCodeError
@ -77,6 +79,12 @@ class Escpos(object):
""" """
pass pass
def _read(self, msg):
""" Returns a NotImplementedError if the instance of the class doesn't override this method.
:raises NotImplementedError
"""
raise NotImplementedError()
def image(self, img_source, high_density_vertical=True, high_density_horizontal=True, impl="bitImageRaster", def image(self, img_source, high_density_vertical=True, high_density_horizontal=True, impl="bitImageRaster",
fragment_height=960): fragment_height=960):
""" Print an image """ Print an image
@ -733,6 +741,20 @@ class Escpos(object):
else: else:
self._raw(PANEL_BUTTON_OFF) self._raw(PANEL_BUTTON_OFF)
def query_status(self):
""" Queries the printer for its status, and returns an array of integers containing it.
:rtype: array(integer)"""
self._raw(RT_STATUS_ONLINE)
time.sleep(1)
status = self._read()
return status or [RT_MASK_ONLINE]
def is_online(self):
""" Queries the printer its online status.
When online, returns True; False otherwise.
:rtype: bool: True if online, False if offline."""
return not (self.query_status()[0] & RT_MASK_ONLINE)
class EscposIO(object): class EscposIO(object):
"""ESC/POS Printer IO object """ESC/POS Printer IO object

View File

@ -84,6 +84,10 @@ class Usb(Escpos):
""" """
self.device.write(self.out_ep, msg, self.timeout) self.device.write(self.out_ep, msg, self.timeout)
def _read(self):
""" Reads a data buffer and returns it to the caller. """
return self.device.read(self.in_ep, 16)
def close(self): def close(self):
""" Release USB interface """ """ Release USB interface """
if self.device: if self.device: