3

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.

Josh Anderson
  • 438
  • 3
  • 7
uoah
  • 169
  • 1
  • 4
  • 13
  • Set up the printer as the default printer (text only driver) and print like you would any other document. To open the drawer, you need to be able to access the COM port and know what signal to send it. – David Dec 15 '11 at 18:51
  • Thanks, I've printed with this way but I need open the drawer. thanks anyway. – uoah Dec 19 '11 at 10:00

3 Answers3

6

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)

Zyo
  • 1,934
  • 21
  • 25
0

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.

Simon MᶜKenzie
  • 8,344
  • 13
  • 50
  • 77
0

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)
Malcolm O'Hare
  • 4,879
  • 3
  • 33
  • 53
  • Thanks a lot, I will try it asap (not all days I have access to printer and drawer). I was trying to use PosExplorer library but visual didn't recognized. I think that utility SetupPos.exe comes with the printer's installation cd. Thanks – uoah Dec 19 '11 at 10:03
  • Don't forget to add a reference to Microsoft.PointOfService.dll in your project. That could be why VS didn't recognize it. – Malcolm O'Hare Dec 19 '11 at 14:50
  • Yes, I found that reference in some examples but my VS didn't recognized it. Maybe I have to install first SetupPos.exe. Today I'll try it. Thanks :) – uoah Dec 20 '11 at 10:13
  • Now I can print but I'm trying to send the codes to cut the paper and print the logo (stored in the printer with the epson's software) but the printer doesn't makes anything. Any suggestion? – uoah Dec 26 '11 at 20:00
  • @uoah can you post what you are doing to send the cut paper and print logo commands? Then I can see what is wrong. – Malcolm O'Hare Dec 28 '11 at 04:24
  • I've edited the code with I use to send codes to the printer. I found this codes ((char)27 + "|#fP") and (char)27 + "|tL") in the documentation of TM printers I've downloaded from EpsonExpert for TM Printers. – uoah Dec 28 '11 at 09:54
  • google for ESC-POS-Programming-Guide . You'll find it has all the information you need. – Malcolm O'Hare Dec 28 '11 at 14:20
  • Ok, I'll try it, by the way, the code you edited: _oposPrinter.PrintNormal((char)29 + (char)47 + (char)0) isn't working for me because _oposPrinter.PrintNormal requires an PrinterStation.Receipt and string. Thanks, you are helping me a lot. – uoah Dec 28 '11 at 15:51
  • Thanks but method PrintNormal requires (PrinterStation,string) I tried to Convert.ToString((char)29 + (char)47 + (char)0); but it doesn't works. Now I'll try to search ESC-POS-Programming-Guide. – uoah Dec 28 '11 at 19:20
  • Searching some info I've found this: "\x1B" + "m"; for cut the paper and "\x1B" + "d" + "\x09"; to feed the paper. Both of two strings are working fine, now I can feed and cut the paper, the problem is that I don't understand this strings and I need to print the stored logo and if I understand the strings I could print the logo. – uoah Dec 28 '11 at 19:45
  • I'm using your code, on T20 Epson, but when i execute it doesn't print on the printer, instead it displays a new form : **Microsoft PostPrinter Simulator** , what am i doing wrong ? – KADEM Mohammed Mar 15 '14 at 18:52