Why do I have to call the initialization command twice? (otherwise i get the output "t@")

194 Views Asked by At

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

I have the following two test functions:

    public static void printerTestFunction(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 + "A€A\nB€B\n\n\n\n\n\n\n\n" + totalCut;
        printer.PrintNormal(PrinterStation.Receipt, cmd);
    }

    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\n\n\n\n\n\n\n" + totalCut;
        printer.PrintNormal(PrinterStation.Receipt, cmd);
    }

The only difference between the two functions: in function2 i send a "double" init to the printer (see string cmd = initialization). Normally I would expect the two functions to lead to the same result. But that is not the case.

After calling "printerTestFunction2" i get the output as expected:

A€A

B€B

correct output

When i restart my program and call "printerTestFunction" i get the following output:

t@A€A

B€B

wrong output

I also tested with other functions. The first init command is always printed as "t@" except if I init the printer twice.

Can somebody explain that behaviour?

2

There are 2 best solutions below

0
On

This is because, as I answered the previous question, the application is sending the initialization command directly.
Why is the “€” character only printed before printer initialization and not after the initialization?

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.

If you want to do something, call the method or put the POSPrinter escape sequence defined in UnifiedPOS into the print request string.

1
On

I think its may cause because you didn't add "Esc @" in the end of command. In Page335 example, there are point out every program have "Start Job" and "End Job" is the same of code "Esc @"(same to new "byte[] { 27, 64 }" )

But it looks like you didn't add this at the end of the command, so if next time you command "Esc @", actually is the last time program of "End Job"? I guess this may be the reason why there have something like "t@" before output?

So you can try something changes like:

string cmd = init + "A€A\nB€B\n\n\n\n\n\n\n\n" + totalCut + init;

If ture, it may success at the second time.