Zebra EPL printer status commands

882 views
Skip to first unread message

Wali Akthar

unread,
Jan 15, 2014, 11:07:17 AM1/15/14
to jzebra...@googlegroups.com

Our clients use quite a few mixed zebra label printers to print out address labels and we have a problem whereby the volume of labels that need to be printed causes some problems. When a lot of print jobs are sent to a label printer, it seems to print some, miss a few out then print another batch.

 

Problem:

How to obtain label printer status codes.

Printer details: Zebra GK420d and LP 2844, it has to work for both types so can only use EPL commands.

 

I am trying to obtain whether a job sent to a label printer has successfully completed or not so I can send the next print job.

I have tried various commands such as ^ee, eR, US and finally ~HS commands.

The only command that responds is the ~HS command, so I’m checking the buffer full flag to see if it is ok to send the next print job.

This works well until I get a buffer full response, so my test application will continually send the ~HS command until the buffer full flag is set back to 0, then I continue to send print jobs.

Then suddenly the printer stops responding, the red led appears and the printer fails to print any further jobs!

 

I have a simple test application (C#) as follows:

 

        private void StartReceive(object state)

        {

            var labelPrinter = "xx.xx.xx.xx";

 

            var client = new TcpClient();

            try

            {

                client.SendTimeout = 30000;

                client.ReceiveTimeout = 30000;

 

                client.Connect(labelPrinter, _portNumber);

                var nStream = client.GetStream();

 

                while (true)

                {

                    var sReader = new StreamReader(nStream);

                    var readBuffer = new char[1000];

                    sReader.Read(readBuffer, 0, readBuffer.Length);

                    PrinterStatusResponse(new string(readBuffer));                    

                }

            }

            catch (Exception ex)

            {

                Console.WriteLine("{0} {1} - EXCEPTION ( {2} )", DateTime.Now.ToShortDateString(),

                    DateTime.Now.ToLongTimeString(), ex.Message);

            }

        }

             

       private void PrinterStatusResponse(string data)

        {

            _okToSend = true;

            if (string.IsNullOrEmpty(data)) return;

 

            if (_STATUS_REPORTING_COMMAND == "~HS")

            { 

                var args = data.Split(',');

                Console.WriteLine("{0} {1} - RECEIVED DATA  {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), data.Substring(0, 34));

                // Check buffer full flag (1 = receive buffer full)

                if (args.Length > 6 && args[5] != null)

                {

                    _okToSend = (args[5] == "0");

                    Console.WriteLine("{0} {1} - PrinterStatusResponse okToSend = {2} after checking buffer full flag", DateTime.Now.ToShortDateString(),

                        DateTime.Now.ToLongTimeString(), _okToSend);

 

                    Console.WriteLine("NUMBER OF FORMATS IN BUFFER = {0}", args[4]);                   

                }

                     }

              }

             

       private void SendCommand(object state)

        {

            Console.WriteLine("{0} {1} - SendCommand called", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());

            while (true)

            {

                if (_client != null && _client.Connected && _queue.Count > 0)

                {

                    try

                    {

                        Console.WriteLine("{0} {1} - Messages in queue {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), _queue.Count);

                        // Wait to see if we can send

                        while (!_okToSend)

                        {

                            Thread.Sleep(50);

                            Console.WriteLine("{0} {1} - SendCommand WAITING for okToSend", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());

                        }

 

                        LabelMessage message;

                        Monitor.Enter(_queue);

                        try

                        {

                            message = _queue.Dequeue();                           

                        }

                        finally

                        {

                            Monitor.Exit(_queue);

                        }

 

                        if (message != null)

                        {

                            var sWriter = new StreamWriter(_nStream);

                            sWriter.WriteLine(message.LabelContent.ToString());

                            sWriter.Flush();

                           Console.WriteLine("{0} {1} - SendCommand sent for printing", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());

                        }

                        else Console.WriteLine("{0} {1} - No messages to send", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());

 

                        _counter++;

                        _messageCount++;

                        if (_counter > (_labelsToPrint.Length - 1)) _counter = 0;

 

                        Console.WriteLine("{0} {1} - SendCommand sent for printing MESSAGECOUNT={2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), _messageCount);

                    }

                    catch (Exception ex)

                    {

                        Console.WriteLine("{0} {1} - EXCEPTION ( {2} )", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), ex.Message);

                    }

                }

            }

        }

             

       private void SendStatusCheck(object state)

        {

            if (_client.Connected)

            {

                try

                {

                    Console.WriteLine("{0} {1} - Sending status check", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());

 

                    var sWriter = new StreamWriter(_nStream);

                    sWriter.WriteLine("~HS");

                    sWriter.Flush();

 

                    Console.WriteLine("Sent {0} Command .. Waiting for Printer Reply...", _STATUS_REPORTING_COMMAND);

                }

                catch (Exception ex)

                {

                    Console.WriteLine("{0} {1} - EXCEPTION ( {2} )", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), ex.Message);

                }  

            }

        }

             

       private void ConnectClient()

        {

            var labelPrinter = "xx.xx.xx.xx";

            _client = new TcpClient();

            try

            {

                _client.SendTimeout = 30000;

                _client.ReceiveTimeout = 30000;

                _client.Connect(labelPrinter, _portNumber);

                _nStream = _client.GetStream();

 

                var sWriter = new StreamWriter(_nStream);

                sWriter.WriteLine("~JA");

                sWriter.Flush();

               

                Console.WriteLine("{0} {1} - Connected to Printer {2} ", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), labelPrinter);

                btnSend.Enabled = true;

 

                ThreadPool.QueueUserWorkItem(StartReceive);

                timer1.Start(); // this continually calls SendStatusCheck

                timer2.Start(); // this continually calls SendCommand

            }

            catch(Exception ex)

            {

               Console.WriteLine("{0} {1} - EXCEPTION ( {2} )", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), ex.Message);

            }

        }

             

 

Why does the printer show a red led after a certain number of prints and stops responding? Am I using the correct code (~HS) to check whether I can send another print job?


Please can you provide details on how I could solve these issues or provide contacts which may be able to help.

 

Tres Finocchiaro

unread,
Jan 15, 2014, 11:42:08 AM1/15/14
to jZebra users
we have a problem whereby the volume of labels that need to be printed causes some problems

I would recommend advanced print spooling to accommodate this:  https://code.google.com/p/jzebra/wiki/TutorialWebApplet#Advanced_Print_Spooling

I am trying to obtain whether a job sent to a label printer has successfully completed or not so I can send the next print job.
Since the plugin relies on the print spooler, the bi-directional methods you use are not available.  Some of them may become available future versions, or if you'd like, I can send you a copy of the in-progress 2.0.0 code and you can see if there is a proper place for your two-way socket connection.

-Tres

--
--
To unsubscribe from this group, send email to jzebra-users...@googlegroups.com
 
http://code.google.com/p/jzebra
 
---
You received this message because you are subscribed to the Google Groups "jZebra users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jzebra-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages