C# 使用Zebra Link Os SDK打印

C# 使用Zebra Link Os SDK打印,c#,image,printing,sdk,zebra-printers,C#,Image,Printing,Sdk,Zebra Printers,我正在使用此代码将图像打印到zebra打印机 ZebraPrinterConnection connection = new TcpPrinterConnection(ipAddress,port); connection.Open(); ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection); printer.GetGraphicsUtil().PrintImage("imageAddress"); 它工作正常,但

我正在使用此代码将图像打印到zebra打印机

ZebraPrinterConnection connection = new TcpPrinterConnection(ipAddress,port);
connection.Open();
ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection);
printer.GetGraphicsUtil().PrintImage("imageAddress");

它工作正常,但有时打印机不打印,在代码中我没有得到任何错误。是否有办法检查标签是否已实际打印?

请尝试使用以下代码:

id<GraphicsUtil, NSObject> graphicsUtil = [zebraPrinter getGraphicsUtil];
UIImage* image = [UIImage imageNamed:@"ImageName"];

BOOL success = [graphicsUtil printImage:[image CGImage] atX:155 atY:0 withWidth:200 withHeight:80 andIsInsideFormat:NO error:&error];

if(error) {
   NSLog(@"ERROR: %@", error);
}
id graphicsUtil=[zebraPrinter getGraphicsUtil];
UIImage*image=[UIImage ImageName:@“ImageName”];
BOOL success=[graphicsUtil printImage:[image CGImage]atX:155 atY:0,宽:200,高:80,侧格式:无错误:&error];
如果(错误){
NSLog(@“错误:%@”,错误);
}

有几种方法可以做到这一点

第一种方法是在打印期间/之后检查状态,并确认缓冲区中没有字节,打印机上也没有错误:

private boolean postPrintCheckPrinterStatus(Connection connection)
{
    ZebraPrinter printer = ZebraPrinterFactory.getInstance(PrinterLanguage.ZPL, connection);
    PrinterStatus printerStatus = printer.getCurrentStatus();

    // loop while printing until print is complete or there is an error
    while ((printerStatus.numberOfFormatsInReceiveBuffer > 0) && (printerStatus.isReadyToPrint))
    {
        printerStatus = printer.getCurrentStatus();
    }
    if (printerStatus.isReadyToPrint) {
        System.out.println("Ready To Print");
        return true;
     } else if (printerStatus.isPaused) {
        System.out.println("Cannot Print because the printer is paused.");
     } else if (printerStatus.isHeadOpen) {
        System.out.println("Cannot Print because the printer head is open.");
     } else if (printerStatus.isPaperOut) {
        System.out.println("Cannot Print because the paper is out.");
     } else {
        System.out.println("Cannot Print.");
     }
    return false;
}
另一种检查方法是使用打印机里程表确保标签已打印。检查里程表之前和之后:

// Set settings, check status, print, etc.
        if (setPrintLanguage(statusConnection) && checkPrinterStatus(statusConnection))
        {
            int labelCount = Integer.parseInt(SGD.GET("odometer.total_label_count", statusConnection));
            // Send Print Job (1 label)
            String zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";
            printerConnection.write(zplData.getBytes());

            if (postPrintCheckPrinterStatus(statusConnection))
            {
                int newLabelCount = Integer.parseInt(SGD.GET("odometer.total_label_count", statusConnection));
                if (newLabelCount == labelCount + 1)
                {
                    System.out.println("Print Successful.");
                }
            }
            //else reprint?
        }