Establishes a TCP connection to a printer

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

Syntax

C#
public class TcpPrinterConnection : ZebraPrinterStreamConnectionA
Visual Basic (Declaration)
Public Class TcpPrinterConnection _
	Inherits ZebraPrinterStreamConnectionA

Examples

Establishes a TCP connection to a printer
CopyC#
using System;
using ZSDK_API.Comm;
using System.Text;
using ZSDK_API.ApiException;

public void SendZplOverTcp(String theIpAddress) {

    try {
        // Instantiate connection for ZPL TCP port at given address. 
        ZebraPrinterConnection thePrinterConn = new TcpPrinterConnection(theIpAddress, TcpPrinterConnection.DEFAULT_ZPL_TCP_PORT);

        // 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 SendCpclOverTcp(String theIpAddress) {

    try {
        // Instantiate connection for CPCL TCP port at given address.
        ZebraPrinterConnection thePrinterConn = new TcpPrinterConnection(theIpAddress, TcpPrinterConnection.DEFAULT_CPCL_TCP_PORT);

        // 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
Imports System.Threading
Public Sub SendZplOverTcp(ByVal theIpAddress As [String])

  Try
   ' Instantiate connection for ZPL TCP port at given address. 
   Dim thePrinterConn As ZebraPrinterConnection = New TcpPrinterConnection(theIpAddress, TcpPrinterConnection.DEFAULT_ZPL_TCP_PORT)

   ' 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 SendCpclOverTcp(ByVal theIpAddress As [String])

 Try
   ' Instantiate connection for CPCL TCP port at given address.
   Dim thePrinterConn As ZebraPrinterConnection = New TcpPrinterConnection(theIpAddress, TcpPrinterConnection.DEFAULT_CPCL_TCP_PORT)

   ' 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

See Also