public interface SettingsProvider
package test.zebra.sdk.setting.examples;
import java.util.Map;
import java.util.Set;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.device.ZebraIllegalArgumentException;
import com.zebra.sdk.printer.ZebraPrinter;
import com.zebra.sdk.printer.ZebraPrinterFactory;
import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;
import com.zebra.sdk.printer.ZebraPrinterLinkOs;
import com.zebra.sdk.printer.discovery.DiscoveredUsbPrinter;
import com.zebra.sdk.printer.discovery.UsbDiscoverer;
import com.zebra.sdk.settings.SettingsException;
public class SettingsProviderExample {
public static void main(String[] args) {
try {
for (DiscoveredUsbPrinter usbPrinter : UsbDiscoverer.getZebraUsbPrinters()) {
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 {
ZebraPrinter genericPrinter = ZebraPrinterFactory.getInstance(c);
ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.createLinkOsPrinter(genericPrinter);
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));
}
}
}
Modifier and Type | Method and Description |
---|---|
Map<String,Setting> |
getAllSettings()
Retrieve all settings and their attributes.
|
Map<String,String> |
getAllSettingValues()
Retrieves all of the device's setting values.
|
Set<String> |
getAvailableSettings()
Retrieve all of the setting identifiers for a device.
|
String |
getSettingRange(String settingId)
Retrieves the allowable range for a setting.
|
Map<String,String> |
getSettingsValues(List<String> listOfSettings)
Retrieves the device's setting values for a list of setting IDs.
|
String |
getSettingType(String settingId)
Returns the data type of the setting.
|
String |
getSettingValue(String settingId)
Retrieves the device's setting value for a setting id.
|
boolean |
isSettingReadOnly(String settingId)
Returns true if the setting is read only.
|
boolean |
isSettingValid(String settingId,
String value)
Returns true if value is valid for the given setting.
|
boolean |
isSettingWriteOnly(String settingId)
Returns true if the setting is write only.
|
Map<String,String> |
processSettingsViaMap(Map<String,String> settingValuePairs)
Change or retrieve printer settings.
|
void |
setSetting(String settingId,
String value)
Sets the setting to the given value.
|
void |
setSettings(Map<String,String> settingValuePairs)
Set more than one setting.
|
Set<String> getAvailableSettings() throws SettingsException
SettingsException
- if the settings could not be loadedgetSettingValue(String)
String getSettingValue(String settingId) throws SettingsException, ConnectionException, ZebraIllegalArgumentException
settingId
- setting id.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.Map<String,String> getSettingsValues(List<String> listOfSettings) throws SettingsException, ConnectionException, ZebraIllegalArgumentException
listOfSettings
- list of setting IDs.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.Map<String,Setting> getAllSettings() throws SettingsException
SettingsException
- if the settings could not be retrievedMap<String,String> getAllSettingValues() throws SettingsException
SettingsException
- if the settings could not be loadedgetAllSettingValues()
void setSetting(String settingId, String value) throws SettingsException
settingId
- setting id.value
- The setting's valueSettingsException
- if the setting is read only, does not exist, or if the setting could not be setvoid setSettings(Map<String,String> settingValuePairs) throws SettingsException
settingValuePairs
- Map a setting ID to the new value for the setting.SettingsException
- If the settings cannot be sent to the device.String getSettingRange(String settingId) throws SettingsException
settingId
- setting id.SettingsException
- if the setting does not existboolean isSettingValid(String settingId, String value) throws SettingsException
settingId
- setting id.value
- the setting's valueSettingsException
- if the setting does not existboolean isSettingReadOnly(String settingId) throws SettingsException
settingId
- the setting idSettingsException
- if the setting does not existboolean isSettingWriteOnly(String settingId) throws SettingsException
settingId
- the setting idSettingsException
- if the setting does not existString getSettingType(String settingId) throws SettingsException
settingId
- the setting idSettingsException
- if the setting does not existMap<String,String> processSettingsViaMap(Map<String,String> settingValuePairs) throws SettingsException, ConnectionException
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.
settingValuePairs
- The settings to change or retrieveSettingsException
- If a setting is malformed, or one or more settings could not be set.ConnectionException
- If there is an error communicating with the printer.
© 2016 ZIH Corp. All Rights Reserved.