如何在pythonescpos中读取ASB状态

2024-06-07 06:46:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我想读回python escpos中的ASB和其他状态结果。我认为._read()方法可以工作,但我得到了一个“AttributeError:'Serial'对象没有属性'_read'”错误。我已经用inspect验证了_read()方法是否存在

关于如何读回python escpos中的状态有什么建议吗


Tags: 对象方法read属性状态错误serial建议
1条回答
网友
1楼 · 发布于 2024-06-07 06:46:00

请尝试将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)

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

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

相关问题 更多 >