public class SGD extends Object
package test.zebra.sdk.printer.examples;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.comm.MultichannelTcpConnection;
import com.zebra.sdk.comm.TcpConnection;
import com.zebra.sdk.printer.SGD;
public class SGDExample {
public static void main(String[] args) {
try {
String ipAddress = "192.168.1.2";
sgdOverTcp(ipAddress);
sgdOverMultiChannelNetworkConnection(ipAddress);
} catch (ConnectionException e) {
e.printStackTrace();
}
}
public static void sgdOverTcp(String ipAddress) throws ConnectionException {
int port = 9100;
Connection printerConnection = new TcpConnection(ipAddress, port);
try {
printerConnection.open();
SGD.SET("print.tone", "15", printerConnection);
String printTone = SGD.GET("print.tone", printerConnection);
System.out.println("SGD print.tone is " + printTone);
} catch (ConnectionException e) {
e.printStackTrace();
} finally {
printerConnection.close();
}
}
private static void sgdOverMultiChannelNetworkConnection(String ipAddress) throws ConnectionException {
// Create and open a connection to a Link-OS printer using both the printing and the status channel
MultichannelTcpConnection printerConnection = new MultichannelTcpConnection(ipAddress, MultichannelTcpConnection.DEFAULT_MULTICHANNEL_PRINTING_PORT, MultichannelTcpConnection.DEFAULT_MULTICHANNEL_STATUS_PORT);
try {
printerConnection.open();
// Get an SGD, using the status channel
String modelName = SGD.GET("device.product_name", printerConnection);
System.out.println("SGD device.product_name is " + modelName);
// Close the connection, and re-open it using only the status channel
printerConnection.close();
printerConnection.openStatusChannel();
// Get an SGD, again using the status channel
String printSpeed = SGD.GET("media.speed", printerConnection);
System.out.println("The print speed is " + printSpeed);
// Close the connection, and re-open it using only the printing channel
printerConnection.close();
printerConnection.openPrintingChannel();
// Get an SGD, using the printing channel
String mirrorFrequency = SGD.GET("ip.mirror.freq", printerConnection);
System.out.println("The mirror frequency is " + mirrorFrequency);
} catch (ConnectionException e) {
e.printStackTrace();
} finally {
printerConnection.close();
}
}
}
Modifier and Type | Method and Description |
---|---|
static void |
DO(OutputStream responseData,
String setting,
String value,
Connection printerConnection)
Constructs an SGD DO command and sends it to the printer.
|
static void |
DO(OutputStream responseData,
String setting,
String value,
Connection printerConnection,
int maxTimeoutForRead,
int timeToWaitForMoreData)
Constructs an SGD DO command and sends it to the printer.
|
static String |
DO(String setting,
String value,
Connection printerConnection)
Constructs an SGD DO command and sends it to the printer.
|
static String |
DO(String setting,
String value,
Connection printerConnection,
int maxTimeoutForRead,
int timeToWaitForMoreData)
Constructs an SGD DO command and sends it to the printer.
|
static String |
GET(String setting,
Connection printerConnection)
Constructs an SGD GET command and sends it to the printer.
|
static String |
GET(String setting,
Connection printerConnection,
int maxTimeoutForRead,
int timeToWaitForMoreData)
Constructs an SGD GET command and sends it to the printer.
|
static void |
SET(String setting,
int value,
Connection printerConnection)
Constructs an SGD SET command and sends it to the printer.
|
static void |
SET(String setting,
String value,
Connection printerConnection)
Constructs an SGD SET command and sends it to the printer.
|
public static void SET(String setting, int value, Connection printerConnection) throws ConnectionException
DO(String, String, Connection)
command.setting
- the SGD settingvalue
- the setting's valueprinterConnection
- the connection to send the command toConnectionException
- if an I/O error occursSET(String, String, Connection)
public static void SET(String setting, String value, Connection printerConnection) throws ConnectionException
DO(String, String, Connection)
command.setting
- the SGD settingvalue
- the setting's valueprinterConnection
- the connection to send the command toConnectionException
- if an I/O error occursSET(String, int, Connection)
public static String GET(String setting, Connection printerConnection) throws ConnectionException
Connection.getMaxTimeoutForRead()
milliseconds for any data to be received. Once some data has been
received it waits until no more data is available within Connection.getTimeToWaitForMoreData()
milliseconds. This method returns the SGD value associated with setting
without the surrounding
quotes.setting
- the SGD settingprinterConnection
- the connection to send the command toConnectionException
- if an I/O error occurspublic static String GET(String setting, Connection printerConnection, int maxTimeoutForRead, int timeToWaitForMoreData) throws ConnectionException
maxTimeoutForRead
milliseconds for any data to be received. Once some data has been received it
waits until no more data is available within timeToWaitForMoreData
milliseconds. This method returns
the SGD value associated with setting
without the surrounding quotes.setting
- the SGD settingprinterConnection
- the connection to send the command tomaxTimeoutForRead
- the maximum time, in milliseconds, to wait for a response from the printertimeToWaitForMoreData
- the maximum time, in milliseconds, to wait in-between reads after the initial data
is receivedConnectionException
- if an I/O error occurspublic static String DO(String setting, String value, Connection printerConnection) throws ConnectionException
Connection.getMaxTimeoutForRead()
milliseconds for any data to be received. Once some data has been
received it waits until no more data is available within Connection.getTimeToWaitForMoreData()
milliseconds. This method returns the SGD value associated with setting
without the surrounding
quotes.setting
- the SGD settingvalue
- the setting's valueprinterConnection
- the connection to send the command toConnectionException
- if an I/O error occurspublic static void DO(OutputStream responseData, String setting, String value, Connection printerConnection) throws ConnectionException
Connection.getMaxTimeoutForRead()
milliseconds for any data to be received. Once some data has been
received it waits until no more data is available within Connection.getTimeToWaitForMoreData()
milliseconds. This method write the SGD value associated with setting
, without the surrounding
quotes, to responseData
.responseData
- output stream to receive the response.setting
- the SGD settingvalue
- the setting's valueprinterConnection
- the connection to send the command toConnectionException
- if an I/O error occurspublic static String DO(String setting, String value, Connection printerConnection, int maxTimeoutForRead, int timeToWaitForMoreData) throws ConnectionException
maxTimeoutForRead
milliseconds for any data to be received. Once some data has been received it
waits until no more data is available within timeToWaitForMoreData
milliseconds. This method returns
the SGD value associated with setting
without the surrounding quotes.setting
- the SGD settingvalue
- the setting's valueprinterConnection
- the connection to send the command tomaxTimeoutForRead
- the maximum time, in milliseconds, to wait for a response from the printertimeToWaitForMoreData
- the maximum time, in milliseconds, to wait in-between reads after the initial data
is receivedConnectionException
- if an I/O error occurspublic static void DO(OutputStream responseData, String setting, String value, Connection printerConnection, int maxTimeoutForRead, int timeToWaitForMoreData) throws ConnectionException
maxTimeoutForRead
milliseconds for any data to be received. Once some data has been received it
waits until no more data is available within timeToWaitForMoreData
milliseconds. This method returns
the SGD value associated with setting
without the surrounding quotes.responseData
- output stream to receive the response.setting
- the SGD settingvalue
- the setting's valueprinterConnection
- the connection to send the command tomaxTimeoutForRead
- the maximum time, in milliseconds, to wait for a response from the printertimeToWaitForMoreData
- the maximum time, in milliseconds, to wait in-between reads after the initial data
is receivedConnectionException
- if an I/O error occurs
© 2015 ZIH Corp. All Rights Reserved.