public static string GetDataLabelString(IBuffer data, uint scanDataType) { // Only certain data types contain encoded text. // To keep this simple, we'll just decode a few of them. if (data == null) { return("No data"); } // This is not an exhaustive list of symbologies that can be converted to a string. if (scanDataType == BarcodeSymbologies.Upca || scanDataType == BarcodeSymbologies.UpcaAdd2 || scanDataType == BarcodeSymbologies.UpcaAdd5 || scanDataType == BarcodeSymbologies.Upce || scanDataType == BarcodeSymbologies.UpceAdd2 || scanDataType == BarcodeSymbologies.UpceAdd5 || scanDataType == BarcodeSymbologies.Ean8 || scanDataType == BarcodeSymbologies.TfStd) { // The UPC, EAN8, and 2 of 5 families encode the digits 0..9 // which are then sent to the app in a UTF8 string (like "01234"). return(CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, data)); } // Some other symbologies (typically 2-D symbologies) contain binary data that // should not be converted to text. return(string.Format("Decoded data unavailable. Raw label data: {0}", DataHelpers.GetDataString(data))); }
/// <summary> /// Scan data was received from the selected scanner. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void ClaimedScanner_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { ScenarioOutputScanDataLabel.Text = DataHelpers.GetDataLabelString(args.Report.ScanDataLabel, args.Report.ScanDataType); ScenarioOutputScanData.Text = DataHelpers.GetDataString(args.Report.ScanData); ScenarioOutputScanDataType.Text = BarcodeSymbologies.GetName(args.Report.ScanDataType); }); }
/// <summary> /// Event handler for the DataReceived event fired when a barcode is scanned by the barcode scanner /// </summary> /// <param name="sender"></param> /// <param name="args"> Contains the BarcodeScannerReport which contains the data obtained in the scan</param> async void claimedScanner_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args) { // need to update the UI data on the dispatcher thread. // update the UI with the data received from the scan. await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { // read the data from the buffer and convert to string. ScenarioOutputScanDataLabel.Text = DataHelpers.GetDataLabelString(args.Report.ScanDataLabel, args.Report.ScanDataType); ScenarioOutputScanData.Text = DataHelpers.GetDataString(args.Report.ScanData); ScenarioOutputScanDataType.Text = BarcodeSymbologies.GetName(args.Report.ScanDataType); }); }
/// <summary> /// This is an event handler for the claimed scanner Instance 2 when it scans and recieves data /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void claimedBarcodeScannerInstance2_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args) { await MainPage.Current.Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, () => { ScanDataType2.Text = BarcodeSymbologies.GetName(args.Report.ScanDataType); DataLabel2.Text = DataHelpers.GetDataLabelString(args.Report.ScanDataLabel, args.Report.ScanDataType); ScanData2.Text = DataHelpers.GetDataString(args.Report.ScanData); rootPage.NotifyUser("Instance 2 received data from the barcode scanner.", NotifyType.StatusMessage); } ); }