我有一台 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@”。
有人可以解释这种行为吗?