Zebra LinkOS Multiplatform SDK for Xamarin  1.1
Link-OS Portable Class Library Plugin for Xamarin
LinkOS.Plugin.Abstractions.IConnection Interface Reference

A connection to a device. More...

Inheritance diagram for LinkOS.Plugin.Abstractions.IConnection:
LinkOS.Plugin.ConnectionImplementation

Public Member Functions

void Initialize (string connectionString)
 Create a new connection. More...
 
void Open ()
 Opens the connection to a device. More...
 
void Close ()
 Closes this connection and releases any system resources associated with the connection. More...
 
void Write (byte[] data)
 Writes data.length bytes from the specified byte array to this output stream. More...
 
byte [] Read ()
 Reads all the available data from the connection. More...
 
byte [] SendAndWaitForResponse (byte[] dataToSend, int initialResponseTimeout, int responseCompletionTimeout, string terminator=null)
 Sends dataToSend and returns the response data. The software returns immediately if the data received contains terminator. The connection must be open before this method is called. If sendAndWaitForResponse is called when a connection is closed, a ConnectionException is thrown. More...
 
void WaitForData (int maxTimeout)
 Causes the currently executing thread to sleep until bytesAvailable() > 0, or for a maximum of maxTimeout milliseconds. More...
 
int BytesAvailable ()
 Returns an estimate of the number of bytes that can be read from this connection without blocking. More...
 

Properties

bool IsConnected [get]
 Returns true if the connection is open. More...
 
int MaxTimeoutForRead [get, set]
 Gets or sets the maximum time, in milliseconds, to wait for any data to be received. Recommended setting before opening the connection. More...
 
int TimeToWaitForMoreData [get, set]
 Gets or sets the maximum time, in milliseconds, to wait in-between reads after the initial read. Recommended setting before opening the connection. More...
 
int TimeToWaitAfterWrite [get, set]
 Ignored in Android. In iOS Bluetooth -overrides the time the write() method will wait after writing data to the stream.
The default time is 60ms. This method is used to adapt to different Bluetooth radio performance requirements.
If you notice an issues writing bytes, try increasing this time. More...
 
int TimeToWaitAfterRead [get, set]
 Ignored in Android. In iOS Bluetooth -overrides the time the read() method will wait after reading data from the stream.
The default time is 10ms. This method is used to adapt to different Bluetooth radio performance requirements.
If you notice an issues writing bytes, try increasing this time. More...
 

Detailed Description

A connection to a device.

See IPrinterStatus for PreCheckPrinterStatus() and PostPrintCheckStatus() code.

using LinkOS.Plugin;
using System.Text;
public void PrintTCP()
{
IConnection connection = ConnectionBuilder.Current.Build("TCP:192.168.1.100:9100");
Print(connection);
}
public void PrintBluetooth()
{
IConnection connection = ConnectionBuilder.Current.Build("BT:00:22:33:44:55:66");
Print(connection);
}
public void Print(IConnection connection)
{
string zpl = "^XA^POI^MNN^LL90^PW400^FO20,20^A0N,50,50^FDTEST^FS^XZ";
try
{
connection.Open();
if (!CheckPrinterLanguage(connection))
return;
if (!PreCheckPrinterStatus(connection))
return;
connection.Write(Encoding.UTF8.GetBytes(zpl));
PostPrintCheckStatus(connection);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("Exception:" + e.Message);
}
finally
{
if (connection.IsConnected)
connection.Close();
}
}
public bool CheckPrinterLanguage(IConnection connection)
{
// Set the printer command languege
connection.Write(GetBytes("! U1 setvar \"device.languages\\" \"zpl\\"\r\n"));
byte[] response = connection.SendAndWaitForResponse(GetBytes("! U1 getvar \"device.languages\\"\r\n"), 500, 100);
string language = Encoding.UTF8.GetString(response, 0, response.Length);
if (!language.Contains("zpl"))
{
ShowErrorAlert("Printer language not set. Not a ZPL printer.");
return false;
}
return true;
}

Member Function Documentation

◆ BytesAvailable()

int LinkOS.Plugin.Abstractions.IConnection.BytesAvailable ( )

Returns an estimate of the number of bytes that can be read from this connection without blocking.

Returns

Implemented in LinkOS.Plugin.ConnectionImplementation.

◆ Close()

void LinkOS.Plugin.Abstractions.IConnection.Close ( )

Closes this connection and releases any system resources associated with the connection.

Implemented in LinkOS.Plugin.ConnectionImplementation.

◆ Initialize()

void LinkOS.Plugin.Abstractions.IConnection.Initialize ( string  connectionString)

Create a new connection.

Parameters
connectionStringThe format of the input string is: [prefix:] address [: port_number(s)]
Prefix is either TCP_MULTI, TCP, TCP_STATUS, BT_MULTI, BT, or BT_STATUS
The format of address depends on the prefix and OS:
   BT : Android - address is the printer's BT MAC address. iOS - address is the printer's serial number.
   TCP : Android - address is either a DNS name or an IPv4 address. iOS - address is an IPv4 address.
port_number(s) is optional, and only applicable for TCP connections.
iOS Considerations:TCP_MULTI, BT_MULTI, and BT_STATUS are not availible. TCP IPv4 address only, DNS name not supported.
Examples :
TCP:ZBR3054027:9100
TCP_STATUS:10.1.2.3
BT:11:22:33:44:55:66
BT:XXQLJ112000026
10.1.2.3

Implemented in LinkOS.Plugin.ConnectionImplementation.

◆ Open()

void LinkOS.Plugin.Abstractions.IConnection.Open ( )

Opens the connection to a device.

Implemented in LinkOS.Plugin.ConnectionImplementation.

◆ Read()

byte [] LinkOS.Plugin.Abstractions.IConnection.Read ( )

Reads all the available data from the connection.

Returns
received data

Implemented in LinkOS.Plugin.ConnectionImplementation.

◆ SendAndWaitForResponse()

byte [] LinkOS.Plugin.Abstractions.IConnection.SendAndWaitForResponse ( byte []  dataToSend,
int  initialResponseTimeout,
int  responseCompletionTimeout,
string  terminator = null 
)

Sends dataToSend and returns the response data. The software returns immediately if the data received contains terminator. The connection must be open before this method is called. If sendAndWaitForResponse is called when a connection is closed, a ConnectionException is thrown.

Parameters
dataToSendbyte array of data to send
initialResponseTimeoutThe maximum time, in milliseconds, to wait for the initial response to be received. If no data is received during this time, the function returns a zero length array
responseCompletionTimeoutAfter the initial response, if no data is received for this period of time, the input is considered complete and the method returns
terminatorIf the response contains this string, the input is considered complete and the method returns. May be used to avoid waiting for more data when the response is always terminated with a known string. Use null if no terminator is desired.
Returns
received data

Implemented in LinkOS.Plugin.ConnectionImplementation.

◆ WaitForData()

void LinkOS.Plugin.Abstractions.IConnection.WaitForData ( int  maxTimeout)

Causes the currently executing thread to sleep until bytesAvailable() > 0, or for a maximum of maxTimeout milliseconds.

Parameters
maxTimeoutmaximum time in milliseconds to wait for an initial response from the printer.

Implemented in LinkOS.Plugin.ConnectionImplementation.

◆ Write()

void LinkOS.Plugin.Abstractions.IConnection.Write ( byte []  data)

Writes data.length bytes from the specified byte array to this output stream.

Parameters
datathe data.

Implemented in LinkOS.Plugin.ConnectionImplementation.

Property Documentation

◆ IsConnected

bool LinkOS.Plugin.Abstractions.IConnection.IsConnected
get

Returns true if the connection is open.

◆ MaxTimeoutForRead

int LinkOS.Plugin.Abstractions.IConnection.MaxTimeoutForRead
getset

Gets or sets the maximum time, in milliseconds, to wait for any data to be received. Recommended setting before opening the connection.

◆ TimeToWaitAfterRead

int LinkOS.Plugin.Abstractions.IConnection.TimeToWaitAfterRead
getset

Ignored in Android. In iOS Bluetooth -overrides the time the read() method will wait after reading data from the stream.
The default time is 10ms. This method is used to adapt to different Bluetooth radio performance requirements.
If you notice an issues writing bytes, try increasing this time.

◆ TimeToWaitAfterWrite

int LinkOS.Plugin.Abstractions.IConnection.TimeToWaitAfterWrite
getset

Ignored in Android. In iOS Bluetooth -overrides the time the write() method will wait after writing data to the stream.
The default time is 60ms. This method is used to adapt to different Bluetooth radio performance requirements.
If you notice an issues writing bytes, try increasing this time.

◆ TimeToWaitForMoreData

int LinkOS.Plugin.Abstractions.IConnection.TimeToWaitForMoreData
getset

Gets or sets the maximum time, in milliseconds, to wait in-between reads after the initial read. Recommended setting before opening the connection.


The documentation for this interface was generated from the following file: