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.
|
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.
|
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 . |
getConnectionReestablisher, getMaxTimeoutForRead, getTimeToWaitForMoreData, read, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxTimeoutForRead, setTimeToWaitForMoreData, waitForData, write
getConnectionReestablisher, getMaxTimeoutForRead, getTimeToWaitForMoreData, read, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxTimeoutForRead, setTimeToWaitForMoreData, waitForData, write
public 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
Connection
open
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 Connection
open
in class ConnectionA
ConnectionException
- if the connection cannot be established.Connection.open()
public void close() throws ConnectionException
Connection
close
in interface Connection
close
in class ConnectionA
ConnectionException
- if an I/O error occurs.RemoteConnection.close()
public void write(byte[] data) throws ConnectionException
Connection
data.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 Connection
write
in class ConnectionA
data
- the data.ConnectionException
- if an I/O error occurs.Connection.write(byte[])
public void write(byte[] data, int offset, int length) throws ConnectionException
Connection
length
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 Connection
write
in class ConnectionA
data
- 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
Connection
byte[] data = printerConnection.read();
read
in interface Connection
read
in class ConnectionA
ConnectionException
- if an I/O error occurs.Connection.read()
public int readChar() throws ConnectionException
Connection
int singleCharacter = printerConnection.readChar();
readChar
in interface Connection
readChar
in class ConnectionA
ConnectionException
- if an I/O error occurs.ConnectionA.readChar()
public boolean isConnected()
Connection
isConnected
in interface Connection
isConnected
in class ConnectionA
true
if this connection is open.Connection.isConnected()
public int bytesAvailable() throws ConnectionException
Connection
bytesAvailable
in interface Connection
bytesAvailable
in class ConnectionA
ConnectionException
- if an I/O error occurs.Connection.bytesAvailable()
public String getUniqueId()
public int getRmiServerPort()
public String toString()
Connection
toString
in interface Connection
toString
in class Object
Object.toString()
public String getSimpleConnectionName()
Connection.getSimpleConnectionName()
© 2015 ZIH Corp. All Rights Reserved.