使用 SDK 发送 TCP 后 Zebra 打印机暂停

问题描述 投票:0回答:2

我使用 Zebra Link-OS SDK nuget 来利用打印机的操作系统功能,包括连接、打印和管理任务。

我正在将几页发送到几台不同的斑马打印机,所有型号都是较旧的。我正在使用 Zebra C# SDK 按照他们提供的示例来执行此操作。我大约每 500 毫秒向每台打印机发送一页。当我这样做时,一些打印机会随机“暂停”自己并停止打印。点击打印机上的“暂停”按钮可取消暂停并恢复打印作业。没有页面丢失,只是令人沮丧,因为用户必须站在那里并不断“取消暂停”打印机才能开始打印。更改打印作业之间的延迟时间似乎没有什么区别。客户端有另一个应用程序,它使用假脱机程序队列而不是 TCP,但它似乎无法实现这种情况。我可以调整打印机上的某处设置来停止这种情况,或者我可以对代码进行任何更改来停止这种随机暂停吗?

var Zebra.Sdk.Comm.Connection thePrinterConn;
thePrinterConn = new Zebra.Sdk.Comm.TcpConnection(IPAddress, TcpConnection.DEFAULT_ZPL_TCP_PORT);    

public string SendZplOverTcp(string zplPayload)
{                        
    if (!MockSending)
    {
        try
        {
            // Open the connection - physical connection is established here.
            thePrinterConn.Open();
            if (!thePrinterConn.Connected)
            {
                return  "ERROR : PRINTER OFFLINE";
            }
           

            // Send the data to printer as a byte array.
            thePrinterConn.SendAndWaitForResponse(Encoding.UTF8.GetBytes(zplPayload), 1000, 500, "\\r");
        }
        catch (Exception e)
        {
            // Try again if it failed, wait for Printer to consume all it's data, or for 15 seconds

            thePrinterConn.WaitForData(15000);
            thePrinterConn.SendAndWaitForResponse(Encoding.UTF8.GetBytes(zplPayload), 1000, 500, "\\r");

            // if it fails again here, bubble the error up so we can log it with label data intact

        }
    }
    // don't close connection automatically, otherwise it will have to re-open on the next pass

    return "OK";
}
c# printing zpl zebra
2个回答
1
投票

我无法弄清楚为什么它会自行暂停,但我确实找到了一种以不同方式解决问题的方法。

在打印机服务中,使用 SDK,我可以检查打印机是否已暂停,如果是,则在将页面的 ZPL 发送到打印机之前发出 ZPL 命令以恢复打印。

public ZebraPrinter printer;
printer = ZebraPrinterFactory.GetInstance(thePrinterConn);

if (printerStatus.isPaused)
  {    
    thePrinterConn.SendAndWaitForResponse(Encoding.UTF8.GetBytes("^XA~PS^XZ"), 1000, 500, "\\r");
  }

0
投票

我使用了David C的解决方案,但它对纸张做了一些不需要的操作,所以我在这个页面找到了:https://www.servopack.de/support/zebra/ZPLII-Prog.pdf命令〜PS,其中完美运作。

ZebraStatus.PAUSED -> {
     connection.sendAndWaitForResponse("~PS".toByteArray(Charsets.UTF_8), 1000, 500, "\\r");
}
© www.soinside.com 2019 - 2024. All rights reserved.