Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify if Zebra printer successfully printed using ZPL and C# (or be able to detect errors)?

Problem

Is there a simple ZPL code or way to get an error message back from a Zebra printer to determine if the labels did not print successfully or that there was some kind of error?

Progress

Here is a nice function I built to send a printer job to the 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();
        }

There is a lot of magic happening in the zplString, but basically it consists of the ZPL code we all have come to love. The problem in my approach is that it seems this is a rather one way ticket to the printer. A lot of work went into the above and I am hoping we can somehow modify it to listen for a response if I somehow had the appropriate ZPL code to listen to a response?

I simply have not seen any literature or forum discuss how to receive a response back from a zebra printer and determine if it was successful?

Issues

Ideally, I would like a way to understand the printer using ZPL wrapped inside C# and .NET if the printer succeeded or failed in some way. Otherwise, I might have to manually query the user "did it print?". This is not ideal, but I have not yet found anything in my manual that indicated an easy way to detect that there was an error in the print job using ZPL?

Thanks for your patience, assistance, and for reading this question.

like image 939
hlyates Avatar asked Nov 01 '16 13:11

hlyates


People also ask

What is the difference between ZPL and ZPL II?

These are the major differences between ZPL and ZPL II: With ZPL II, all data fields are formatted as they are received. In standard ZPL, the data fields are not processed until after the ^XZ (End Format) command is received. New commands and enhancements to existing commands were added into the ZPL II language.


1 Answers

Use ~HS or Host Status Command, see page 227 of the ZPL Manual.

Zebra provides a C# Socket example.

The printer will give you the status of the following:

• MEDIA OUT

• RIBBON OUT

• HEAD OPEN

• REWINDER FULL

• HEAD OVER-TEMPERATURE

like image 68
Elton Saunders Avatar answered Sep 18 '22 20:09

Elton Saunders