Unable to open connection with Zebra KR203 using LinkOS/PC.NET

Hello,

I haven't been able to get the Zebra KR203 to work with the LinkOS/PC.NET SDK to read the printer's status. I'm having issues establishing a connection with the printer.

Let me just start by saying that I can successfully discover the printer by calling:

UsbDiscoverer.GetZebraUsbPrinters();

But all the below attempts to connect to the printer failed:

1) Opening a connection with the "DiscoveredPrinter" object throws an exception:

foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters())

{

    var = usbPrinter.GetConnection();

    c.Open(); //throws a "ConnectionException"

    //Exception Details:

    //Zebra.Sdk.Comm.ConnectionException: Unable to connect to USB device '\\?\usb#vid_0a5f&pid_00b3#kr203#{28d78fad-5a12-11d1-ae5b-0000f803a8c2}'

    //at Zebra.Sdk.Comm.UsbConnection.OpenPrinter()

    //at Zebra.Sdk.Comm.UsbConnection.Open()

    //at ZebraPrinter.ZebraOfficialSdk.GetPrinterSettings()

}

2) Querying the printer status through TCP always returns "IsReadyToPrint" even if it's out of paper or cover is open:

var c = new TcpConnection("10.70.225.107", TcpConnection.DEFAULT_ZPL_TCP_PORT);

c.Open();

var printer = ZebraPrinterFactory.GetInstance(c);

var printerStatus = printer.GetCurrentStatus();   //always returns "IsReadyToPrint"

3) Opening a USB_DIRECT connection with the printer throws an exception:

var connection = ConnectionBuilder.Build("\\\\?\\usb#vid_0a5f&pid_00b3#kr230#...");

connection.Open(); //throws the below exception

//Exception Details:

//An unhandled exception of type 'Zebra.Sdk.Comm.ConnectionException' occurred in SdkApi_Desktop.dll

//Additional information: Unable to connect to USB device '\\?\usb#vid_0a5f&pid_00b3#kr203#...'

4) Opening a USB connection with the printer throws an exception:

var connection = ConnectionBuilder.Build(@"USB:Zebra KR203");

connection.Open();     //throws the below exception

//Exception Details:

//An unhandled exception of type 'Zebra.Sdk.Comm.ConnectionException' occurred in SdkApi_Desktop.dll

//Additional information: No installed printer named Zebra KR203

5) Attempting to print sample text using ZPL over TCP doesn't print anything (nor it does throw exceptions):

var connection = new TcpConnection("10.70.225.107", TcpConnection.DEFAULT_ZPL_TCP_PORT);

connection.Open();

string zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";

connection.Write(Encoding.UTF8.GetBytes(zplData)); //does not print any document

Below is how our environment is setup:

- Printer Model: Zebra KR203

- Printer Driver: 1.3.510.109

- LinkOS SDK PC-.NET v.2.13.898

- Printer installed locally (not a network printer)

- .NET Version: 4.7

- OS: Win 7

Any help would be appreciated, thanks.

Anonymous (not verified)
Hi Zahi, The KR203 is not a

Hi Zahi, The KR203 is not a ZPL, CPCL, or even line-print printer.  It uses a print language called KPL that our SDK's do not support.  Most developers using this printer use the KR203 driver.  Here is a decent example of using a driver to print:

The KR403 is supported and should work with your code, but the KR203 is different.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mark Voros
My experience with the KR403

My experience with the KR403 has been similar actually.

Opening a connection directly on a DiscoveredUsbPrinter fails:

foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters()) 

    var connection = usbPrinter.GetConnection(); 

    connection.Open(); // ConnectionException: Unable to connect to USB device '\\?\usb#vid_0a5f&pid_00b1#6&13c1c3f6&0&3#{28d78fad-5a12-11d1-ae5b-0000f803a8c2}'

Opening a connection by passing in the USB address to ConnectionBuilder fails:

var address = discoveredPrinter.Address;

var connection = ConnectionBuilder.Build($"USB_DIRECT:{address}"); 

connection.Open(); // ConnectionException: Unable to connect to USB device '\\?\usb#vid_0a5f&pid_00b1#6&13c1c3f6&0&3#{28d78fad-5a12-11d1-ae5b-0000f803a8c2}'

However, opening a connection by passing in the device name to ConnectionBuilder name does work:

var connection = ConnectionBuilder.Build("USB:ZDesigner KR403"); 

connection.Open(); // Works!

Is this a known issue? It would be nice to be able to do it fully programmatically rather than having to pass in the device name.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Mark,The issue with USB

Hi Mark,

The issue with USB discovery in PC.NET SDK is a known issue that we are working on fixing.  We expect the update for the SDK soon, as in within the month. I can't guarantee it will work for the KR203 as the SDK was not designed for this printer.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Zahi Hajjar
@Robin WestThanks for you

@Robin West

Thanks for you reply. Your sample code is what we use to send print jobs to the KR203. I'm actually more interested in reading the status of the printer. I've tried using the 'winspool.drv' to do that but there's 2 problems we're facing:

1) The status it returns is not always accurate, ex: it sometimes returns that the printer is offline when it's not

2) I can't use it to read the 'low-paper' sensor (I believe that's printer/manufacturer specific and thus not exposed to Windows)

I'd like to query the status of the printer directly using Zebra's native commands (ex: "<ESC><ENQ><1>")... any sample code in .NET to achieve that?

Thank you

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Zahi, I will try to put

Hi Zahi,

I will try to put together some sample code for this.  I'm actually surprised you are able to communicate at all with the KR203.  The SDK was not set up for it and the printer has a unique USB configuration.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Zahi and Mark,To get the

Hi Zahi and Mark,

To get the status on the KR203, it seems the SDK does seem to work at least with the basic Connection class.  I was able to get the status with the following code.  The response is by default in XML:

                Connection connection = // However you get the connection in your code

                byte[] KPL_STRING = { 0x1B + 0x05 + 0x31 };   // <ESC><ENQ><1>

                connection.Open();

                byte[] resp = connection.SendAndWaitForResponse(KPL_STRING, 5000, 5000, null);  //give it a nice long timeout

                string response = Encoding.ASCII.GetString(resp);

                connection.Close();

                Console.WriteLine("Done Checking Status:\r\n{0}\r\n", response);

                string statusCode = SubstringBetween(response, "<code id=\"", "\" group=");

                string status = SubstringBetween(response, "<name>", "</name>");

                Console.WriteLine("Status:{0}", status);

Hope this helps,

Robin

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
OOps - code for

OOps - code for SubstringBetween:

        private string SubstringBetween(string source, string from, string to)

        {

            int pFrom = source.IndexOf(from) + from.Length;

            int pTo = source.IndexOf(to);

            return source.Substring(pFrom, pTo - pFrom);

        }

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Zahi Hajjar
Thanks Robin for the sample

Thanks Robin for the sample code but it doesn't work because I still can't open a connection with the KR203. As you mentioned earlier, it's probably because of it being a KPL and not a ZPL.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Zahi,If you are using the

Hi Zahi,

If you are using the SDK to try and connect, we should have the fix out soon, or you can use the driver based connection.

var connection = ConnectionBuilder.Build("USB:Zebra Technologies KR203");

I did verify it works with the KR203 as long as you are just using the Connection and Discovery classes. The ZebraPrinter based functions will not work.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Zahi Hajjar
Hello Robin,Opening a

Hello Robin,

Opening a connection the way you suggested throws the below exception:

An unhandled exception of type 'Zebra.Sdk.Comm.ConnectionException' occurred in SdkApi_Desktop.dll

Additional information: No installed printer named Zebra KR203

Contrary to what the exception says, the Zebra KR203 drivers (v.1.3.510.109) are actually installed on our machine and the printer is working fine (our printer and its installed drivers are named "Zebra KR203" and not "Zebra Technologies KR203").

Are we missing something?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Zahi,I'm not sure what to

Hi Zahi,

I'm not sure what to tell you.  We expect to have an update soon to fix the known issues with .NET and USB printing.  I was able to print and get status over USB to the KR203 with the updated SDK.  

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Zahi Hajjar
Hello Robin,Do you have a

Hello Robin,

Do you have a timeline of when the updated .NET SDK will be released? And just to confirm, the update will include fixes for the KR203 and not just for the KR403, correct?

Thank you.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments