public class RemoteStatusConnection extends ConnectionStatusA
package test.zebra.sdk.comm.examples;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.printer.SGD;
import com.zebra.sdk.remote.comm.RemoteStatusConnection;
public class RemoteStatusConnectionExample {
// This example assumes Link-OS printers are connected via Web Sockets to a server which is running a Zebra servlet
// instance.
public static void main(String[] args) throws Exception {
new RemoteStatusConnectionExample().sendJSONOverStatusChannel("myPrinterUUID");
}
private void sendJSONOverStatusChannel(String theIpAddress) throws ConnectionException {
// Instantiate a remote status connection to the printer specified by UUID using the default Zebra Web
// services port (11995).
// Note: The printer must be connected to a server which is running a Zebra servlet instance.
Connection thePrinterConn = new RemoteStatusConnection(theIpAddress);
try {
// Open the connection - physical connection is established here.
thePrinterConn.open();
// This sends down JSON to the status channel to retrieve the 'appl.name' setting
String firmwareVersion = SGD.GET("appl.name", thePrinterConn);
System.out.println("The firmware version is : " + firmwareVersion);
} catch (ConnectionException e) {
// Handle communications error here.
e.printStackTrace();
} finally {
// Close the connection to release resources.
thePrinterConn.close();
}
}
}
| Constructor and Description |
|---|
RemoteStatusConnection(String uniqueId)
Initializes a new instance of the
RemoteStatusConnection class using the default Zebra Web services
port (11995).This constructor will use the default timeouts for Connection.read(). |
RemoteStatusConnection(String uniqueId,
int rmiServerPort)
Initializes a new instance of the
RemoteStatusConnection class using the specified
rmiServerPort. |
RemoteStatusConnection(String uniqueId,
int rmiServerPort,
int maxTimeoutForRead,
int timeToWaitForMoreData)
Initializes a new instance of the
RemoteStatusConnection class using the specified
rmiServerPort. |
| Modifier and Type | Method and Description |
|---|---|
int |
bytesAvailable()
Returns an estimate of the number of bytes that can be read from this connection without blocking.
|
void |
close()
Closes this connection and releases any system resources associated with the connection.
|
ConnectionReestablisher |
getConnectionReestablisher(long thresholdTime)
Returns a
ConnectionReestablisher which allows for easy recreation of a connection which may have
been closed. |
int |
getRmiServerPort()
Returns the RMI server port.
|
String |
getSimpleConnectionName()
Return the remote connection unique id of the status port as the description.
|
String |
getUniqueId()
Returns the unique ID of the device.
|
boolean |
isConnected()
Returns true if the connection is open.
|
void |
open()
Opens the connection to a device.
|
byte[] |
read()
Reads all the available data from the connection.
|
byte[] |
read(int maxBytesToRead)
Reads
maxBytesToRead of the available data from the connection. |
int |
readChar()
Reads the next byte of data from the connection, similar to a Java InputStream.
|
String |
toString()
See the classes which implement this method for the format of the description string.
|
void |
write(byte[] data)
Writes
data.length bytes from the specified byte array to this output stream. |
void |
write(byte[] data,
int offset,
int length)
Writes
length bytes from data starting at offset. |
addWriteLogStream, getManufacturer, getMaxDataToWrite, getMaxTimeoutForRead, getTimeToWaitForMoreData, read, read, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxDataToWrite, setMaxTimeoutForRead, setReadTimeout, setTimeToWaitForMoreData, waitForData, writeaddWriteLogStreamgetMaxTimeoutForRead, getTimeToWaitForMoreData, read, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxTimeoutForRead, setTimeToWaitForMoreData, waitForData, writepublic RemoteStatusConnection(String uniqueId)
RemoteStatusConnection class using the default Zebra Web services
port (11995).Connection.read(). The default timeout is a maximum of
5 seconds for any data to be received. If no more data is available after 1 second the read operation is assumed
to be complete.RemoteStatusConnection(String, int, int, int)uniqueId - the UUID of the device.RemoteStatusConnection(String, int)
to specify a non default RMI port.public RemoteStatusConnection(String uniqueId,
int rmiServerPort)
RemoteStatusConnection class using the specified
rmiServerPort. This constructor will use the default timeouts for Connection.read(). The
default timeout is a maximum of 5 seconds for any data to be received. If no more data is available after 1
second the read operation is assumed to be complete.RemoteStatusConnection(String, int, int, int)uniqueId - the UUID of the device.rmiServerPort - the port the RMI server is running on.public RemoteStatusConnection(String uniqueId,
int rmiServerPort,
int maxTimeoutForRead,
int timeToWaitForMoreData)
RemoteStatusConnection class using the specified
rmiServerPort. This constructor will use the specified timeouts for Connection.read(). The
timeout is a maximum of maxTimeoutForRead milliseconds for any data to be received. If no more data
is available after timeToWaitForMoreData milliseconds the read operation is assumed to be complete.uniqueId - the UUID of the device.rmiServerPort - the port the RMI server is running on.maxTimeoutForRead - the maximum time, in milliseconds, to wait for any data to be received.timeToWaitForMoreData - the maximum time, in milliseconds, to wait in-between reads after the initial read.public void open()
throws ConnectionException
Connectionopen method is called when this connection has already been
opened, this call is ignored. When a handle to the connection is no longer needed, you must call Connection.close()
to free up system resources.open in interface Connectionopen in class ConnectionAConnectionException - if the connection cannot be established.Connection.open()public void close()
throws ConnectionException
Connectionclose in interface Connectionclose in class ConnectionAConnectionException - if an I/O error occurs.RemoteConnection.close()public void write(byte[] data)
throws ConnectionException
Connectiondata.length bytes from the specified byte array to this output stream. The connection must be
open before this method is called. If write is called when a connection is closed, a
ConnectionException is thrown.write in interface Connectionwrite in class ConnectionAdata - the data.ConnectionException - if an I/O error occurs.Connection.write(byte[])public void write(byte[] data,
int offset,
int length)
throws ConnectionException
Connectionlength bytes from data starting at offset. The connection must be
open before this method is called. If write is called when a connection is closed, a
ConnectionException is thrown.write in interface Connectionwrite in class ConnectionAdata - the data.offset - the start offset in the data.length - number of bytes to write.ConnectionException - if an I/O error occurs.Connection.write(byte[], int, int)public byte[] read()
throws ConnectionException
Connectionbyte[] data = printerConnection.read();
read in interface Connectionread in class ConnectionAConnectionException - if an I/O error occurs.Connection.read()public byte[] read(int maxBytesToRead)
throws ConnectionException
ConnectionAmaxBytesToRead of the available data from the connection. This call is non-blocking.read in class ConnectionAmaxBytesToRead - number of bytes to readConnectionException - if an I/O error occurs.ConnectionA.read(int)public int readChar()
throws ConnectionException
Connectionint singleCharacter = printerConnection.readChar();
readChar in interface ConnectionreadChar in class ConnectionAConnectionException - if an I/O error occurs.ConnectionA.readChar()public boolean isConnected()
ConnectionisConnected in interface ConnectionisConnected in class ConnectionAtrue if this connection is open.Connection.isConnected()public int bytesAvailable()
throws ConnectionException
ConnectionbytesAvailable in interface ConnectionbytesAvailable in class ConnectionAConnectionException - if an I/O error occurs.Connection.bytesAvailable()public String getUniqueId()
public int getRmiServerPort()
public String toString()
ConnectiontoString in interface ConnectiontoString in class ObjectObject.toString()public String getSimpleConnectionName()
Connection.getSimpleConnectionName()public ConnectionReestablisher getConnectionReestablisher(long thresholdTime) throws ConnectionException
ConnectionConnectionReestablisher which allows for easy recreation of a connection which may have
been closed.
getConnectionReestablisher in interface ConnectiongetConnectionReestablisher in class ConnectionAthresholdTime - how long the Connection reestablisher will wait before attempting to reconnection to the
printerConnectionException - if the ConnectionReestablisher could not be created.ConnectionA.getConnectionReestablisher(long thresholdTime)
© 2017 ZIH Corp. All Rights Reserved.