Establishes a serial (RS-232) connection to a printer.

Namespace:  ZSDK_API.Comm
Assembly:  ZSDK_API (in ZSDK_API.dll) Version: 1.1.123.0

Syntax

C#
public class SerialPrinterConnection : ZebraPrinterConnectionA
Visual Basic (Declaration)
Public Class SerialPrinterConnection _
	Inherits ZebraPrinterConnectionA

Examples

Communicate over a serial (RS-232) connection to a printer
CopyC#
using ZSDK_API.Comm;
using System.Text;
using ZSDK_API.ApiException;

public void SendZplOverSerial() {

    try {
        // Instantiate connection for ZPL Serial port on COM1. 
        ZebraPrinterConnection thePrinterConn = new SerialPrinterConnection("COM1", 9600, 8, Parity.None, StopBits.One, Handshake.None);

        // Open the connection - physical connection is established here.
        thePrinterConn.Open();

        // This example prints "This is a ZPL test." near the top of the label.
        String zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";

        // Send the data to printer as a byte array.
        thePrinterConn.Write(Encoding.Default.GetBytes(zplData));

        // Close the connection to release resources.
        thePrinterConn.Close();

    } catch (ZebraPrinterConnectionException e) {

        // Handle communications error here.
        Console.Write(e.StackTrace);
    }
}

public void SendCpclOverSerial() {

    try {
        // Instantiate connection for CPCL Serial port on COM1.
        ZebraPrinterConnection thePrinterConn = new SerialPrinterConnection("COM1", 9600, 8, Parity.None, StopBits.One, Handshake.None);

        // Open the connection - physical connection is established here.
        thePrinterConn.Open();

        // This example prints "This is a CPCL test." near the top of the label.
        String cpclData = "! 0 200 200 210 1\r\n"
                        + "TEXT 4 0 30 40 This is a CPCL test.\r\n"
                        + "FORM\r\n"
                        + "PRINT\r\n";

        // Send the data to printer as a byte array.
        thePrinterConn.Write(Encoding.Default.GetBytes(cpclData));

        // Close the connection to release resources.
        thePrinterConn.Close();

    } catch (ZebraPrinterConnectionException e) {

        // Handle communications error here.
        Console.Write(e.StackTrace);
    }
}
CopyVB.NET
 Imports ZSDK_API.Comm
 Imports System.Text
 Imports ZSDK_API.ApiException

    Public Sub SendZplOverSerial()

    Try
        ' Instantiate connection for ZPL Serial port on COM1. 
        Dim thePrinterConn As ZebraPrinterConnection = New SerialPrinterConnection("COM1", 9600, 8, Parity.None, StopBits.One, Handshake.XOnXOff)

        ' Open the connection - physical connection is established here.
        thePrinterConn.Open()

        ' This example prints "This is a ZPL test." near the top of the label.
        Dim zplData As [String] = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ"

        ' Send the data to printer as a byte array.
        thePrinterConn.Write(Encoding.[Default].GetBytes(zplData))

        ' Close the connection to release resources.


        thePrinterConn.Close()
    Catch e As ZebraPrinterConnectionException

        ' Handle communications error here.
        Console.Write(e.StackTrace)
    End Try
End Sub

Public Sub SendCpclOverSerial()

    Try
        ' Instantiate connection for CPCL Serial port on COM1.
        Dim thePrinterConn As ZebraPrinterConnection = New SerialPrinterConnection("COM1", 9600, 8, Parity.None, StopBits.One, Handshake.None)

        ' Open the connection - physical connection is established here.
        thePrinterConn.Open()

        ' This example prints "This is a CPCL test." near the top of the label.
        Dim cpclData As [String] = "! 0 200 200 210 1" & vbCr & vbLf & "TEXT 4 0 30 40 This is a CPCL test." & vbCr & vbLf & "FORM" & vbCr & vbLf & "PRINT" & vbCr & vbLf

        ' Send the data to printer as a byte array.
        thePrinterConn.Write(Encoding.[Default].GetBytes(cpclData))

        ' Close the connection to release resources.


        thePrinterConn.Close()
    Catch e As ZebraPrinterConnectionException

        ' Handle communications error here.
        Console.Write(e.StackTrace)
    End Try
End Sub

Inheritance Hierarchy

System..::.Object
  ZSDK_API.Comm..::.ZebraPrinterConnectionA
    ZSDK_API.Comm..::.SerialPrinterConnection

See Also