Interface SettingsProvider

All Known Subinterfaces:
Device, ZebraPrinterLinkOs
All Known Implementing Classes:
Profile

public interface SettingsProvider
Interface implemented by devices that provide settings.

package test.zebra.sdk.setting.examples;
 
 import java.util.*;
 
 import com.zebra.sdk.comm.*;
 import com.zebra.sdk.device.ZebraIllegalArgumentException;
 import com.zebra.sdk.printer.*;
 import com.zebra.sdk.printer.discovery.*;
 import com.zebra.sdk.settings.SettingsException;
 
 public class SettingsProviderExample {
 
     public static void main(String[] args) {
         try {
             for (DiscoveredUsbPrinter usbPrinter : UsbDiscoverer.getZebraUsbPrinters(new ZebraPrinterFilter())) {
                 Connection c = usbPrinter.getConnection();
                 c.open();
                 if (c.isConnected()) {
                     displaySettings(c);
                 }
                 c.close();
             }
         } catch (SettingsException e) {
             e.printStackTrace();
         } catch (ConnectionException e) {
             e.printStackTrace();
         } catch (ZebraPrinterLanguageUnknownException e) {
             e.printStackTrace();
         } catch (ZebraIllegalArgumentException e) {
             e.printStackTrace();
         }
     }
 
     private static void displaySettings(Connection c) throws ConnectionException, ZebraPrinterLanguageUnknownException, SettingsException, ZebraIllegalArgumentException {
         ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.getLinkOsPrinter(c);
 
         if (linkOsPrinter != null) {
 
             System.out.println("Available Settings for myDevice");
             Set<String> availableSettings = linkOsPrinter.getAvailableSettings();
             for (String setting : availableSettings) {
                 System.out.println(setting + ": Range = (" + linkOsPrinter.getSettingRange(setting) + ")");
             }
 
             System.out.println("\nCurrent Setting Values for myDevice");
             Map<String, String> allSettingValues = linkOsPrinter.getAllSettingValues();
             for (String settingName : allSettingValues.keySet()) {
                 System.out.println(settingName + ":" + allSettingValues.get(settingName));
             }
 
             String darknessSettingId = "print.tone";
             String newDarknessValue = "10.0";
             if (availableSettings.contains(darknessSettingId) &&
                     linkOsPrinter.isSettingValid(darknessSettingId, newDarknessValue) &&
                     linkOsPrinter.isSettingReadOnly(darknessSettingId) == false) {
                 linkOsPrinter.setSetting(darknessSettingId, newDarknessValue);
             }
 
             System.out.println("\nNew " + darknessSettingId + " Value = " + linkOsPrinter.getSettingValue(darknessSettingId));
         }
     }
 }
 
  • Method Details

    • getAvailableSettings

      Set<String> getAvailableSettings() throws SettingsException
      Retrieve all of the setting identifiers for a device. These are the IDs that may be used as keys for retrieving and updating settings for a device.
      Returns:
      Set of identifiers available for a device.
      Throws:
      SettingsException - if the settings could not be loaded
      See Also:
    • getSettingValue

      Retrieves the device's setting value for a setting id.
      Parameters:
      settingId - setting id.
      Returns:
      the setting's value.
      Throws:
      SettingsException - if the setting could not be retrieved.
      ZebraIllegalArgumentException - if there was an error parsing the response from the printer.
      ConnectionException - if there is an error communicating with the printer.
    • getSettingsValues

      Retrieves the device's setting values for a list of setting IDs.
      Parameters:
      listOfSettings - list of setting IDs.
      Returns:
      the settings' values.
      Throws:
      SettingsException - if the settings could not be retrieved.
      ZebraIllegalArgumentException - if there was an error parsing the response from the printer.
      ConnectionException - if there is an error communicating with the printer.
    • getAllSettings

      Map<String,Setting> getAllSettings() throws SettingsException
      Retrieve all settings and their attributes.
      Returns:
      Map of setting IDs and setting attributes contained in the profile
      Throws:
      SettingsException - if the settings could not be retrieved
    • getAllSettingValues

      Map<String,String> getAllSettingValues() throws SettingsException
      Retrieves all of the device's setting values.
      Returns:
      Values of all the settings provided by the device.
      Throws:
      SettingsException - if the settings could not be loaded
      See Also:
    • setSetting

      void setSetting(String settingId, String value) throws SettingsException
      Sets the setting to the given value.
      Parameters:
      settingId - setting id.
      value - The setting's value
      Throws:
      SettingsException - if the setting is read only, does not exist, or if the setting could not be set
    • setSettings

      void setSettings(Map<String,String> settingValuePairs) throws SettingsException
      Set more than one setting.
      Parameters:
      settingValuePairs - Map a setting ID to the new value for the setting.
      Throws:
      SettingsException - if the settings cannot be sent to the device.
    • getSettingRange

      String getSettingRange(String settingId) throws SettingsException
      Retrieves the allowable range for a setting.
      Parameters:
      settingId - setting id.
      Returns:
      the setting's range as a string
      Throws:
      SettingsException - if the setting does not exist
    • isSettingValid

      boolean isSettingValid(String settingId, String value) throws SettingsException
      Returns true if value is valid for the given setting.
      Parameters:
      settingId - setting id.
      value - the setting's value
      Returns:
      true if value is valid for the given setting.
      Throws:
      SettingsException - if the setting does not exist
    • isSettingReadOnly

      boolean isSettingReadOnly(String settingId) throws SettingsException
      Returns true if the setting is read only.
      Parameters:
      settingId - the setting id
      Returns:
      true if the setting is read only
      Throws:
      SettingsException - if the setting does not exist
    • isSettingWriteOnly

      boolean isSettingWriteOnly(String settingId) throws SettingsException
      Returns true if the setting is write only.
      Parameters:
      settingId - the setting id
      Returns:
      true if the setting is write only
      Throws:
      SettingsException - if the setting does not exist
    • getSettingType

      String getSettingType(String settingId) throws SettingsException
      Returns the data type of the setting.
      Parameters:
      settingId - the setting id
      Returns:
      the data type of the setting (e.g. string, bool, enum, etc.)
      Throws:
      SettingsException - if the setting does not exist
    • processSettingsViaMap

      Map<String,String> processSettingsViaMap(Map<String,String> settingValuePairs) throws SettingsException, ConnectionException
      Change or retrieve printer settings.

      Note: Due to the setting verification and validation, additional time and data traffic will be needed for each processSettingsViaMap method call. It is recommended to bundle all settings into one map and one method call to reduce this overhead.

      Parameters:
      settingValuePairs - The settings to change or retrieve
      Returns:
      Mapinvalid input: '<'String, String> results of the setting commands
      Throws:
      SettingsException - if a setting is malformed, or one or more settings could not be set.
      ConnectionException - if there is an error communicating with the printer.