Package com.zebra.sdk.printer
Class SGD
Object
com.zebra.sdk.printer.SGD
A utility class used to wrap and send SGD commands to a connection
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();
}
}
}
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidDO(OutputStream responseData, String setting, String value, Connection printerConnection) Constructs an SGD DO command and sends it to the printer.static voidDO(OutputStream responseData, String setting, String value, Connection printerConnection, int maxTimeoutForRead, int timeToWaitForMoreData) Constructs an SGD DO command and sends it to the printer.static StringDO(String setting, String value, Connection printerConnection) Constructs an SGD DO command and sends it to the printer.static StringDO(String setting, String value, Connection printerConnection, int maxTimeoutForRead, int timeToWaitForMoreData) Constructs an SGD DO command and sends it to the printer.static StringGET(String setting, Connection printerConnection) Constructs an SGD GET command and sends it to the printer.static StringGET(String setting, Connection printerConnection, int maxTimeoutForRead, int timeToWaitForMoreData) Constructs an SGD GET command and sends it to the printer.static voidSET(String setting, int value, Connection printerConnection) Constructs an SGD SET command and sends it to the printer.static voidSET(String setting, String value, Connection printerConnection) Constructs an SGD SET command and sends it to the printer.
-
Method Details
-
SET
public static void SET(String setting, int value, Connection printerConnection) throws ConnectionException Constructs an SGD SET command and sends it to the printer. This method will not wait for a response from the printer. If the SGD SET command returns a response, the caller is responsible for reading the data off of the connection. If a response is expected, consider using the analogousDO(String, String, Connection)command.- Parameters:
setting- the SGD settingvalue- the setting's valueprinterConnection- the connection to send the command to- Throws:
ConnectionException- if an I/O error occurs- See Also:
-
SET
public static void SET(String setting, String value, Connection printerConnection) throws ConnectionException Constructs an SGD SET command and sends it to the printer. This method will not wait for a response from the printer. If the SGD SET command returns a response, the caller is responsible for reading the data off of the connection. If a response is expected, consider using the analogousDO(String, String, Connection)command.- Parameters:
setting- the SGD settingvalue- the setting's valueprinterConnection- the connection to send the command to- Throws:
ConnectionException- if an I/O error occurs- See Also:
-
GET
Constructs an SGD GET command and sends it to the printer. This method waits for a maximum ofConnection.getMaxTimeoutForRead()milliseconds for any data to be received. Once some data has been received it waits until no more data is available withinConnection.getTimeToWaitForMoreData()milliseconds. This method returns the SGD value associated withsettingwithout the surrounding quotes.- Parameters:
setting- the SGD settingprinterConnection- the connection to send the command to- Returns:
- the setting's value
- Throws:
ConnectionException- if an I/O error occurs
-
GET
public static String GET(String setting, Connection printerConnection, int maxTimeoutForRead, int timeToWaitForMoreData) throws ConnectionException Constructs an SGD GET command and sends it to the printer. This method waits for a maximum ofmaxTimeoutForReadmilliseconds for any data to be received. Once some data has been received it waits until no more data is available withintimeToWaitForMoreDatamilliseconds. This method returns the SGD value associated withsettingwithout the surrounding quotes.- Parameters:
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 received- Returns:
- the setting's value
- Throws:
ConnectionException- if an I/O error occurs
-
DO
public static String DO(String setting, String value, Connection printerConnection) throws ConnectionException Constructs an SGD DO command and sends it to the printer. This method waits for a maximum ofConnection.getMaxTimeoutForRead()milliseconds for any data to be received. Once some data has been received it waits until no more data is available withinConnection.getTimeToWaitForMoreData()milliseconds. This method returns the SGD value associated withsettingwithout the surrounding quotes.- Parameters:
setting- the SGD settingvalue- the setting's valueprinterConnection- the connection to send the command to- Returns:
- The response from the SGD DO command
- Throws:
ConnectionException- if an I/O error occurs
-
DO
public static void DO(OutputStream responseData, String setting, String value, Connection printerConnection) throws ConnectionException Constructs an SGD DO command and sends it to the printer. This method waits for a maximum ofConnection.getMaxTimeoutForRead()milliseconds for any data to be received. Once some data has been received it waits until no more data is available withinConnection.getTimeToWaitForMoreData()milliseconds. This method write the SGD value associated withsetting, without the surrounding quotes, toresponseData.- Parameters:
responseData- output stream to receive the response.setting- the SGD settingvalue- the setting's valueprinterConnection- the connection to send the command to- Throws:
ConnectionException- if an I/O error occurs
-
DO
public static String DO(String setting, String value, Connection printerConnection, int maxTimeoutForRead, int timeToWaitForMoreData) throws ConnectionException Constructs an SGD DO command and sends it to the printer. This method waits for a maximum ofmaxTimeoutForReadmilliseconds for any data to be received. Once some data has been received it waits until no more data is available withintimeToWaitForMoreDatamilliseconds. This method returns the SGD value associated withsettingwithout the surrounding quotes.- Parameters:
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 received- Returns:
- The response from the SGD DO command
- Throws:
ConnectionException- if an I/O error occurs
-
DO
public static void DO(OutputStream responseData, String setting, String value, Connection printerConnection, int maxTimeoutForRead, int timeToWaitForMoreData) throws ConnectionException Constructs an SGD DO command and sends it to the printer. This method waits for a maximum ofmaxTimeoutForReadmilliseconds for any data to be received. Once some data has been received it waits until no more data is available withintimeToWaitForMoreDatamilliseconds. This method returns the SGD value associated withsettingwithout the surrounding quotes.- Parameters:
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 received- Throws:
ConnectionException- if an I/O error occurs
-