Search code examples
c#epsonescpospos-for-.net

Why is the "€" character only printed before printer initialization and not after the initialization?


I have an Epson TM-T88VI printer and use the Microsoft.PointOfService.PosPrinter in C# for printing.

Using the following function i get a strange output printed:

    public static void printerTestFunction2(string printerName)
    {
        PosExplorer explorer = new PosExplorer();
        DeviceInfo di = explorer.GetDevice("PosPrinter", printerName);
        PosPrinter printer = (PosPrinter)explorer.CreateInstance(di);

        printer.Open();
        printer.Claim(10000);
        printer.DeviceEnabled = true;
        printer.AsyncMode = false;

        string init = System.Text.ASCIIEncoding.ASCII.GetString(new byte[] { 27, 64 });
        string totalCut = System.Text.ASCIIEncoding.ASCII.GetString(new byte[] { 27, 105 });
        string cmd = init + init + "A€A\nB€B\n" + init + "C€C\nD€D\n\n\n\n\n\n\n" + totalCut;
        printer.PrintNormal(PrinterStation.Receipt, cmd);
    }

The output is:

A€A

B€B

CFC

DFD

enter image description here

So the € symbol is printed as a strange "F" symbol (seems like the F is lower than the normal characters). The paper is cut correctly.

I also have tested different constellations. It seems that the "€" sign is only printed before the first init command which is send to the printer after at least one row has been printed out. (I can send multiple init commands at the beginning - the € is printed. If i send the init after some chars have been printed, the "F" will appear instead of the "€"). If I restart my program, the "€" is again printed correctly, but if i send the init command it will be printed as "F" again.

What is the reason that the "€" symbol is only printed before the third init command? Is there anything wrong with my code or do i miss a setting?


Solution

  • The reason why letters like F are printed is because the printer is in the initialized state, code page 437.
    Look at the letters in the following material at 213 in decimal and 0xD5 in hexadecimal.

    Page 0 [PC437: USA, Standard Europe]

    Page 19 [PC858: Euro]


    The POS for.NET service object internally manages code page settings according to the value of CharacterSet property.

    If the application arbitrarily sends initialization commands to the printer, the service object's management information may be inconsistent and the printer may print incorrectly.

    If you are using POS for.NET (including OPOS/JavaPOS), you should not use the initialization command (ESC@) or similar commands to change the mode or settings.

    In that sense, instead of sending the paper cut also directly the ESC i({ 27, 105 }) command, call the CutPaper method or put the POSPrinter paper cut escape sequence (ESC|P) defined in UnifiedPOS in the print request string.