Click or drag to resize

SettingsProvider Interface

Interface that provides access to device related settings.

Namespace:  Zebra.Sdk.Settings
Assembly:  SdkApi_Core (in SdkApi_Core.dll) Version: 2.14.1989
Syntax
public interface SettingsProvider

The SettingsProvider type exposes the following members.

Methods
  NameDescription
Public methodGetAllSettings
Retrieve all settings and their attributes.
Public methodGetAllSettingValues
Retrieves all of the device's setting values.
Public methodGetAvailableSettings
Retrieve all of the setting identifiers for a device.
Public methodGetSettingRange
Retrieves the allowable range for a setting.
Public methodGetSettingsValues
Retrieves the device's setting values for a list of setting IDs.
Public methodGetSettingType
Returns the data type of the setting.
Public methodGetSettingValue
Retrieves the device's setting value for a setting id.
Public methodIsSettingReadOnly
Returns true if the setting is read only.
Public methodIsSettingValid
Returns true if value is valid for the given setting.
Public methodIsSettingWriteOnly
Returns true if the setting is write only.
Public methodProcessSettingsViaMap
Change or retrieve printer settings.
Public methodSetSetting
Sets the setting to the given value.
Public methodSetSettings
Set more than one setting.
Top
Examples
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
}
See Also