def print_barcode(self, code): """ Print a barcode representing the given code. """ if not code: return # If the barcode size exceeds the maximum size in which the printer # could input in a single line, split it in two lines if len(code) > self.max_barcode_characters: # int() conversion is not actually required, but it makes the code # Python 3 ready. length = int(len(code) / 2) self.print_barcode(code[:length]) self.print_line(b'') self.print_barcode(code[length:]) return # Set Width and Height self.write(self.BARCODE_HEIGHT + chr(30)) self.write(self.BARCODE_WIDTH + chr(2)) # Other settings self.write(self.BARCODE_FONT_REGULAR) self.write(self.BARCODE_TXT_OFF) # Then write the code self.write(self.BARCODE_CODE93 + chr(len(code)) + encode_text(code, self.charset))
def print_barcode(self, code): """ Print a barcode representing the given code. """ if not code: return # If the barcode size exceeds the maximum size in which the printer # could input in a single line, split it in two lines if len(code) > self.max_barcode_characters: # int() conversion is not actually required, but it makes the code # Python 3 ready. length = int(len(code) / 2) self.print_barcode(code[:length]) self.print_line('') self.print_barcode(code[length:]) return # Set Width and Height self.write(BARCODE_HEIGHT + chr(80)) self.write(BARCODE_WIDTH + chr(2)) # Other settings self.write(BARCODE_FONT_A) self.write(BARCODE_TXT_OFF) # Then write the code self.write(BARCODE_CODE93 + chr(len(code)) + encode_text(code, self.charset))
def _configure_printer(self): enc = lambda text: encode_text(text, self.coupon_printer_charset) self._define_tax_name(0, enc(self.CASH_SUPPLY), entrada=True) self._define_tax_name(1, enc(self.CASH_REMOVAL), entrada=False) for code in range(2, 15): self._delete_tax_name(code) self._define_payment_method(0, enc('Cheque')) self._define_payment_method(1, enc('Boleto')) self._define_payment_method(2, enc('Cartão credito'), vinculated=True) self._define_payment_method(3, enc('Cartão debito'), vinculated=True) self._define_payment_method(4, enc('Financeira')) self._define_payment_method(5, enc('Vale compra')) for code in range(6, 15): self._delete_payment_method(code) self._define_tax_code(0, Decimal("17.00")) self._define_tax_code(1, Decimal("12.00")) self._define_tax_code(2, Decimal("25.00")) self._define_tax_code(3, Decimal("8.00")) self._define_tax_code(4, Decimal("5.00")) self._define_tax_code(5, Decimal("3.00"), service=True) for code in range(6, 16): self._delete_tax_code(code)
def _till_read_memory_to_serial(self, start, end): self._send_command(CMD_READ_MEMORY, '%s%sR' % ( start.strftime('%d%m%y'), end.strftime('%d%m%y'))) data = '' while True: c = self.read(1) if ord(c) == 0x03: break data += encode_text(c, self.coupon_printer_charset) return data
def _till_read_memory_to_serial(self, start, end): # Page 39 ret = self.send_command(CMD_READ_MEMORY, 's%s%s' % (start.strftime('%d%m%y'), end.strftime('%d%m%y'))) data = '' while True: line = self.readline() if line[-1] == '\xff': break data += line data = encode_text(data, 'cp860') return (ret, data)
def print_inline(self, text): """ Print a given text in a unique line. """ # Do nothing for empty texts if not text: return # Encode the text with the correct codepage if self.codepage: text = encode_text(text, self.codepage) # Then, finally write the text self.write(self.default_font) self.write(text)
def _till_read_memory_to_serial(self, start, end): self._send_command(CMD_READ_MEMORY, '%s%sR' % ( start.strftime('%d%m%y'), end.strftime('%d%m%y'))) data = '' while True: c = self.read(1) if ord(c) == 0x03: break data += encode_text(c, self.coupon_printer_charset) return data
def _till_read_memory_to_serial(self, start, end): # Page 39 ret = self.send_command( CMD_READ_MEMORY, 's%s%s' % (start.strftime('%d%m%y'), end.strftime('%d%m%y'))) data = '' while True: line = self.readline() if line[-1] == '\xff': break data += line data = encode_text(data, 'cp860') return (ret, data)
def _format_text(self, text): return encode_text(text, self._charset)
def _format_text(self, text): return encode_text(text, self._charset)
def gerencial_report_print(self, text): text = encode_text(text, self.coupon_printer_charset) for line in text.split('\n'): line = line.replace('\\', '\\\\') # Vespague sucks self._send_command('ImprimeTexto', TextoLivre=line)