Reputation: 169
I've searching a lot and I've found here examples with Posexplorer but my printer is usb and I've read that PosExplorer is for parallel. I don't know how to print with the printer and how to send the code to printer to open the drawer.
I'm using to send escape sequence to the printer the following code:
string ESC = Convert.ToString((char)27);
string logo=Convert.ToString(ESC+"|tL");
_oposPrinter.PrintNormal(PrinterStation.Receipt, logo);
_oposPrinter.PrintNormal(PrinterStation.Receipt, "Print example\n");
_oposPrinter.PrintNormal(PrinterStation.Receipt, Convert.ToString((char)27 + "|#fP"));
When debugging and reaches the lines:
_oposPrinter.PrintNormal(PrinterStation.Receipt, logo);
or
_oposPrinter.PrintNormal(PrinterStation.Receipt, Convert.ToString((char)27 + "|#fP"));
The printer doesn't prints anything.
Upvotes: 3
Views: 15620
Reputation: 2068
If you are looking to a very lightweight solution without having a 3rd party installed software such as Microsoft POS for .NET.
You need to include the function RawPrinterHelper (can be download from https://support.microsoft.com/en-us/help/322091/how-to-send-raw-data-to-a-printer-by-using-visual-c-.net)
Then send the specific cash drawer code to open it to the printer it's connected to.
For instance, on an Epson TM88, this function would open it.
SendStringToPrinter(printerName, System.Text.ASCIIEncoding.ASCII.GetString(new byte[] { 27, 112, 48, 55, 121 }));
Other printers may require other code sequences.
Citizen
27,112,0,50,250
Epson
27,112,48,55,121
27,112,0,25,250
27,112,48,25,250
IBM
7
... (view more code including auto-cutter or 2nd drawer at http://keyhut.com/popopen.htm)
Upvotes: 6
Reputation: 31
For those trying to do this with VB.NET and POS.NET, send this to the printer:
m_printer = the instance you created for the PosExplorer
m_printer.PrintNormal(PrinterStation.Receipt, System.Text.ASCIIEncoding.ASCII.GetString(New Byte() {27, 112, 48, 55, 121}))
This worked for my Epson TM-T20
Odd thing is that it doesn't open on the first send, but every one after.
Upvotes: 0
Reputation: 5009
I know this code works for normal printing. I have not tested the cash drawer portion but I believe that is the correct command, you just need to know the right parameters to put with it.
This code assumes that you have set up your printer using the utility SetupPos.exe provided by Epson. I don't remember where I got it, but EpsonExpert.com might be a good place to look. Then just make sure you are passing the correct LDN (you set it up in the setuppos software).
PosExplorer explorer = null;
DeviceInfo _device;
PosPrinter _oposPrinter;
string LDN;
explorer = new PosExplorer();
_device = explorer.GetDevice(DeviceType.PosPrinter, LDN);
_oposPrinter = (PosPrinter)explorer.CreateInstance(_device);
_oposPrinter.Open();
_oposPrinter.Claim(10000);
_oposPrinter.DeviceEnabled = true;
// normal print
_oposPrinter.PrintNormal(PrinterStation.Receipt, yourprintdata);
// pulse the cash drawer pin pulseLength-> 1 = 100ms, 2 = 200ms, pin-> 0 = pin2, 1 = pin5
_oposPrinter.PrintNormal(PrinterStation.Receipt, (char)16 + (char)20 + (char)1 + (char)pin + (char)pulseLength);
// cut the paper
_oposPrinter.PrintNormal(PrinterStation.Receipt, (char)29 + (char)86 + (char)66)
// print stored bitmap
_oposPrinter.PrintNormal(PrinterStation.Receipt, (char)29 + (char)47 + (char)0)
Upvotes: 0