SettingsProvider Interface |
Namespace: Zebra.Sdk.Settings
The SettingsProvider type exposes the following members.
Name | Description | |
---|---|---|
GetAllSettings |
Retrieve all settings and their attributes.
| |
GetAllSettingValues |
Retrieves all of the device's setting values.
| |
GetAvailableSettings |
Retrieve all of the setting identifiers for a device.
| |
GetSettingRange |
Retrieves the allowable range for a setting.
| |
GetSettingsValues |
Retrieves the device's setting values for a list of setting IDs.
| |
GetSettingType |
Returns the data type of the setting.
| |
GetSettingValue |
Retrieves the device's setting value for a setting id.
| |
IsSettingReadOnly |
Returns true if the setting is read only.
| |
IsSettingValid |
Returns true if value is valid for the given setting.
| |
IsSettingWriteOnly |
Returns true if the setting is write only.
| |
ProcessSettingsViaMap |
Change or retrieve printer settings.
| |
SetSetting |
Sets the setting to the given value.
| |
SetSettings |
Set more than one setting.
|
using System; using System.Collections.Generic; using System.Globalization; using Zebra.Sdk.Card.Printer; using Zebra.Sdk.Card.Printer.Discovery; using Zebra.Sdk.Card.Zmotif.Settings; using Zebra.Sdk.Comm; using Zebra.Sdk.Printer.Discovery; public class SettingsProviderExample { public static void Main(string[] args) { Connection connection = null; ZebraCardPrinter zebraCardPrinter = null; try { foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters(new ZebraCardPrinterFilter())) { connection = usbPrinter.GetConnection(); connection.Open(); zebraCardPrinter = ZebraCardPrinterFactory.GetInstance(connection); DisplaySettings(zebraCardPrinter); SetPrinterClock(zebraCardPrinter); CloseQuietly(connection, zebraCardPrinter); } } catch (Exception e) { Console.WriteLine($"Error retrieving settings: {e.Message}"); } finally { CloseQuietly(connection, zebraCardPrinter); } } - #region Settings /// <exception cref="ArgumentException"></exception> /// <exception cref="ConnectionException"></exception> /// <exception cref="System.IO.IOException"></exception> /// <exception cref="Zebra.Sdk.Settings.SettingsException"></exception> /// <exception cref="Zebra.Sdk.Card.Exceptions.ZebraCardException"></exception> private static void DisplaySettings(ZebraCardPrinter zebraCardPrinter) { if (zebraCardPrinter != null) { Console.WriteLine("Available Settings for myDevice:"); HashSet<string> availableSettings = zebraCardPrinter.GetAvailableSettings(); foreach (string setting in availableSettings) { Console.WriteLine($"{setting}: Range = ({zebraCardPrinter.GetSettingRange(setting)})"); } Console.WriteLine("\nCurrent Setting Values for myDevice:"); Dictionary<string, string> allSettingValues = zebraCardPrinter.GetAllSettingValues(); foreach (string settingName in allSettingValues.Keys) { Console.WriteLine($"{settingName}:{allSettingValues[settingName]}"); } } } #endregion Settings - #region SetClock private static void SetPrinterClock(ZebraCardPrinter zebraCardPrinter) { try { if (zebraCardPrinter != null) { HashSet<string> availableSettings = zebraCardPrinter.GetAvailableSettings(); if (availableSettings.Contains(ZebraCardSettingNamesZmotif.CLOCK_MONTH)) { Dictionary<string, string> clockSettings = new Dictionary<string, string> { { ZebraCardSettingNamesZmotif.CLOCK_MONTH, DateTime.Now.Month.ToString() }, { ZebraCardSettingNamesZmotif.CLOCK_DAY, DateTime.Now.Day.ToString() }, { ZebraCardSettingNamesZmotif.CLOCK_YEAR, DateTime.Now.Year.ToString() }, { ZebraCardSettingNamesZmotif.CLOCK_HOUR, DateTime.Now.Hour.ToString() }, { ZebraCardSettingNamesZmotif.CLOCK_MINUTE, DateTime.Now.Minute.ToString() } }; Console.WriteLine($"\nSetting the clock to: {FormatTime(clockSettings)}"); zebraCardPrinter.SetSettings(clockSettings); List<string> clockSettingsNames = new List<string>(new string[] { ZebraCardSettingNamesZmotif.CLOCK_MONTH, ZebraCardSettingNamesZmotif.CLOCK_DAY, ZebraCardSettingNamesZmotif.CLOCK_YEAR, ZebraCardSettingNamesZmotif.CLOCK_HOUR, ZebraCardSettingNamesZmotif.CLOCK_MINUTE }); Dictionary<string, string> clockValues = zebraCardPrinter.GetSettingsValues(clockSettingsNames); DateTime time = DateTime.ParseExact($"{FormatTime(clockValues)}", "M-dd-yyyy HH:mm", CultureInfo.InvariantCulture); Console.WriteLine($"New clock value: {time.ToString("M-dd-yyyy HH:mm")}"); } } } catch (Exception e) { Console.WriteLine($"Error setting the clock: {e.Message}"); } } private static string FormatTime(Dictionary<string, string> clockSettings) { return $"{clockSettings[ZebraCardSettingNamesZmotif.CLOCK_MONTH]}-{clockSettings[ZebraCardSettingNamesZmotif.CLOCK_DAY]}-{clockSettings[ZebraCardSettingNamesZmotif.CLOCK_YEAR]} {clockSettings[ZebraCardSettingNamesZmotif.CLOCK_HOUR]}:{int.Parse(clockSettings[ZebraCardSettingNamesZmotif.CLOCK_MINUTE]).ToString("00")}"; } #endregion SetClock - #region CleanUp private static void CloseQuietly(Connection connection, ZebraCardPrinter zebraCardPrinter) { try { if (zebraCardPrinter != null) { zebraCardPrinter.Destroy(); } if (connection != null) { connection.Close(); } } catch { } } #endregion CleanUp }