1

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

Fi3n1k
  • 863
  • 3
  • 12
  • 20
  • try "wb" mode instead of "a" and configure printer to accept commands. [To open attached cash drawer](http://keyhut.com/popopen.htm) the control codes are `27,112,0,25,250` – jfs Oct 31 '12 at 12:06
  • when i enter code for open_till the printer is not printing at all – Fi3n1k Nov 08 '12 at 14:39

1 Answers1

1

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")
E.D
  • 78
  • 7