Zebra KR403 Reading Status Problems

Z Zahi Hajjar 3 years 7 months ago
97 1 0

Hello,

I've implemented a C# application/dll to continuously read the printer's status every ~30 seconds by calling the below sample code. Every time I run the application for quite some time (usually a few hours), it crashes on me and the app becomes unresponsive. The last logged exception from Zebra's SDK would be:

Zebra.Sdk.Comm.ConnectionException: Malformed status response - unable to determine printer status
   at Zebra.Sdk.Printer.Internal.PrinterStatusZpl.GetPrinterStatus()
   at Zebra.Sdk.Printer.Internal.PrinterStatusZpl.UpdateStatus()
   at Zebra.Sdk.Printer.PrinterStatus.GetStatusFromPrinter()
   at Zebra.Sdk.Printer.Internal.ZebraPrinterZpl.GetCurrentStatus()

try{       printerConnection = UsbDiscoverer.GetZebraUsbPrinters().FirstOrDefault().GetConnection();    printerConnection.Open();    printer = ZebraPrinterFactory.GetInstance(printerConnection);    linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(printer);    ZebraPrinterStatus status = (linkOsPrinter != null) ? linkOsPrinter.GetCurrentStatus() : printer.GetCurrentStatus();    string[] printerStatusString = new PrinterStatusMessages(status).GetStatusMessage();    List printerStatusPrefix = GetPrinterStatusPrefix(status);    StringBuilder sb = new StringBuilder();    foreach (string s in printerStatusPrefix)    sb.AppendLine(s);   foreach (string s in printerStatusString)       sb.AppendLine(s);   Console.WriteLine(sb);}catch (ConnectionException e){    Console.WriteLine(e);}catch (ZebraPrinterLanguageUnknownException e){   Console.WriteLine(e);}finally{    if (printerConnection != null)    {        try        {            printerConnection.Close();        }        catch (ConnectionException ce)        {            Console.WriteLine(e);        }    }}
I've tested the app with different Zebra KR403 units we have. I've tested it on different Win10 machines we have. I've also tested it with PC-.NET v.2.13 but all tests would eventually lead to a crash. I've also tried different variations of the sample code:

I've tried opening the connection once and keeping it open (instead of opening it before each status-read and closing it afterwards)
I've tried sending the "~HQES" raw command to read the status such as:

var printer = ZebraPrinterFactory.GetInstance(connection);byte[] buffer = Encoding.ASCII.GetBytes("~HQES");var response = connection.SendAndWaitForResponse(buffer, 5000, 5000, null);var result = Encoding.ASCII.GetString(resp);
The crash dumps created by Windows (after the app crashes) state that a "0x0000005 access violation" occurred which most likely means that it was trying to access some memory that has been cleaned up.

Is this a known issue? Any idea what's causing the crashes?

Here's the environment I'm working with:
Platform: Win10
.Net Framework Version: 4.7
LinkOS Version: PC-.NET 2.14.1989
Printer: Zebra KR403

Thanks

Please Register or Login to post a reply

1 Replies

A ALAIN CLERMONT

Hi,

We are facing an identical issue, C# application crashing after a while performing periodic status reading (10 secs) from a dedicated worker thread.
Platform: Win7 Embedded
.Net Framework Version: 4.7.2
LinkOS Version: 2.15.2634
Printer: Zebra KR403 , using USB connection.

Despite our app unhandled exception handler ( System.AppDomain.UnhandledException ), these crashes are never caught by our handler.
Our application log files have shown repeatedly the last action before the crash was a call to the SDK ZebraPrinter.GetCurrentStatus() .

We have tried several strategies regarding the ZebraPrinter and Connection instances, keep them alive to reuse them or Create-Use-Close.  Regardless, the crashes still occur.

Here an example of the code being called periodically, inspired by the Zebra SDK documentation examples.

public ZebraPrinterStatus ReadPrinterStatus()
{
// find printer
var discoveredUsbPrinters = UsbDiscoverer.GetZebraUsbPrinters();
var discoveredUsbPrinter = discoveredUsbPrinters.FirstOrDefault(p => p.DiscoveryDataMap.ContainsKey("MODEL") && p.DiscoveryDataMap["MODEL"].Contains("KR403"));
if (discoveredUsbPrinter == null)
{
    return null;
}

var printerConnection = discoveredUsbPrinter.GetConnection();
printerConnection.Open();
var zebraPrinter = ZebraPrinterFactory.GetInstance(printerConnection);
// read status
ZebraPrinterStatus status = zebraPrinter.GetCurrentStatus();
// closing
zebraPrinter = null;
printerConnection?.Close();
printerConnection = null;

return status;
}

CONTACT
Can’t find what you’re looking for?