def write_additional(table_no, lines, usb_printer=None, print_item_code=True): p = usb_printer if usb_printer else File("/dev/usb/lp0") p.text('Table Number: {0}\n'.format(table_no)) p.text('ADDITIONAL ITEMS\n\n') p.text(line_block([ {'text': 'Qty', 'align': '<', 'width': QTY_WIDTH}, {'text': 'Item', 'align': '<', 'width': ITEM_WIDTH} ])) for line in lines: p.text(line_block([ {'text': line['qty'], 'align': '<', 'width': QTY_WIDTH}, {'text': line['itemName'], 'align': '<', 'width': ITEM_WIDTH}, ])) if print_item_code: p.text(line_block([ {'text': '-', 'align': '<', 'width': QTY_WIDTH}, {'text': line['itemCode'], 'align': '<', 'width': ITEM_WIDTH} ])) # Time p.text('\n\nPrinted on:\n') p.text(time.ctime()) p.cut()
def write_void(table_no, lines, usb_printer=None, print_item_code=True): p = usb_printer if usb_printer else File("/dev/usb/lp0") p.text('Table Number: {0}\n'.format(table_no)) p.text('***VOID ITEMS***\n\n') p.text( line_block([{ 'text': 'Item', 'align': '<', 'width': QTY_WIDTH + ITEM_WIDTH }])) for line in lines: p.text( line_block([{ 'text': line['itemName'], 'align': '<', 'width': QTY_WIDTH + ITEM_WIDTH }])) if print_item_code: p.text( line_block([{ 'text': line['itemCode'], 'align': '<', 'width': QTY_WIDTH + ITEM_WIDTH }])) p.text('\n\nPrinted on:\n') p.text(time.ctime()) p.cut()
def print_instructions(instructions): """ Print instructions to a thermal printer. :param instructions: list of strings containing the instructions """ try: # Vendor ID and Product ID of the 36-pin IEEE 1284 to USB converter, # this printer is so old it doesn't have USB directly printer = Usb(0x1a86, 0x7584, profile="TM-T88II") except Exception as e: print("Exception while trying to access printer via USB:") print(str(e)) try: printer = File("/dev/usb/lp0", profile="TM-T88II") except FileNotFoundError as e: print( "Received exception while trying to access printer via File:") print(str(e)) return # print header printer.set(custom_size=True, width=4, height=3) printer.textln(" Reparatur") printer.textln(" anweisung") printer.set() # reset to default printer.ln(2) for instruction in instructions: printer.textln(instruction) printer.ln() printer.image(ASSETS_PATH / "images/combined.png", center=True) printer.ln() printer.cut()
def abrir_cajon(self, *args): try: if self.tipo == "Network": printer = Network(self.ip_caja, timeout=1) if self.tipo == "Usb": printer = Usb(*self.usb) if self.tipo == "File": printer = File(self.url) printer.cashdraw(2) except Exception as e: print("[ERROR ] %s" % e)
def imprimirUrgente(self, camarero, mesa, hora, lineas): try: if self.tipo == "Network": printer = Network(self.ip_caja, timeout=1) if self.tipo == "Usb": printer = Usb(*self.usb) if self.tipo == "File": printer = File(self.url) with EscposIO(printer) as p: p.printer.codepage = 'cp858' p.printer._raw(escpos.CHARCODE_PC852) p.printer.set(align='center') p.writelines("") p.writelines('URGENTE!!', height=2, width=2, font='a', align='center') p.writelines('------------------------------------------', align='center') p.writelines('HORA: %s' % hora, height=2, width=2, font='b', align='center') p.writelines("Mesa: %s" % mesa, height=2, width=2, font='a', align='center') p.writelines(camarero, height=2, width=2, font='a', align='center') p.writelines('------------------------------------------', align='center') p.writelines("") for ln in lineas: p.writelines("{0: >3} {1: <25} {2:0.2f}".format( ln['can'], ln['nombre'], float(ln["precio"])), height=2, align='center') p.writelines("") p.writelines("") except Exception as e: print("[ERROR ] %s" % e)
def main(): imageIn = sys.argv[1] fileOut = imageIn + "_tmp.txt" p = Dummy() p.image(imageIn) f = File(fileOut) f._raw(p.output) f.cut() subprocess.call("lpr -P THERMAL -o raw " + fileOut, shell=True) os.remove(fileOut)
def printDesglose(self, fecha, lineas): if type(fecha) is datetime: fecha = fecha.strftime("%d/%m/%Y %H:%M:%S") else: fecha = datetime.strptime(fecha, "%Y-%m-%d %H:%M:%S.%f") fecha = fecha.strftime("%d/%m/%Y %H:%M:%S") try: if self.tipo == "Network": printer = Network(self.ip_caja, timeout=1) if self.tipo == "Usb": printer = Usb(*self.usb) if self.tipo == "File": printer = File(self.url) with EscposIO(printer) as p: p.printer.codepage = 'cp858' p.printer._raw(escpos.CHARCODE_PC852) p.writelines("Cierre de caja", align='center', width=2, height=2) p.writelines(fecha, align='center', width=2, height=2) p.writelines("------------------------------------------", align='center') p.writelines("") for linea in lineas: can = linea["can"] texto_tipo = linea["texto_tipo"] tipo = linea["tipo"] titulo = linea["titulo"] p.writelines("{3} {0: >5} {1: <3} de {2:6.2f} €".format( can, texto_tipo, tipo, titulo), height=2, align='center') p.writelines("") p.writelines("") except Exception as e: print("[ERROR ] %s" % e)
from escpos.printer import File printer = File(devfile='/dev/usb/lp0') printer.text("سبسلبلبلل\n") printer.text("some text\n") printer.text("some text\n") printer.text("سبلبلباال\n") # printer.set(codepage='pc864') printer.profile.media['width']['pixels'] = 575 printer.image("images/logo-text-small.png", center=True) # printer.image("images/logo-text-small.png") # printer.set(align=u'center') printer.text("Far" + "\n\n") # printer.text(total_price + " Toman" + "\n") printer.qr('total_price', size=8, center=True) # printer.qr(str(self.total_price), size=8) # printer.text(mobile_number + "\n") printer.text("farazist.ir" + "\n") # printer.text(datetime) printer.cut()
def write_order(order, usb_printer=None, print_item_code=True): if usb_printer: p = usb_printer else: p = File("/dev/usb/lp0") print("ORDER ITEMS") lines = [] for i in order.items: lines.append(i.__dict__) # Order p.text('Order Id: {0}\n'.format(order.id)) # Table Number p.text('Table Number: {0}\n'.format(order.table_no)) # Take Away p.text('Type: {0}\n\n'.format(order.type)) # Headers header_line = line_block([ { 'text': 'Qty', 'align': '<', 'width': QTY_WIDTH }, { 'text': 'Item', 'align': '<', 'width': ITEM_WIDTH }, ]) p.text(header_line) # Lines for line in lines: line_text = line_block([ { 'text': line['qty'], 'align': '<', 'width': QTY_WIDTH }, { 'text': line['item_name'], 'align': '<', 'width': ITEM_WIDTH }, ]) p.text(line_text) if print_item_code: item_code = line_block([{ 'text': '-', 'align': '<', 'width': QTY_WIDTH }, { 'text': line['item_code'], 'align': '<', 'width': ITEM_WIDTH }]) p.text(item_code) # Remarks p.text('\n\nRemarks:\n{0}'.format(order.remarks)) # Time p.text('\n\nPrinted on:\n') p.text(time.ctime()) p.cut()
def saveToText(self, fn): f = File(fn) f._raw(self.p.output) f.cut()
def printAJsBill(bill, table): item_quantitys = bill.getBillSummary() bid = str(bill.bid) time = str(datetime.now()) table = table.name.upper() total = str(bill.amount) epson = File("/dev/usb/lp0") Printer.printAJsAddress(bid=bid, table=table, time=time, epson=epson) # epson.text('01234567890123456789012345678901\n') epson.text('--------------------------------\n') epson.set(align='left', text_type='B', width=1, height=1) epson.text('Item Qt Rate Amt\n') epson.set(align='left', text_type='normal', width=1, height=1) epson.text('--------------------------------\n') sub_total = 0 for iq in item_quantitys: name = str(iq.get('item').cat) cost = str(iq.get('item').cost) quantity = str(iq.get('quantity')) amount = str(iq.get('quantity') * iq.get('item').cost) if len(name) > 16: epson.text(txt=name[0:16]) epson.text(' ') Printer.printQuantityCostAndAmount(epson=epson,\ name=name, cost=cost, quantity=quantity, amount=amount) epson.text(txt=name[16:len(name)]) epson.text(txt='\n') else: epson.text(txt=name) for i in range(16 - len(name)): epson.text(' ') epson.text(' ') Printer.printQuantityCostAndAmount(epson=epson,\ name=name, cost=cost, quantity=quantity, amount=amount) epson.set(align='left', text_type='B', width=1, height=1) epson.text('--------------------------------\n') epson.text('TOTAL Rs ' + total + '\n') epson.text('\n') epson.set(align='left', text_type='normal') epson.text('COMPOSITION TAXABLE PERSON\n') epson.text('GSTIN: 30AFGPG9096R1ZT\n') epson.set(align='left', text_type='B') epson.text(' FREE HOME DELIVERY \n') epson.text('\n') epson.cut()
def imprimirPreTicket(self, camarero, numcopias, fecha, mesa, lineas, total): if type(fecha) is datetime: fecha = fecha.strftime("El %a %d-%B a las (%H:%M)") else: fecha = datetime.strptime(fecha, "%Y-%m-%d %H:%M:%S.%f") fecha = fecha.strftime("El %a %d-%B a las (%H:%M)") try: if self.tipo == "Network": printer = Network(self.ip_caja, timeout=1) if self.tipo == "Usb": printer = Usb(*self.usb) if self.tipo == "File": printer = File(self.url) with EscposIO(printer) as p: p.printer.codepage = 'cp858' p.printer._raw(escpos.CHARCODE_PC852) p.printer.set(align='center') p.writelines('PRETICKET', font='a', height=2, align='center') p.writelines('') p.writelines('------------------------------------------', align='center') p.writelines('FECHA', height=2, width=2, font='a', align='center') p.writelines(fecha, height=2, width=1, font='b', align='center') p.writelines("Num copias: %d" % numcopias, font='a', align='center') p.writelines("Mesa: %s" % mesa, font='a', align='center') p.writelines('------------------------------------------', align='center') for ln in lineas: p.writelines( "{0: >3} {1: <20} {2:5.2f} € {3:6.2f} €".format( ln['can'], ln['nombre'], float(ln['precio']), float(ln['totallinea'])), align='center', font="a") p.writelines("") p.writelines("Total: {0:0.2f} €".format(float(total)), align='right', height=2) p.writelines("") p.writelines("No olvide pedir su ticket", text_type='bold', height=2, align='center') p.writelines(camarero, text_type='bold', font='a', align='center') p.writelines("") p.writelines("") except Exception as e: print("[ERROR ] %s" % e)
p.writelines("") p.writelines("No olvide pedir su ticket", text_type='bold', height=2, align='center') p.writelines(camarero, text_type='bold', font='a', align='center') p.writelines("") p.writelines("") except Exception as e: print("[ERROR ] %s" % e) def test_print(self): print("Test print console") if __name__ == '__main__': import sys import os import locale #locale.setlocale(locale.LC_TIME, "es_ES.UTF-8") # swedish with EscposIO(File("/dev/usb/lp0")) as p: p.printer.codepage = 'cp858' p.printer._raw(escpos.CHARCODE_PC852) p.writelines("ñññññ€", height=2, width=2)
def write_order_void(order, usb_printer=None, print_item_code=True): if usb_printer: p = usb_printer else: p = File("/dev/usb/lp0") lines = [] for i in order.items: lines.append(i.__dict__) # Order p.text('Void Items') # Headers header_line = line_block([ { 'text': 'Qty', 'align': '<', 'width': QTY_WIDTH }, { 'text': 'Item', 'align': '<', 'width': ITEM_WIDTH }, ]) p.text(header_line) # Lines for line in lines: if line['is_voided']: line_text = line_block([ { 'text': line['qty'], 'align': '<', 'width': QTY_WIDTH }, { 'text': line['item_name'], 'align': '<', 'width': ITEM_WIDTH }, ]) p.text(line_text) if print_item_code: item_code = line_block([{ 'text': '-', 'align': '<', 'width': QTY_WIDTH }, { 'text': line['item_code'], 'align': '<', 'width': ITEM_WIDTH }]) p.text(item_code) # Time p.text('\n\nPrinted on:\n') p.text(time.ctime()) p.cut()
def setup(): global myTwitterStream, myTwitterClient, mySmsStream global lastTwitterCheck, lastSmsCheck global myNeuralNet global PHONE_NUMBER,PHONE_FORMAT global logFile global screen, font, font_title global printer, PRT_MODEL lastTwitterCheck = time() lastSmsCheck = time() with open('secrets.json') as dataFile: data = json.load(dataFile) ## What to search for SEARCH_TERMS = data["search_terms"] PHONE_NUMBER = data["phone_number"] PHONE_FORMAT='({}) {}-{}'.format(PHONE_NUMBER[2:5], PHONE_NUMBER[5:8], PHONE_NUMBER[8:]) PRT_MODEL = data["printer_model"] try: if PRT_MODEL == "adafruit": printer = Adafruit_Thermal(data["usb_port"], 9600, timeout=5) printer.begin(255) elif PRT_MODEL == "epson": printer = File("/dev/usb/lp0") except: print('Error loading serial port...') ## start Twitter stream reader myTwitterStream = TwitterStreamReceiver(app_key = data["twitter"]['CONSUMER_KEY'], app_secret = data["twitter"]['CONSUMER_SECRET'], oauth_token = data["twitter"]['ACCESS_TOKEN'], oauth_token_secret = data["twitter"]['ACCESS_SECRET']) #twitter client to post twitts myTwitterClient = Twython(app_key = data["twitter"]['CONSUMER_KEY'], app_secret = data["twitter"]['CONSUMER_SECRET'], oauth_token = data["twitter"]['ACCESS_TOKEN'], oauth_token_secret = data["twitter"]['ACCESS_SECRET']) streamThread = Thread(target=myTwitterStream.statuses.filter, kwargs={'track':','.join(SEARCH_TERMS)}) streamThread.daemon = True streamThread.setName('TwitterThread') streamThread.start() ## start Twilio client mySmsStream = SMSReceiver(data["twilio"]['ACCOUNT_SID'], data["twilio"]['AUTH_TOKEN']) smsStreamThread = Thread(target=mySmsStream.update) smsStreamThread.daemon = True smsStreamThread.setName('SmsThread') smsStreamThread.start() myNeuralNet = NeuralNetProcessor(data['working_path'], data['model_path'], data['length'], data['temperature']) ## open new file for writing log now = datetime.now(utc) logFile = open("logs/" + now.isoformat() + ".log", "a") #getNeuralNetText('Life is hard') #init pygame pygame.init() pygame.display.set_caption("RapRobot") pygame.mouse.set_visible(False) screen = pygame.display.set_mode(SCREEN_RESOLUTION) screen.fill((0,0,0)) pygame.display.update() font = pygame.font.Font("assets/HN.otf", FONT_SIZE) font_title = pygame.font.Font("assets/HN.otf", FONT_SIZE*2)
def write_order(order, usb_printer=None, print_item_code=True): if usb_printer: p = usb_printer else: p = File("/dev/usb/lp0") lines = loads(order.lines) # Order p.text('Order Id: {0}\n'.format(order.id)) # Table Number p.text('Table Number: {0}\n'.format(order.table_no)) # Take Away if order.is_takeaway: p.text('Type: TAKE AWAY\n\n') else: p.text('Type: DINE IN\n\n') # Headers header_line = line_block([ {'text': 'Qty', 'align': '<', 'width': QTY_WIDTH}, {'text': 'Item', 'align': '<', 'width': ITEM_WIDTH}, ]) p.text(header_line) # Lines for line in lines: line_text = line_block([ {'text': line['qty'], 'align': '<', 'width': QTY_WIDTH}, {'text': line['itemName'], 'align': '<', 'width': ITEM_WIDTH}, ]) p.text(line_text) if print_item_code: item_code = line_block([ {'text': '-', 'align': '<', 'width': QTY_WIDTH}, {'text': line['itemCode'], 'align': '<', 'width': ITEM_WIDTH} ]) p.text(item_code) # Remarks p.text('\nRemarks:\n{0}'.format(order.remarks)) # Time p.text('\n\nPrinted on:\n') p.text(time.ctime()) p.cut()
def imprimirTicket(self, num, camarero, fecha, mesa, total, efectivo, cambio, lineas): if type(fecha) is datetime: fecha = fecha.strftime("El %a %d-%B a las (%H:%M)") else: fecha = datetime.strptime(fecha, "%Y/%m/%d %H:%M") fecha = fecha.strftime("El %a %d-%B a las (%H:%M)") try: if self.tipo == "Network": printer = Network(self.ip_caja, timeout=1) if self.tipo == "Usb": printer = Usb(*self.usb) if self.tipo == "File": printer = File(self.url) with EscposIO(printer) as p: p.printer.codepage = 'cp858' p.printer._raw(escpos.CHARCODE_PC852) p.printer.image("logo.png") p.writelines('Calle Dr Mesa Moles, 2', font='a', align='center') p.writelines('18012 Granada', font='a', align='center') p.writelines('NIF: B18616201', font='b', align='center') p.writelines('------------------------------------------', align='center') p.writelines(fecha, height=2, width=1, font='b', align='center') p.writelines("Num Ticket: %d" % num, font='a', align='center') p.writelines("Camarero: %s" % camarero, font='a', align='center') p.writelines("Mesa: %s" % mesa, font='a', align='center') p.writelines('------------------------------------------', align='center') for ln in lineas: p.writelines( "{0: >3} {1: <20} {2:5.2f} € {3:6.2f} €".format( ln['can'], ln['nombre'], float(ln['precio']), float(ln['totallinea'])), density=1, align='center') p.writelines("", text_type='bold', font='b', align='center') p.writelines("Total: {0:0.2f} €".format(float(total)), align='right', height=2) p.writelines("Efectivo: {0:0.2f} €".format(float(efectivo)), align='right') p.writelines( "Cambio: {0:0.2f} €".format(float(cambio)), align='right', ) p.writelines("", text_type='bold', font='a', align='center') p.writelines("Factura simplificada", text_type='bold', font='a', align='center') p.writelines("Iva incluido", text_type='bold', font='a', align='center') p.writelines("Gracias por su visita", font='a', align='center') except Exception as e: print("[ERROR ] %s" % e)
def printReceipt(self): p = File("/dev/usb/lp0", auto_flush=False) # Header Receipt p.set(align='center', text_type='B') p.text("Kantin Wisuda Oktober\n") p.text("Institut Teknologi Bandung\n") p.text(self.orderTime + "\n") # p.text("Rabu,13/02/2019,15:30\n") # printTableNumber(orderList[0]['tableNumber']) p.text("Nomor Meja: " + str(self.orderList[0]['tableNumber'])) p.text("\n") p.text("Order ID: " + str(self.orderID)) p.text("\n\n\n") # Print Receipt List p.set(align='left') p.text('\x1b\x44\x00') # reset tabulation p.text('\x1b\x44\x10\x19\x00') # tabulation setting location for item in self.orderList: subTotal = item['price'] * item['qty'] p.text(str(item['menuName']) + "\n") p.text( str(item['price']) + "\x09" + "x" + str(item['qty']) + "\x09" + str(subTotal) + "\n") p.text("--------------------------------\n\n") p.text("Total Belanja " + "\t" + "\t" + str(self.totalPrice)) p.text("\n") p.set(align='center') p.text("Card ID: {}".format(self.cardID)) p.text("\n") p.text("Saldo Akhir: {}".format(formatRupiah(self.balance))) p.text("\n\n") p.set(align='center') p.text("-TERIMAKASIH-") p.cut() p.flush()
def main(total_price, datetime): try: printer = File(devfile='/dev/usb/lp0') printer.profile.media['width']['pixels'] = 575 printer.image("images/logo-text-small.png", center=True) # printer.image("images/logo-text-small.png") printer.set(align=u'center') printer.text("\n") # printer.text('Your ID: ' + str(user_id) + "\n") printer.text(total_price + " Toman" + "\n") # printer.qr(total_price, size=12, center=True) # printer.text('Support: ' + owner_mobile_number + "\n") # printer.text('ID: ' + str(owner_id) + "\n") printer.text("farazist.ir" + "\n") printer.text(datetime) printer.cut() print("print receipt") except Exception as e: print("error:", e)
def printKOT(orders, kid): epson = File("/dev/usb/lp0") epson.text('\n\n\n\n') epson.set(text_type='B', width=2, height=2) table = orders[0].table epson.text('' + table.name + ' KID:' + str(kid) + '\n') epson.set(text_type='normal', width=1, height=2) for order in orders: name = order.item.name quantity = order.quantity message = str(order.message) epson.text(' ' + name) epson.set(text_type='U', width=1, height=2) epson.text(' ' + message) epson.set(text_type='normal', width=1, height=2) epson.text(' x' + str(quantity) + '\n') epson.cut() epson.close()
from escpos.printer import File printer = File('/dev/usb/lp0') PRINTER_CHAR_WIDTH = 32 API_HOST = 'api.flipdot.org' API_PREFIX = '/sensors/' DB_SENSOR_TYPE = 'beverage_consumption' STATS_URL = 'https://stats.flipdot.org/d/-wCfcYtZz/0xa-drinks-consumption' BANNER_FREQUENCY = 20 QR_CODE_SIZE = 11