我想在python escpos中读取ASB和其他状态结果。我想_read((方法可以工作,但我得到一个"AttributeError:'Serial'对象没有属性'_read'"错误。我已经用inspect验证了_read((方法的存在。
关于如何在python escpos中读取状态,有什么建议吗?
请尝试将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_PARER:纸张传感器。返回类型:数组(整数(
defquery_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)
#状态命令
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