如何在python-escpos中读取ASB状态

时间:2020-03-20 15:16:10

标签: python escpos

我想在python-escpos中读回ASB和其他状态结果。我以为._read()方法可以工作,但出现“ AttributeError:'Serial'对象没有属性'_read'”错误。我已经通过inspect验证了_read()方法。

关于如何在python-escpos中读回状态的任何建议?

1 个答案:

答案 0 :(得分:1)

请尝试在GS a方法中将query_status()命令指定为参数并调用它。

GS a

[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

请尝试为n指定0xFF。

query_status(mode)

查询打印机的状态,并返回包含它的整数数组。

参数:mode –整数,用于设置查询到打印机的状态模式。 -RT_STATUS_ONLINE:打印机状态。 -RT_STATUS_PAPER:纸张传感器。 返回类型:array(integer)

def query_status(self, mode):

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):

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):

def _read(self):
    """ Reads a data buffer and returns it to the caller. """
    return self.device.read(self.in_ep, 16)

# Status Command

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