我有一个基于c#visual studio 2012构建的POS应用程序。
POS解决方案基于从消费者到受益人的资金交易。我的POS解决方案为每次发生的交易提供打印输出。我使用的是EPSON TM-T81热敏打印机。正在使用c#的EPSON api。现在我将打印命令作为RAW数据直接发送到打印机。但我想使用Windows假脱机程序发送打印命令。
EPSON提供的api仅提供RAW打印的代码。有一个异步打印功能,但没有提供所需的结果。我的c#应用程序是基于主服务器和几个手持设备之间的套接字通信,这些设备进行货币交易。为此,我使用的是异步套接字服务器。这部分没有问题,但如果同时发生2个交易,则打印机只打印一个收据。我在两次打印之间放了一个sleep()大约2秒,但是这不是方法,以后会引起问题。
我使用c#发送打印命令的代码:
m_Printer.PrintNormal(PrinterStation.Receipt, "\u001b|N" + "userID : " + cardId + "\n");
m_Printer.PrintNormal(PrinterStation.Receipt, "\u001b|N" + "Member : " + user_name + "\n");
我之前正在初始化打印机:
PosExplorer posExplorer = new PosExplorer();
DeviceInfo deviceInfo = null;
try
{
deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName);
m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo);
}
catch (Exception)
{
}
//Register OutputCompleteEventHandler.
AddOutputComplete(m_Printer);
//Open the device
m_Printer.Open();
try
{
//Get the exclusive control right for the opened device.
//Then the device is disable from other application.
m_Printer.Claim(1000);
Console.WriteLine("Printer claimed");
}
catch (Exception e)
{
Console.WriteLine("Printer Not claimed");
}
我想从直接RAW打印转到使用c#上的Windows假脱机程序。
我看了一下windows后台处理程序api: Windows Spooler API 但是不知道如何使用相同的方式实现我的格式和打印机。
感谢您提供的任何帮助。
答案 0 :(得分:3)
使用RAW数据类型不表示数据未被假脱机。它很可能是。要查找,暂停打印机,打印一些内容,然后查看\windows\system32\spool\printers
。如果你找到两个带有.SPL和.SHD扩展名的文件,那么数据就会被假脱机。
但是如果Epson API 直接与打印机通信并绕过假脱机程序,我不知道该API做了什么,因此无法告诉您如何复制它。为此,您需要打印机的技术手册。但是,假设打印机安装了打印驱动程序,您应该能够像使用任何其他打印机一样使用Win32 API或.NET进行打印。通过常规Windows机制确定是否可以打印到此打印机的最简单方法是打开记事本,键入内容并打印。如果可行,则可以丢弃Espson API并使用Win32或.NET进行打印。