Zebra KR403 Reading Status Problems

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<string> 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