Search code examples
c#thermal-printerpos-for-.net

Print and open drawer with Epson T20 (thermal printer)


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.


Solution

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