Add support for custom cash drawer kick sequence

This commit is contained in:
belono 2016-09-15 22:54:35 +02:00
parent 4166ee2209
commit a82fefb301
2 changed files with 8 additions and 3 deletions

View File

@ -47,6 +47,7 @@ HW_RESET = ESC + b'\x3f\x0a\x00' # Reset printer hardware
# Cash Drawer (ESC p <pin> <on time: 2*ms> <off time: 2*ms>)
_CASH_DRAWER = lambda m, t1='', t2='': ESC + b'p' + m + six.int2byte(t1) + six.int2byte(t2)
CD_KICK_DEC_SEQUENCE = lambda esc, p, m, t1=50, t2=50: six.int2byte(esc) + six.int2byte(p) + six.int2byte(m) + six.int2byte(t1) + six.int2byte(t2)
CD_KICK_2 = _CASH_DRAWER(b'\x00', 50, 50) # Sends a pulse to pin 2 []
CD_KICK_5 = _CASH_DRAWER(b'\x01', 50, 50) # Sends a pulse to pin 5 []

View File

@ -636,9 +636,10 @@ class Escpos(object):
def cashdraw(self, pin):
""" Send pulse to kick the cash drawer
Kick cash drawer on pin 2 or pin 5 according to parameter.
Kick cash drawer on pin 2 or pin 5 according to default parameter.
For non default parameter send a decimal sequence i.e. [27,112,48] or [27,112,0,25,255]
:param pin: pin number, 2 or 5
:param pin: pin number, 2 or 5 or list of decimals
:raises: :py:exc:`~escpos.exceptions.CashDrawerError`
"""
if pin == 2:
@ -646,7 +647,10 @@ class Escpos(object):
elif pin == 5:
self._raw(CD_KICK_5)
else:
raise CashDrawerError()
try:
self._raw(CD_KICK_DEC_SEQUENCE(*pin))
except:
raise CashDrawerError()
def hw(self, hw):
""" Hardware operations