opening till through printer with Python

2.1k Views Asked by At

I have Epson TM-U220B Network printer and a cash drawer. I am developing Python Web app I managed to configure printer over my application. My printer is working fine, I just want to open till when I print ticket. I found some codes over internet for opening till drawer.

Here is the code:

def print_(printer_name, file_path):
    preorder = chr(27)+chr(100)+chr(0)    
    cut_paper = chr(29)+chr(86)+chr(66)+chr(0)

    open_till = chr(27)+chr(112)+chr(10)

    the_file = open(file_path, "a")
    the_file.seek(0)
    the_file.write(preorder)
    the_file.seek(0,2)
    the_file.write(cut_paper)
    the_file.write(open_till)
    the_file.close()
    conn.printFile(printer_name, file_path, md5(file_path), {})

The open_till is the code that not working, everything else is ok

Thank you

1

There are 1 best solutions below

0
On

You can use the below code to open the cash drawer

import win32print

def OpenCashDrawer(printerName) :   
       printerHandler = win32print.OpenPrinter(printerName)
       cashDraweOpenCommand = chr(27)+chr(112)+chr(0)+chr(25)+chr(250)
       win32print.StartDocPrinter(printerHandler, 1, ('Cash Drawer Open',None,'RAW')) 
       win32print.WritePrinter( printerHandler, cashDraweOpenCommand)
       win32print.EndDocPrinter(printerHandler)
       win32print.ClosePrinter(printerHandler)

OpenCashDrawer("YourPrinterName")