Click or drag to resize

MultichannelBluetoothConnection Class

Establishes a Bluetooth® label and status connection to a printer. (Windows 10 only)
Inheritance Hierarchy
SystemObject
  Zebra.Sdk.CommMultichannelConnection
    Zebra.Sdk.CommMultichannelBluetoothConnection

Namespace:  Zebra.Sdk.Comm
Assembly:  SdkApi_Desktop (in SdkApi_Desktop.dll) Version: 2.14.1989
Syntax
public class MultichannelBluetoothConnection : MultichannelConnection

The MultichannelBluetoothConnection type exposes the following members.

Constructors
  NameDescription
Public methodMultichannelBluetoothConnection(String)
Initializes a new instance of the MultichannelBluetoothConnection class.
Public methodMultichannelBluetoothConnection(String, Int32, Int32)
Initializes a new instance of the MultichannelBluetoothConnection class.
Public methodMultichannelBluetoothConnection(String, Int32, Int32, Int32, Int32)
Initializes a new instance of the MultichannelBluetoothConnection class.
Top
Properties
  NameDescription
Public propertyConnected
Returns true if the connection is open.
(Inherited from MultichannelConnection.)
Public propertyMaxTimeoutForRead
Gets or sets the maximum time, in milliseconds, to wait for any data to be received.
(Inherited from MultichannelConnection.)
Public propertyPrintingChannel
Gets the underlying printing Connection of this MultichannelConnection.
(Inherited from MultichannelConnection.)
Public propertySimpleConnectionName
Return the MAC address as the description.
(Overrides MultichannelConnectionSimpleConnectionName.)
Public propertyStatusChannel
Gets the underlying status StatusConnection of this MultichannelConnection.
(Inherited from MultichannelConnection.)
Public propertyTimeToWaitForMoreData
Gets or sets the maximum time, in milliseconds, to wait in-between reads after the initial read.
(Inherited from MultichannelConnection.)
Top
Methods
  NameDescription
Public methodAddWriteLogStream
Sets the stream to log the write data to.
(Inherited from MultichannelConnection.)
Public methodBytesAvailable
Returns an estimate of the number of bytes that can be read from this connection without blocking.
(Inherited from MultichannelConnection.)
Public methodClose
Closes both the printing and status channels of this MultichannelConnection.
(Overrides MultichannelConnectionClose.)
Public methodClosePrintingChannel
Closes the printing channel of this MultichannelConnection.
(Inherited from MultichannelConnection.)
Public methodCloseStatusChannel
Closes the status channel of this MultichannelConnection.
(Inherited from MultichannelConnection.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetConnectionReestablisher
Returns a ConnectionReestablisher which allows for easy recreation of a connection which may have been closed.
(Inherited from MultichannelConnection.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodOpen
Opens both the printing and status channel of this Multichannel connection.
(Overrides MultichannelConnectionOpen.)
Public methodOpenPrintingChannel
Opens the printing channel of this Multichannel connection.
(Inherited from MultichannelConnection.)
Public methodOpenStatusChannel
Opens the status channel of this Multichannel connection.
(Inherited from MultichannelConnection.)
Public methodRead
Reads all the available data from the connection. This call is non-blocking.
(Inherited from MultichannelConnection.)
Public methodRead(BinaryWriter)
Reads all the available data from the connection.
(Inherited from MultichannelConnection.)
Public methodReadChar
Reads the next byte of data from the connection.
(Inherited from MultichannelConnection.)
Public methodSendAndWaitForResponse(Byte, Int32, Int32, String)
Sends dataToSend and returns the response data.
(Inherited from MultichannelConnection.)
Public methodSendAndWaitForResponse(BinaryWriter, BinaryReader, Int32, Int32, String)
Sends data from sourceStream and writes the response data to destinationStream.
(Inherited from MultichannelConnection.)
Public methodSendAndWaitForValidResponse(Byte, Int32, Int32, ResponseValidator)
Sends dataToSend and returns the response data.
(Inherited from MultichannelConnection.)
Public methodSendAndWaitForValidResponse(BinaryWriter, BinaryReader, Int32, Int32, ResponseValidator)
Sends data from sourceStream and writes the response data to destinationStream.
(Inherited from MultichannelConnection.)
Public methodToString
Returns Bluetooth_MULTI:[MAC Address]:[Friendly Name].
(Overrides ObjectToString.)
Public methodWaitForData
Causes the currently executing thread to sleep until BytesAvailable > 0, or for a maximum of maxTimeout milliseconds.
(Inherited from MultichannelConnection.)
Public methodWrite(Byte)
Writes data.Length bytes from the specified byte array to this output stream.
(Inherited from MultichannelConnection.)
Public methodWrite(BinaryReader)
Writes all available bytes from the data source to this output stream.
(Inherited from MultichannelConnection.)
Public methodWrite(Byte, Int32, Int32)
Writes length bytes from data starting at offset.
(Inherited from MultichannelConnection.)
Top
Remarks
In order to connect to a device with Bluetooth®, the device must be discoverable, authentication must be enabled, and the authentication pin must be set (1-16 alphanumeric characters).
The encryption type and whether or not it is used is determined by the device initiating the connection and not the device being connected to.
Examples
using System;
using System.Text;
using Zebra.Sdk.Comm;

public class BluetoothConnectionExample {

    public static void Main(string[] Args) {
        BluetoothConnectionExample example = new BluetoothConnectionExample();

        string theBtMacAddress = "00:11:BB:DD:55:FF";
        example.SendZplOverBluetooth(theBtMacAddress);
        example.SendCpclOverBluetooth(theBtMacAddress);
    }

    private void SendZplOverBluetooth(string theBtMacAddress) {
        Connection thePrinterConn = null;
        try {
            // Instantiate connection for given Bluetooth® MAC Address.
            thePrinterConn = new MultichannelBluetoothConnection(theBtMacAddress);

            // 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.UTF8.GetBytes(zplData));
        } catch (Exception e) {
            // Handle communications error here.
            Console.WriteLine(e.ToString());
        } finally {
            // Close the connection to release resources.
            if (thePrinterConn != null) {
                thePrinterConn.Close();
            }
        }
    }

    private void SendCpclOverBluetooth(string theBtMacAddress) {
        Connection thePrinterConn = null;
        try {
            // Instantiate connection for given Bluetooth® MAC Address.
            thePrinterConn = new MultichannelBluetoothConnection(theBtMacAddress);

            // 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.UTF8.GetBytes(cpclData));
        } catch (Exception e) {
            // Handle communications error here.
            Console.WriteLine(e.ToString());
        } finally {
            // Close the connection to release resources.
            if (thePrinterConn != null) {
                thePrinterConn.Close();
            }
        }
    }
}
See Also