Hi,
I'm currently in the process of developing a desktop application in VB.NET to interface with Zebra Printers, specifically the ZT410 model. So far, I've managed to achieve printing functionality using ZXing and System.Drawing.Printing in a Windows environment. However, I'm now exploring an alternative approach, which involves accessing a predefined format stored in the printer's memory using ZebraDesigner for Developers. This format contains various variables that I need to populate programmatically.
My challenge at the moment is incorporating the Zebra.SDK for this purpose, and I've encountered some roadblocks in the process. I've included my code below for reference.
Imports System
Imports Zebra.Sdk.Comm
Imports Zebra.Sdk.Printer
Imports System
Imports Zebra.Sdk.Comm
Imports Zebra.Sdk.Printer
Public Class Form1
Private Sub PrintLabel()
Dim printerFactory As ZebraPrinterFactory = ZebraPrinterFactory.GetInstance()
Dim printer As ZebraPrinter = printerFactory.CreateZebraPrinter("ZDesigner ZT410-300dpi ZPL")
' Abre la conexión con la impresora
printer.Open()
' Carga el formato de etiqueta guardado localmente en la impresora
Dim labelFormat As LabelFormat = printer.LoadStoredFormat("R:TEST.ZPL")
Public Class Form1
Private Sub PrintLabel()
Dim printerFactory As ZebraPrinterFactory = ZebraPrinterFactory.GetInstance()
Dim printer As ZebraPrinter = printerFactory.CreateZebraPrinter("ZDesigner ZT410-300dpi ZPL")
printer.Open()
Dim labelFormat As LabelFormat = printer.LoadStoredFormat("E:FORMAT1.ZPL")
labelFormat.SetVariableValue("BARCODE", "1234567890")
labelFormat.SetVariableValue("LOT", "ABCD")
labelFormat.SetVariableValue("PARTNUMBER", "1234567890")
labelFormat.SetVariableValue("REV", "A")
labelFormat.SetVariableValue("SUPPLIER", "Zebra")
printer.PrintLabel(labelFormat)
End Sub
End Class
I would greatly appreciate it if someone could provide a VB code example demonstrating how to establish communication with the printer and send the required variables to the stored format.
Thank you in advance for any assistance you can offer!
6 Replies
The Zebra.Sdk.Printer module in the Zebra.Printer.SDK library contains a few methods to achieve the objective.
1. FormatUtil.RetrieveFormatFromPrinter() - To retrieve the format stored on the printer.
2. FormatUtil.GetVariableFields() - To get the variables from the format.
3. FormatUtil.PrintStoredFormat() - To print the label by passing the variable values to the stored format
Thank you, Steve, I have followed your reply and used those methods, but I'm stuck trying to retrieve the formats from the printer. Could you please give me a hand looking to my methods?
I used ZebraDesigner for developers and stored the format in the internal flash. As a reference, this was the ZPL generated (which I think should be the same stored in the printer):
Attached is my method to get the variable fields from the printer.
Thank you!!
Eduardo
What is the issue with the RetrieveFormatFromPrinter() API call? Does it return the content of the E:SHIPPING.ZPL template?
I don't see it returns something, or in the worst case I'm not accessing correctly to the return. The printer returns True for printerStatus.isReadyToPrint. For the API call of RetrieveFormatFromPrinter() I have this in console:
The thread 0x691c has exited with code 0 (0x0).
ZDesigner ZT410-300dpi ZPL
\\?\usb#vid_0a5f&pid_00fa#18j152704918#{28d78fad-5a12-11d1-ae5b-0000f803a8c2}
Done discovering local printers.
System.Collections.Generic.List`1[Zebra.Sdk.Printer.Discovery.DiscoveredUsbPrinter]
Ready to print
formatdata: System.Byte[] (RETRIEVE API)
System.Byte[]
Zebra.Sdk.Printer.FieldDescriptionData[]
The thread 0x3634 has exited with code 0 (0x0).
The thread 0x4c4 has exited with code 0 (0x0).
There is a developer demo app that comes with the Link-OS Multiplatform SDK for .NET. It's called DeveloperDemo_Windows under the demos-desktop folder. It has the souce code calling the RetrieveFormatFromPrinter() API. Though the code is in .NET, it provides an example on how the RetrieveFormatFromPrinter() is called. You can actually run the demo in Visual Studio and watch the action. Below is the code snippet.
Hey Steven, I really appreciate your time following this thread, thank you! I adapted the code from the demo you shared and is now working correctly! The printer works, the label is printed with the variable values that I send, just 1 issue to solve; the last variable is a PDF-417 barcode format which will have these values: Variable1#TABVariable2#TABVariable3TABVariable4#TAB
All the variables are stored into a dictionary and then passed to the PrintStoredFormat function, which looks like this:
The issue is with the 5th variable, which is the concatenation of the other variables. The barcode is printed with the correct values, but no tab is included on the printing.
Once again, thank you for your help!