【问题标题】:opening till through printer with Python使用 Python 打开直到通过打印机
【发布时间】:2012-10-20 17:51:29
【问题描述】:

我有 Epson TM-U220B 网络打印机和一个钱箱。我正在开发 Python Web 应用程序,我设法通过我的应用程序配置打印机。我的打印机工作正常,我只想打开直到打印票。我在互联网上找到了一些打开抽屉的代码。

代码如下:

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), {})

open_till 是不工作的代码,其他一切正常

谢谢

【问题讨论】:

  • 尝试“wb”模式而不是“a”并配置打印机以接受命令。 To open attached cash drawer 控制码为27,112,0,25,250
  • 当我输入 open_till 的代码时,打印机根本不打印

标签: python epson network-printers drawer twistd


【解决方案1】:

您可以使用以下代码打开钱箱

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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多