[FIX] hw_escpos: Cash drawer doesn't always open

With some printers (ex: Epson TM-m30), the cash drawer only opens 50%
of the time if you just send the kick command.

A fix has already been made (odoo/odoo#33328). In the previous fix, we
retried up to five times to send the pulse, checking the status of the
drawer between each pulse. The problem was that, when we read the value
of the status, the pulse was not yet done and the status was not yet
updated. The pulse was then always sent five times, even if the first
pulse worked, making a lot of noise.

For some reason, if you read the status right after sending the pulse,
the drawer always opens and the loop is not needed anymore.

TaskID: 2045581

closes odoo/odoo#35368

Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
This commit is contained in:
Antoine Prieels
2019-08-01 07:58:24 +00:00
parent 9a16198862
commit b515d54232
+11 -14
View File
@@ -894,24 +894,21 @@ class Escpos:
self._raw(PAPER_FULL_CUT)
def cashdraw(self, pin, tries=5):
def cashdraw(self, pin):
""" Send pulse to kick the cash drawer
With some printers the drawer will not open after one pulse, for this reason we will check
the drawer status up to 'tries' times and send a new pulse if the drawer is still closed. If the
drawer status is open, we will stop sending pulses.
For some reason, with some printers (ex: Epson TM-m30), the cash drawer
only opens 50% of the time if you just send the pulse. But if you read
the status afterwards, it opens all the time.
"""
for i in range(tries):
if pin == 2:
self._raw(CD_KICK_2)
elif pin == 5:
self._raw(CD_KICK_5)
else:
raise CashDrawerError()
if i != tries - 1 and not self.get_printer_status()['printer']['drawer_pin_high']:
break
if pin == 2:
self._raw(CD_KICK_2)
elif pin == 5:
self._raw(CD_KICK_5)
else:
raise CashDrawerError()
self.get_printer_status()
def hw(self, hw):
""" Hardware operations """