I want to read back ASB and other status results in python-escpos. I thought the ._read() method would work but I get a "AttributeError: 'Serial' object has no attribute '_read'" error. I have verified the _read() method is there with inspect.
Any suggestion on how I can read back status's in python-escpos?
Please try specifying the GS a
command as a parameter in the query_status()
method and calling it.
[Name] Enable/disable Automatic Status Back (ASB) [Format] ASCII GS a n Hex 1D 61 n Decimal 29 97 n [Range] n = 0 – 255 [Default] n: different depending on the printers
Please try by specifying 0xFF for n
.
Queries the printer for its status, and returns an array of integers containing it.
Parameters: mode – Integer that sets the status mode queried to the printer. - RT_STATUS_ONLINE: Printer status. - RT_STATUS_PAPER: Paper sensor. Return type: array(integer)
def query_status(self, mode): """ Queries the printer for its status, and returns an array of integers containing it. :param mode: Integer that sets the status mode queried to the printer. - RT_STATUS_ONLINE: Printer status. - RT_STATUS_PAPER: Paper sensor. :rtype: array(integer) """ self._raw(mode) time.sleep(1) status = self._read() return status
def _raw(self, msg): """ Print any command sent in raw format :param msg: arbitrary code to be printed :type msg: bytes """ 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)
RT_STATUS = DLE + EOT RT_STATUS_ONLINE = RT_STATUS + b'\x01' RT_STATUS_PAPER = RT_STATUS + b'\x04' RT_MASK_ONLINE = 8 RT_MASK_PAPER = 18 RT_MASK_LOWPAPER = 30 RT_MASK_NOPAPER = 114