private async void SetSymbologyAttributes_Click(object sender, RoutedEventArgs e) { if ((claimedScanner != null) && (symbologyAttributes != null)) { // populate attributes if (symbologyAttributes.IsCheckDigitValidationSupported) { symbologyAttributes.IsCheckDigitValidationEnabled = EnableCheckDigit.IsChecked.Value; } if (symbologyAttributes.IsCheckDigitTransmissionSupported) { symbologyAttributes.IsCheckDigitTransmissionEnabled = TransmitCheckDigit.IsChecked.Value; } if (symbologyAttributes.IsDecodeLengthSupported) { if (SetDecodeRangeLimits.IsChecked.Value) { symbologyAttributes.DecodeLengthKind = BarcodeSymbologyDecodeLengthKind.Range; symbologyAttributes.DecodeLength1 = (uint)MinimumDecodeLength.Value; symbologyAttributes.DecodeLength2 = (uint)MaximumDecodeLength.Value; } else { symbologyAttributes.DecodeLengthKind = BarcodeSymbologyDecodeLengthKind.AnyLength; } } SymbologyListEntry symbologyListEntry = (SymbologyListEntry)SymbologyListBox.SelectedItem; if (symbologyListEntry != null) { bool attributesSet = false; try { attributesSet = await claimedScanner.SetSymbologyAttributesAsync(symbologyListEntry.Id, symbologyAttributes); } catch (Exception) { // Scanner could not set the attributes. } if (attributesSet) { rootPage.NotifyUser("Attributes set for symbology '" + symbologyListEntry.Name + "'", NotifyType.StatusMessage); } else { rootPage.NotifyUser("Attributes could not be set for symbology '" + symbologyListEntry.Name + "'.", NotifyType.ErrorMessage); } } else { rootPage.NotifyUser("Select a symbology from the list.", NotifyType.ErrorMessage); } } }
/// <summary> /// Event handler for Symbology listbox selection changed. /// Get symbology attributes and populate attribute UI components /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void SymbologySelection_Changed(object sender, SelectionChangedEventArgs args) { if (claimedScanner != null) { SymbologyListEntry symbologyListEntry = (SymbologyListEntry)SymbologyListBox.SelectedItem; if (symbologyListEntry != null) { SetSymbologyAttributesButton.IsEnabled = false; try { symbologyAttributes = await claimedScanner.GetSymbologyAttributesAsync(symbologyListEntry.Id); } catch (Exception) { symbologyAttributes = null; } if (symbologyAttributes != null) { SetSymbologyAttributesButton.IsEnabled = true; // initialize attributes UIs EnableCheckDigit.IsEnabled = symbologyAttributes.IsCheckDigitValidationSupported; EnableCheckDigit.IsChecked = symbologyAttributes.IsCheckDigitValidationEnabled; TransmitCheckDigit.IsEnabled = symbologyAttributes.IsCheckDigitTransmissionSupported; TransmitCheckDigit.IsChecked = symbologyAttributes.IsCheckDigitTransmissionEnabled; SetDecodeRangeLimits.IsEnabled = symbologyAttributes.IsDecodeLengthSupported; bool decodeLengthEnabled = (symbologyAttributes.DecodeLengthKind == BarcodeSymbologyDecodeLengthKind.Range); SetDecodeRangeLimits.IsChecked = decodeLengthEnabled; if (decodeLengthEnabled) { MinimumDecodeLength.Value = Math.Min(symbologyAttributes.DecodeLength1, symbologyAttributes.DecodeLength2); MaximumDecodeLength.Value = Math.Max(symbologyAttributes.DecodeLength1, symbologyAttributes.DecodeLength2); } } else { rootPage.NotifyUser("Symbology attributes are not available.", NotifyType.ErrorMessage); EnableCheckDigit.IsEnabled = false; TransmitCheckDigit.IsEnabled = false; SetDecodeRangeLimits.IsEnabled = false; } } } }