0

我有一台 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”后,我得到了预期的输出:

欧元

早餐

正确的输出

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

t@A€A

早餐

错误的输出

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

有人可以解释这种行为吗?

4

2 回答 2

1

这是因为,正如我回答上一个问题一样,应用程序正在直接发送初始化命令。
为什么“€”字符只在打印机初始化之前打印,而不是在初始化之后?

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

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

于 2020-04-08T01:30:09.700 回答
0

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

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

所以你可以尝试一些改变,比如:

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

如果真的,它可能会在第二次成功。

于 2020-04-08T01:31:37.480 回答