Package com.zebra.sdk.settings
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 Summary
Modifier and TypeMethodDescriptionRetrieve all settings and their attributes.Retrieves all of the device's setting values.Retrieve all of the setting identifiers for a device.getSettingRange(String settingId) Retrieves the allowable range for a setting.getSettingsValues(List<String> listOfSettings) Retrieves the device's setting values for a list of setting IDs.getSettingType(String settingId) Returns the data type of the setting.getSettingValue(String settingId) Retrieves the device's setting value for a setting id.booleanisSettingReadOnly(String settingId) Returns true if the setting is read only.booleanisSettingValid(String settingId, String value) Returns true if value is valid for the given setting.booleanisSettingWriteOnly(String settingId) Returns true if the setting is write only.processSettingsViaMap(Map<String, String> settingValuePairs) Change or retrieve printer settings.voidsetSetting(String settingId, String value) Sets the setting to the given value.voidsetSettings(Map<String, String> settingValuePairs) Set more than one setting.
-
Method Details
-
getAvailableSettings
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
String getSettingValue(String settingId) throws SettingsException, ConnectionException, ZebraIllegalArgumentException 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
Map<String,String> getSettingsValues(List<String> listOfSettings) throws SettingsException, ConnectionException, ZebraIllegalArgumentException 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
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
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
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
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
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
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
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
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
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, ConnectionExceptionChange or retrieve printer settings.Note: Due to the setting verification and validation, additional time and data traffic will be needed for each
processSettingsViaMapmethod 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.
-