Neodynamic ThermalLabel SDK for .NET
Thermal Printer Communication
Thermal Printers can be connected by Serial Port (RS-232), Parallel Port (Centronics), USB and IP Ethernet network depending on the printer model. Printer communication with ThermalLabel SDK is handled by using PrinterCommunication class. However, that class is not directly used in .NET code but through a PrintJob object or the PrintUtils class.


USB
If your printer is connected by USB, then you will have to install/configure a Windows Driver for the printer which can be the Zebra Universal Driver (ZUD) or the Windows built-in "Microsoft Generic Text Only" printer driver before trying to use it with ThermalLabel SDK. The following code is about how to configure printer communication for a Zebra printer connected by USB through a PrintJob object:

Visual Basic

'Create a PrintJob object
Dim pj As New PrintJob()
'Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
'Set Thermal Printer name
pj.PrinterSettings.PrinterName = "Zebra  TLP2844-Z"


C#

//Create a PrintJob object
PrintJob pj = new PrintJob();
//Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
//Set Thermal Printer name 
pj.PrinterSettings.PrinterName = "Zebra  TLP2844-Z";


Parallel Port (Centronics)
If your printer is connected by Parallel Port (Centronic), then you just need to know the parallel port name to specify it in the PrinterCommunication object. The following code is about how to configure printer communication for a Zebra printer connected by LPT1 Parallel Port through a PrintJob object:



Visual Basic

'Create a PrintJob object
Dim pj As New PrintJob()
'Thermal Printer is connected through Parallel Port
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Parallel
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
'Set Thermal Printer parallel port name
pj.PrinterSettings.ParallelPortName= "LPT1"


C#

//Create a PrintJob object
PrintJob pj = new PrintJob();
//Thermal Printer is connected through Parallel Port
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Parallel;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
//Set Thermal Printer parallel port name 
pj.PrinterSettings.ParallelPortName= "LPT1";




Serial Port (RS-232)
If your printer is connected by Serial Port (RS-232), then you need to know the Thermal Printer serial port settings to specify it in the PrinterCommunication object. Please refer to your Zebra Printer User Manual and look for the Serial Communication parameters. The following code is about how to configure printer communication for a Zebra printer connected by COM1 Serial Port through a PrintJob object:



Visual Basic

'Create a PrintJob object
Dim pj As New PrintJob()
'Thermal Printer is connected through Serial Port
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Serial
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
'Set Thermal Printer serial port settings
pj.PrinterSettings.Communication.SerialPortName = "COM1"
pj.PrinterSettings.Communication.SerialPortBaudRate = 9600
pj.PrinterSettings.Communication.SerialPortDataBits = 8
pj.PrinterSettings.Communication.SerialPortStopBits = System.IO.Ports.StopBits.One
pj.PrinterSettings.Communication.SerialPortParity = System.IO.Ports.Parity.None
pj.PrinterSettings.Communication.SerialPortFlowControl = System.IO.Ports.Handshake.XOnXOff


C#

//Create a PrintJob object
PrintJob pj = new PrintJob();
//Thermal Printer is connected through Serial Port
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Serial;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
//Set Thermal Printer serial port settings 
pj.PrinterSettings.Communication.SerialPortName = "COM1";
pj.PrinterSettings.Communication.SerialPortBaudRate = 9600;
pj.PrinterSettings.Communication.SerialPortDataBits = 8;
pj.PrinterSettings.Communication.SerialPortStopBits = System.IO.Ports.StopBits.One;
pj.PrinterSettings.Communication.SerialPortParity = System.IO.Ports.Parity.None;
pj.PrinterSettings.Communication.SerialPortFlowControl = System.IO.Ports.Handshake.XOnXOff;




IP Ethernet Network
If your printer is connected by an IP Ethernet network, then you just need to know the IP Address as well as the port number for the printer to specify them in the PrinterCommunication object. The following code is about how to configure printer communication for a Zebra printer connected by IP Ethernet through a PrintJob object:



Visual Basic

'Create a PrintJob object
Dim pj As New PrintJob()
'Thermal Printer is connected through IP network
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Network
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
'Set Thermal Printer network info
pj.PrinterSettings.Communication.NetworkIPAddress = System.Net.IPAddress.Parse("127.0.0.1")
pj.PrinterSettings.Communication.NetworkPort = 9100


C#

//Create a PrintJob object
PrintJob pj = new PrintJob();
//Thermal Printer is connected through IP network
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.Network;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
//Set Thermal Printer network info 
pj.PrinterSettings.Communication.NetworkIPAddress = System.Net.IPAddress.Parse("127.0.0.1");
pj.PrinterSettings.Communication.NetworkPort = 9100;