Class SGD

Object
com.zebra.sdk.printer.SGD

public class SGD extends Object
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 Type
    Method
    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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 analogous DO(String, String, Connection) command.
      Parameters:
      setting - the SGD setting
      value - the setting's value
      printerConnection - 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 analogous DO(String, String, Connection) command.
      Parameters:
      setting - the SGD setting
      value - the setting's value
      printerConnection - the connection to send the command to
      Throws:
      ConnectionException - if an I/O error occurs
      See Also:
    • GET

      public static String GET(String setting, Connection printerConnection) throws ConnectionException
      Constructs an SGD GET command and sends it to the printer. This method waits for a maximum of 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.
      Parameters:
      setting - the SGD setting
      printerConnection - 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 of 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.
      Parameters:
      setting - the SGD setting
      printerConnection - the connection to send the command to
      maxTimeoutForRead - the maximum time, in milliseconds, to wait for a response from the printer
      timeToWaitForMoreData - 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 of 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.
      Parameters:
      setting - the SGD setting
      value - the setting's value
      printerConnection - 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 of 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.
      Parameters:
      responseData - output stream to receive the response.
      setting - the SGD setting
      value - the setting's value
      printerConnection - 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 of 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.
      Parameters:
      setting - the SGD setting
      value - the setting's value
      printerConnection - the connection to send the command to
      maxTimeoutForRead - the maximum time, in milliseconds, to wait for a response from the printer
      timeToWaitForMoreData - 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 of 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.
      Parameters:
      responseData - output stream to receive the response.
      setting - the SGD setting
      value - the setting's value
      printerConnection - the connection to send the command to
      maxTimeoutForRead - the maximum time, in milliseconds, to wait for a response from the printer
      timeToWaitForMoreData - the maximum time, in milliseconds, to wait in-between reads after the initial data is received
      Throws:
      ConnectionException - if an I/O error occurs