【问题标题】:Why do I have to call the initialization command twice? (otherwise i get the output "t@")为什么我必须调用两次初始化命令? (否则我得到输出“t@”)
【发布时间】:2020-07-20 07:55:16
【问题描述】:

我有一台 Epson TM-T88VI 打印机并使用 C# 中的 Microsoft.PointOfService.PosPrinter 进行打印。

我有以下两个测试函数:

    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);
    }

这两个函数之间的唯一区别是:在函数 2 中,我向打印机发送了一个“双重”初始化(参见 string cmd = 初始化)。 通常我希望这两个函数会导致相同的结果。但事实并非如此。

调用“printerTestFunction2”后,我得到了预期的输出:

A€A

B€B

当我重新启动程序并调用“printerTestFunction”时,我得到以下输出:

t@A€A

B€B

我还测试了其他功能。第一个 init 命令总是打印为“t@”,除非我初始化打印机两次。

有人能解释一下这种行为吗?

【问题讨论】:

    标签: c# epson escpos pos-for-.net


    【解决方案1】:

    这是因为,正如我回答上一个问题,应用程序正在直接发送初始化命令。
    Why is the “€” character only printed before printer initialization and not after the initialization?

    如果您使用 POS for.NET(包括 OPOS/JavaPOS),则不应使用初始化命令 (ESC@) 或类似命令来更改模式或设置。

    如果你想做某事,调用方法或将UnifiedPOS中定义的POSPrinter转义序列放入打印请求字符串中。

    【讨论】:

      【解决方案2】:

      我认为这可能是因为您没有在命令末尾添加“Esc @”。在Page335 示例中,指出每个程序都有“Start Job”和“End Job”与代码“Esc @”相同(与新的“byte[] { 27, 64 }”相同)

      但是看起来你没有在命令末尾添加这个,所以如果你下次命令“Esc @”,实际上是最后一次“结束作业”的程序吗?我想这可能是输出前有“t@”之类的原因?

      因此您可以尝试以下更改:

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

      如果是,第二次可能会成功。

      【讨论】:

      • 在函数printerTestFunction中添加另一个init导致相同的结果,t@仍然被打印
      猜你喜欢
      • 2020-05-31
      • 2017-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-14
      • 1970-01-01
      相关资源
      最近更新 更多