How to check if the Zebra printer prints correctly using ZPL and C # (or error detection capability)?

Problem

Is there a simple ZPL code or a way to get an error message from a Zebra printer to determine if these labels were not printed successfully or that there was some kind of error?

Progress

Here is a nice feature that I created to send a printer job to a zebra printer:

public static void SendToPrinter(string zplString, string ipAddress = "127.0.0.1", int port = 1337)
        {
            // Open connection
            TcpClient tcpClient = new TcpClient();
            tcpClient.Connect(ipAddress, port);

            // Write ZPL String to connection
            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(tcpClient.GetStream()))
            {
                writer.Write(zplString);
                writer.Flush();
                writer.Close();
            }
            // Close Connection
            tcpClient.Close();
        }

ZplString has a lot of magic, but it’s mostly ZPL code that we all love. The problem with my approach is that it seems to be more like a one-way printer ticket. A lot of work went into the above, and I hope that we can somehow change it to listen to the answer, if I somehow had the appropriate ZPL code to listen to the answer?

, - , , ?

, , ZPL, # .NET, - . , , " ?". , , , ZPL?

, .

+5
3

~ HS Host Status, . . 227 ZPL.

Zebra Socket Socket.

:

• MEDIA OUT

• RIBBON OUT

• HEAD OPEN

• REWINDER FULL

• HEAD

+6

~ HS , , .

+1

, ~ HS. SDK Link-OS , ~ HS, . "PrinterStatus.isReadyToPrint" , , ~ HQES . , , , , , . , , .

    public static bool CheckStatusAfter(ZebraPrinter printer)
    {
        try
        {
            printerStatus = printer.GetCurrentStatus();
            while ((printerStatus.numberOfFormatsInReceiveBuffer > 0) && (printerStatus.isReadyToPrint))
            {
                Thread.Sleep(500);
                printerStatus = printer.GetCurrentStatus();
            }
        }
        catch (ConnectionException e)
        {
            Console.WriteLine($"Error getting status from printer: {e.Message}");
        }
        if (printerStatus.isReadyToPrint)
        {
            Console.WriteLine($"Print Success");
            return true;
        }
        else
        {
            Console.WriteLine($"Cannot Print because the printer is in error.");
        }
        return false;
    }

: https://github.com/Zebra/devtalks/blob/121317-LinkOS_CSharp/BasicWpfPrintApp

0
source

Source: https://habr.com/ru/post/1659521/


All Articles