Establishes a Bluetooth(R) connection to a printer.

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

Syntax

C#
public class BluetoothPrinterConnection : ZebraPrinterConnection
Visual Basic (Declaration)
Public Class BluetoothPrinterConnection _
	Implements ZebraPrinterConnection

Remarks

The encryption type and whether or not it is used is determined by the smartphone and not the printer. Note: Some Mobile printers (including the MZ series printers) will not communicate over Bluetooth(R) if the printer is not ready to print. On these printers, status information is not available when, for example, the printer is out of paper.

Examples

The following example demonstrates how to establish and send data via a Bluetooth(R) connection.
CopyC#
using System;
using ZSDK_API.Comm;
using System.Text;
using System.Threading;

// This example prints "This is a ZPL test." near the top of the label.
private void SendZplOverBluetooth(String theBtMacAddress) {
    try {
        // Instantiate a connection for given Bluetooth(R) MAC Address.
        ZebraPrinterConnection thePrinterConn = new BluetoothPrinterConnection(theBtMacAddress);

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

        // Defines the ZPL data to be sent.
        String zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";

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

        // Make sure the data got to the printer before closing the connection
        Thread.Sleep(500);

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

    } catch (Exception e) {

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

// This example prints "This is a CPCL test." near the top of the label.
private void SendCpclOverBluetooth(String theBtMacAddress) {
    try {
        // Instantiate a connection for given Bluetooth(R) MAC Address.
        ZebraPrinterConnection thePrinterConn = new BluetoothPrinterConnection(theBtMacAddress);

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

           // Defines the CPCL data to be sent.
        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 the printer as a byte array.
        thePrinterConn.Write(Encoding.Default.GetBytes(cpclData));

        // Make sure the data got to the printer before closing the connection
        Thread.Sleep(500);

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

    } catch (Exception 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
'This example prints "This is a ZPL test." near the top of the label.
Private Sub SendZplOverBluetooth(theBtMacAddress As [String])
        Try
            ' Instantiate a connection for given Bluetooth(R) MAC Address.
              Dim thePrinterConn As ZebraPrinterConnection = New BluetoothPrinterConnection(theBtMacAddress)

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

            ' Defines the ZPL data to be sent.
            Dim zplData As [String] = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ"

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

            ' Make sure the data got to the printer before closing the connection
            Thread.Sleep(500)

            ' Close the connection to release resources.


            thePrinterConn.Close()
        Catch e As Exception

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

 'This example prints "This is a CPCL test." near the top of the label.
    Private Sub SendCpclOverBluetooth(theBtMacAddress As [String])
        Try
            ' Instantiate a connection for given Bluetooth(R) MAC Address.
            Dim thePrinterConn As ZebraPrinterConnection = New BluetoothPrinterConnection(theBtMacAddress)

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

            ' Defines the CPCL data to be sent.
            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))

            'Make sure the data got to the printer before closing the connection
            Thread.Sleep(500)

            ' Close the connection to release resources.


            thePrinterConn.Close()
        Catch e As Exception

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

Inheritance Hierarchy

System..::.Object
  ZSDK_API.Comm..::.BluetoothPrinterConnection

See Also