/// <summary>
        ///
        /// head.resolution.in_dpi:203
        /// zpl.label_length:590
        /// odometer.label_dot_length:590
        /// media.width_sense.in_mm:104.1
        /// media.width_sense.in_cm:10.41
        /// media.width_sense.in_dots:832
        /// media.width_sense.in_inches:4.099
        /// sensor.width.cur:209
        /// sensor.width.in_dots:832
        ///
        /// </summary>
        /// <param name="c"></param>
        private static void DisplaySettings(Connection c)
        {
            ZebraPrinter       genericPrinter = ZebraPrinterFactory.GetInstance(c);
            ZebraPrinterLinkOs linkOsPrinter  = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter);

            if (linkOsPrinter != null)
            {
                Console.WriteLine("Available Settings for myDevice");
                HashSet <string> availableSettings = linkOsPrinter.GetAvailableSettings();
                foreach (string setting in availableSettings)
                {
                    Console.WriteLine($"{setting}: Range = ({linkOsPrinter.GetSettingRange(setting)})");
                }

                Console.WriteLine("\nCurrent Setting Values for myDevice");
                Dictionary <string, string> allSettingValues = linkOsPrinter.GetAllSettingValues();
                foreach (string settingName in allSettingValues.Keys)
                {
                    Console.WriteLine($"{settingName}:{allSettingValues[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);
                }

                Console.WriteLine($"\nNew {darknessSettingId} Value = {linkOsPrinter.GetSettingValue(darknessSettingId)}");
            }
        }
Esempio n. 2
0
 //通过指令ID设置打印机(! U1 setvar "input.capture" "run",其中的"input.capture"为指令ID)
 public static bool SetPrintSetting(string settingID, string value)
 {
     if (printerHTTP != null && linkOsPrinter != null)
     {
         linkOsPrinter.SetSetting(settingID, value);
         return(true);
     }
     return(false);
 }
        private bool SaveModifiedSettingsToPrinter()
        {
            bool       result     = false;
            Connection connection = null;

            try {
                connection = connectionSelector.GetConnection();
                connection.Open();

                ZebraPrinter       genericPrinter = ZebraPrinterFactory.GetInstance(connection);
                ZebraPrinterLinkOs printer        = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter);

                if (printer != null)
                {
                    foreach (string key in viewModel.ModifiedSettings.Keys)
                    {
                        if (printer.IsSettingReadOnly(key) == false)
                        {
                            printer.SetSetting(key, viewModel.ModifiedSettings[key]);
                        }
                    }

                    viewModel.ModifiedSettings.Clear();
                    result = true;
                }
                else
                {
                    MessageBoxCreator.ShowError("Connected printer does not support settings", "Connection Error");
                }
            } catch (ConnectionException e) {
                MessageBoxCreator.ShowError(e.Message, "Connection Error");
            } catch (ZebraPrinterLanguageUnknownException e) {
                MessageBoxCreator.ShowError(e.Message, "Connection Error");
            } catch (SettingsException e) {
                MessageBoxCreator.ShowError(e.Message, "Settings Error");
            } catch (Exception e) {
                MessageBoxCreator.ShowError(e.Message, "Save Settings Error");
            } finally {
                try {
                    if (connection != null)
                    {
                        connection.Close();
                    }
                } catch (ConnectionException) { }
            }
            return(result);
        }
        private async void SaveSettingsButton_Clicked(object sender, EventArgs eventArgs)
        {
            SetInputEnabled(false);

            Connection connection            = null;
            bool       linePrintEnabled      = false;
            bool       deviceLanguageUpdated = false;

            try {
                await Task.Factory.StartNew(() => {
                    connection = CreateConnection();
                    connection.Open();

                    ZebraPrinter printer             = ZebraPrinterFactory.GetInstance(connection);
                    ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(printer);

                    if (linkOsPrinter != null)
                    {
                        string originalPrinterLanguage = SGD.GET(DeviceLanguagesSgd, connection);
                        linePrintEnabled = "line_print".Equals(originalPrinterLanguage, StringComparison.OrdinalIgnoreCase);

                        if (linePrintEnabled)
                        {
                            SGD.SET(DeviceLanguagesSgd, "zpl", connection);
                            printer       = ZebraPrinterFactory.GetInstance(connection);
                            linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(printer);
                        }

                        foreach (string key in modifiedSettings.Keys)
                        {
                            if (linkOsPrinter.IsSettingReadOnly(key) == false)
                            {
                                linkOsPrinter.SetSetting(key, modifiedSettings[key]);
                            }
                        }

                        deviceLanguageUpdated = modifiedSettings.ContainsKey(DeviceLanguagesSgd);

                        modifiedSettings.Clear();
                        ClearSettings();
                        UpdateSettingsTable(connection, originalPrinterLanguage);
                    }
                    else
                    {
                        Device.BeginInvokeOnMainThread(async() => {
                            await DisplayAlert("Connection Error", "Connected printer does not support settings", "OK");
                        });
                    }
                });
            } catch (Exception e) {
                await DisplayAlert("Error", e.Message, "OK");
            } finally {
                if (linePrintEnabled && !deviceLanguageUpdated)
                {
                    await Task.Factory.StartNew(() => {
                        try {
                            connection?.Open();
                            SGD.SET(DeviceLanguagesSgd, "line_print", connection);
                        } catch (ConnectionException) { }
                    });
                }

                try {
                    connection?.Close();
                } catch (ConnectionException) { }

                SetInputEnabled(true);
            }
        }