I have a POS application built on c# visual studio 2012.
The POS solution is based on transaction of money from a consumer to the beneficiary. My POS solution gives a printout for every transaction occurred.I am using an EPSON TM-T81 thermal printer. The EPSON api for c# are being used. Right now I send the commands for printing directly to the printer as RAW data. But I want to use the windows spooler to send the commands for print.
The api provided by EPSON only gives code for RAW printing. There is a function for Asynchronous Print, but does not give the required result.My c# application is based on socket communication between a main server and a couple of hand-held devices which carry out the transaction of money. For this I am using a asynchronous socket server. Upto this part there is no problem, but If there are 2 transactions occurring at the same time, the printer only prints a single receipt. I have put a sleep() for about 2 sec in between 2 prints, but still this is not the way and will cause problems later.
My code for sending print commands using c# :
m_Printer.PrintNormal(PrinterStation.Receipt, "\u001b|N" + "userID : " + cardId + "\n");
m_Printer.PrintNormal(PrinterStation.Receipt, "\u001b|N" + "Member : " + user_name + "\n");
I am initializing the printer earlier :
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");
}
I want to shift from direct RAW printing to using the windows spooler on c#.
I had a look at the windows spooler api : Windows Spooler API But do not know how to implement my format and printer using the same.
I would appreciate any help provided.
Using RAW data type does not mean the data isn't being spooled. It most likely is. To find out, pause the printer, print something, then go look in
\windows\system32\spool\printers
. If you find two files there with .SPL and .SHD extensions, the data is being spooled.But if the Epson API is communicating directly with the printer and bypassing the spooler, I don't know what that API does so can't tell you how to replicate it. For that, you'll need the technical manual for the printer. However, assuming the printer has a print driver installed, you should be able to print to it using the Win32 API or .NET just as you would with any other printer. The simplest way to find out if you can print to this printer through the normal Windows mechanisms is to just open Notepad, type something, and print it. If that works, then you can discard the Espson API and print using Win32 or .NET.