Problem printing labels on my Zebra ZD420

Hello,

I have developed a test application for printing labels.
Sometimes it prints like a charm, sometimes it doesn't print anything and
just throws exceptions like "Malformed Multipart Form Data" and "Malformed status response - unable to determine printer status".
Can you please help me with these errors?
I am using the latest Zebra.SDK nuget package (2.15.2634), Firmware version is V84.20.22Z.

Here is my sample code:

ZPL Format :
ZPL_String = "^XA" +
"^DFE:FORMAT2.ZPL" +
"^FS" +
"^FT26,243^A0N,56,55^FH\\^FN12\"First Name\"^FS" +
"^FT26,296^A0N,56,55^FH\\^FN11\"Last Name\"^FS" +
"^FT258,73^A0N,39,38^FH\\^FDVisitor^FS" +
"^FO100,100^XG^FN13,1,1^FS" +
"^FO5,17^GB601,379,8^FS" +
"^XZ";

Variables for printing:
Dictionary<int, string> variables = new Dictionary<int, string>
{
{12,"Sinan" },
{11,"Redzheb" },
{13,"Something" }
};

public void Print(Dictionary<int, string> variables)
{
Connection conn = new UsbConnection(_printer.Address); // DiscoveredUsbPrinter

try
{
conn.Open();

ZebraPrinter _genericPrinter = ZebraPrinterFactory.GetInstance(PrinterLanguage.ZPL, conn);
ZebraPrinterLinkOs _linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(_genericPrinter, PrinterLanguage.ZPL);

PrinterStatus printerStatus = _genericPrinter.GetCurrentStatus();

if (CanPrint(printerStatus) == false) return;

if (_linkOsPrinter != null)
{
//I have already successfully stored format on the printer
_linkOsPrinter.PrintStoredFormatWithVarGraphics("E:FORMAT2.ZPL", variables);
}
}
catch (ConnectionException ex)
{
ErrorLog = "***** ERROR " + ex.Message.ToString() + Environment.NewLine;
}
catch (ZebraPrinterLanguageUnknownException ex)
{
ErrorLog = "***** ERROR " + ex.Message.ToString() + Environment.NewLine;
}
finally
{
conn.Close();
}
}

Sinan Redzheb
I already had tried setting

I already had tried setting conn.setMaxTimeoutForRead = 1000 and conn.setTimeToWaitForMoreData = 1000, but the results were the same.

Also LinkOsPrinter creation sometimes fails and returns null (ZebraPrinterLinkOs _linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(_genericPrinter, PrinterLanguage.ZPL)), but using only conn.SendCommand() with the zpl string works fine without exceptions and much more faster than using linkos.PrintStoredFormatWithVarGraphics().

Thank you for your support by the way :)

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Steven Si
These errors might be related

These errors might be related to the USB connection timing. Try the following timeouts on the USB connection before calling conn.Open(). Let us know if this works.

conn.setMaxTimeoutForRead(200); // Adjustable
conn.setTimeToWaitForMoreData(100); // Adjustable

 

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sinan Redzheb
Hi Steven,

Hi Steven,

I've used example2 in this page (https://techdocs.zebra.com/link-os/2-14/pc_net/content/html/c3ded0a4-c27...) for creating the zpl format.
The problem itself is that the above code sometimes throws exceptions and just doesn't print labels ("Malformed Multipart Form Data" and "Malformed status response - unable to determine printer status".).

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Steven Si
For ZPL, each line of ZPL

For ZPL, each line of ZPL should be ended with carriage return and new line, i.e. "\r\n". I'd suggest to add "\r\n" to the end of each ZPL line. What is this line? The ^FN13 should not be used as parameter to ^XG. If you want to print the stored graphics, you can put the name of the image file directly after ^XG. 

"^FO100,100^XG^FN13,1,1^FS" +

 

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments