private void Dispose(bool disposing)
 {
     if (disposing)
     {
         this.scanner = null;
     }
 }
Example #2
0
        /// <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)
        {
            // Grab the data from the IBuffers
            string scanData      = String.Empty;
            string scanDataLabel = String.Empty;

            if (args.Report.ScanData != null)
            {
                scanData = GetDataString(args.Report.ScanData);
            }

            if (args.Report.ScanDataLabel != null)
            {
                scanDataLabel = GetDataLabelString(args.Report.ScanDataLabel, args.Report.ScanDataType);
            }

            await MainPage.Current.Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                () =>
            {
                // Symbology
                ScanDataType2.Text = String.Format("{0}", BarcodeSymbologies.GetName(args.Report.ScanDataType));

                // DataLabel
                DataLabel2.Text = String.Format("{0}", scanDataLabel);

                // Data
                ScanData2.Text = String.Format("{0}", scanData);

                rootPage.NotifyUser("Instance 2 received data from the barcode scanner.", NotifyType.StatusMessage);
            }
                );
        }
Example #3
0
        private async void ClaimedScanner_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
        {
            lock (SyncRootProvider.SyncRoot)
            {
                if (IsRunning)
                {
                    return;
                }
                IsRunning = true;
            }

            string BarcodeType  = BarcodeSymbologies.GetName(args.Report.ScanDataType).ToUpper();
            string BarcodeLabel = GetDataLabel(args);

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                ContentDialog dialog = new ContentDialog
                {
                    Content         = BarcodeLabel,
                    Title           = BarcodeType + "标签内容",
                    CloseButtonText = "确定",
                    Background      = Application.Current.Resources["DialogAcrylicBrush"] as Brush
                };
                await dialog.ShowAsync();

                BarcodeHistory.Add(new BarcodeItem(BarcodeType, BarcodeLabel));

                IsRunning = false;
            });
        }
        public async Task StartAsync()
        {
            if (this.scanner == null)
            {
                var collection = await DeviceInformation.FindAllAsync(PosBarcodeScanner.GetDeviceSelector());

                if (collection != null && collection.Count > 0)
                {
                    var identity = collection.First().Id;
                    var device   = await PosBarcodeScanner.FromIdAsync(identity);

                    if (device != null)
                    {
                        this.scanner = await device.ClaimScannerAsync();

                        if (this.scanner != null)
                        {
                            this.scanner.IsDecodeDataEnabled     = true;
                            this.scanner.ReleaseDeviceRequested += WhenScannerReleaseDeviceRequested;
                            this.scanner.DataReceived           += WhenScannerDataReceived;
                            await this.scanner.EnableAsync();
                        }
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// This method is called upon when a claim request is made on instance 2. If a retain request was placed on the device it rejects the new claim.
        /// </summary>
        /// <param name="instance"></param>
        /// <returns></returns>
        async void claimedBarcodeScannerInstance2_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
        {
            await MainPage.Current.Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                () =>
            {
                //check if the instance wants to retain the device
                if (Retain2.IsChecked == true)
                {
                    try
                    {
                        //Retain the device
                        claimedBarcodeScannerInstance2.RetainDevice();
                    }
                    catch (Exception exception)
                    {
                        rootPage.NotifyUser("Retain instance 1 failed: " + exception.Message, NotifyType.ErrorMessage);
                    }
                }
                //Release the device
                else
                {
                    claimedBarcodeScannerInstance2.Dispose();
                    claimedBarcodeScannerInstance2 = null;

                    if (barcodeScannerInstance2 != null)
                    {
                        barcodeScannerInstance2.Dispose();
                        barcodeScannerInstance2 = null;
                    }
                }
            }
                );
        }
        async public void Reclaim(string options)
        {
            PluginResult result;

            if (barcodeScanner != null)
            {
                claimedBarcodeScanner = await barcodeScanner.ClaimScannerAsync();

                if (claimedBarcodeScanner != null)
                {
                    await claimedBarcodeScanner.EnableAsync();
                    claimedBarcodeScanner.DataReceived += DataReceived;

                    result = new PluginResult(PluginResult.Status.NO_RESULT);
                    result.KeepCallback = true;
                }
                else
                {
                    result = new PluginResult(PluginResult.Status.ERROR, "Barcode Scanner could not get claimed");
                }
            }
            else
            {
                result = new PluginResult(PluginResult.Status.ERROR, "Barcode Scanner Object not exists");
            }

            DispatchCommandResult(result);
        }
        void DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
        {
            PluginResult result = new PluginResult(PluginResult.Status.OK, this.GetDataString(args.Report.ScanData));

            result.KeepCallback = true;
            DispatchCommandResult(result);
        }
Example #8
0
        /// <summary>
        /// Event handler for the Release Device Requested event fired when barcode scanner receives Claim request from another application
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"> Contains the ClamiedBarcodeScanner that is sending this request</param>
        void claimedScanner_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
        {
            // always retain the device
            e.RetainDevice();

            rootPage.NotifyUser("Event ReleaseDeviceRequested received. Retaining the barcode scanner.", NotifyType.StatusMessage);
        }
        public async void GetScanningDevice()
        {
            _barcodeScanner = await BarcodeScanner.GetDefaultAsync();

            if (_barcodeScanner != null)
            {
                _claimedBarcodeScanner = await _barcodeScanner.ClaimScannerAsync();
            }
            else
            {
                ErrorMsg = "scanning device not found";
                return;
            }
            if (_claimedBarcodeScanner != null)
            {
                _claimedBarcodeScanner.DataReceived       += ClaimedBarcode_DataRecieved;
                _claimedBarcodeScanner.IsDecodeDataEnabled = true;
                await _claimedBarcodeScanner.EnableAsync();
            }
            else
            {
                ErrorMsg = "scanning device cant be claimed ";
                return;
            }
        }
        async public void Reclaim(string options)
        {
            PluginResult result;

            if (barcodeScanner != null)
            {
                claimedBarcodeScanner = await barcodeScanner.ClaimScannerAsync();

                if (claimedBarcodeScanner != null)
                {
                    await claimedBarcodeScanner.EnableAsync();

                    claimedBarcodeScanner.DataReceived += DataReceived;

                    result = new PluginResult(PluginResult.Status.NO_RESULT);
                    result.KeepCallback = true;
                }
                else
                {
                    result = new PluginResult(PluginResult.Status.ERROR, "Barcode Scanner could not get claimed");
                }
            }
            else
            {
                result = new PluginResult(PluginResult.Status.ERROR, "Barcode Scanner Object not exists");
            }

            DispatchCommandResult(result);
        }
Example #11
0
        async System.Threading.Tasks.Task resetScanner()
        {
            if (_ClaimedBarcodeScanner != null)
            {
                if (_autoScan)
                {
                    await _ClaimedBarcodeScanner.StopSoftwareTriggerAsync();
                }
                _ClaimedBarcodeScanner.DataReceived           -= _ClaimedBarcodeScanner_DataReceived;
                _ClaimedBarcodeScanner.ReleaseDeviceRequested -= _ClaimedBarcodeScanner_ReleaseDeviceRequested;
                _ClaimedBarcodeScanner.Dispose();
                _ClaimedBarcodeScanner = null;
            }
            _BarcodeScanner = null;
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                //UI code here
                textBox_Scan.Background = new SolidColorBrush(Windows.UI.Colors.White);
                textBox_Scan.Text       = "";
                textBox_Time.Text       = "";
                //play sound at end of Release
            });

            App.mySoundEffects.Play(AppSoundEffects.SoundEfxEnum.ComputerError);
        }
        /// <summary>
        /// This is an event handler for the claimed scanner Instance 1 when it scans and recieves data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void claimedBarcodeScannerInstance1_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
        {
            // Grab the data from the IBuffers
            string scanData      = String.Empty;
            string scanDataLabel = String.Empty;

            if (args.Report.ScanData != null)
            {
                scanData = GetDataString(args.Report.ScanData);
            }

            if (args.Report.ScanDataLabel != null)
            {
                scanDataLabel = GetDataLabelString(args.Report.ScanDataLabel, args.Report.ScanDataType);
            }

            await MainPage.Current.Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                () =>
            {
                ScanDataType1.Text = String.Format("{0}", BarcodeSymbologies.GetName(args.Report.ScanDataType));

                // DataLabel
                DataLabel1.Text = String.Format("{0}", scanDataLabel);

                // Data
                ScanData1.Text = String.Format("{0}", scanData);

                UpdateOutput("Instance1 Data Received from Barcode Scanner.");
            }
                );
        }
        //</SnippetSetupBarcodeScanner>


        /// <summary>
        /// Event handler for the Release Device Requested event fired when barcode scanner receives Claim request from another application
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"> Contains the ClaimedBarcodeScanner that is sending this request</param>
        //<SnippetReleaseDeviceRequested>
        async void claimedScanner_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                e.RetainDevice();
            });
        }
        /// <summary>
        /// Event Handler for Start Scan Button Click.
        /// Sets up the barcode scanner to be ready to receive the data events from the scan.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ScenarioStartScanButton_Click(object sender, RoutedEventArgs e)
        {
            ScenarioStartScanButton.IsEnabled = false;

            rootPage.NotifyUser("Acquiring barcode scanner object.", NotifyType.StatusMessage);

            // create the barcode scanner.
            scanner = await DeviceHelpers.GetFirstBarcodeScannerAsync();

            if (scanner != null)
            {
                // after successful creation, list supported symbologies
                IReadOnlyList <uint> supportedSymbologies = await scanner.GetSupportedSymbologiesAsync();

                foreach (uint symbology in supportedSymbologies)
                {
                    listOfSymbologies.Add(new SymbologyListEntry(symbology));
                }

                // Claim the scanner for exclusive use and enable it so raises DataReceived events.
                claimedScanner = await scanner.ClaimScannerAsync();

                if (claimedScanner != null)
                {
                    // It is always a good idea to have a release device requested event handler.
                    // If this event is not handled, then another app can claim ownership of the barcode scanner.
                    claimedScanner.ReleaseDeviceRequested += claimedScanner_ReleaseDeviceRequested;

                    // after successfully claiming, attach the datareceived event handler.
                    claimedScanner.DataReceived += claimedScanner_DataReceived;

                    // Ask the platform to decode the data by default. When this is set, the platform
                    // will decode the raw data from the barcode scanner and include in the
                    // BarcodeScannerReport.ScanDataLabel and ScanDataType in the DataReceived event.
                    claimedScanner.IsDecodeDataEnabled = true;

                    // Enable the scanner so it raises DataReceived events.
                    // Do this after adding the DataReceived event handler.
                    await claimedScanner.EnableAsync();

                    // reset the button state
                    ScenarioEndScanButton.IsEnabled      = true;
                    SetActiveSymbologiesButton.IsEnabled = true;

                    rootPage.NotifyUser("Ready to scan. Device ID: " + claimedScanner.DeviceId, NotifyType.StatusMessage);
                }
                else
                {
                    scanner.Dispose();
                    scanner = null;
                    ScenarioStartScanButton.IsEnabled = true;
                    rootPage.NotifyUser("Claim barcode scanner failed.", NotifyType.ErrorMessage);
                }
            }
            else
            {
                ScenarioStartScanButton.IsEnabled = true;
                rootPage.NotifyUser("Barcode scanner not found. Please connect a barcode scanner.", NotifyType.ErrorMessage);
            }
        }
 /// <summary>
 /// This method is called upon when a claim request is made on instance 2. If a retain request was placed on the device it rejects the new claim.
 /// </summary>
 /// <param name="instance"></param>
 /// <returns></returns>
 async void claimedBarcodeScannerInstance2_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
 {
     await MainPage.Current.Dispatcher.RunAsync(
         Windows.UI.Core.CoreDispatcherPriority.Normal,
         () =>
     {
         UpdateOutput(String.Format("\nReleaseDeviceRequested ({0})", claimedBarcodeScannerInstance2.DeviceId));
         //check if the instance wants to retain the device
         if (Retain2.IsChecked == true)
         {
             try
             {
                 //Retain the device
                 claimedBarcodeScannerInstance2.RetainDevice();
                 UpdateOutput(String.Format("\t(Scanner Retained)"));
             }
             catch (Exception exception)
             {
                 UpdateOutput(String.Format("\t(retain failed) ({0})", exception.ToString()));
             }
         }
         //Release the device
         else
         {
             claimedBarcodeScannerInstance2.Dispose();
             claimedBarcodeScannerInstance2 = null;
             UpdateOutput("Scanner Released.");
         }
     }
         );
 }
Example #16
0
        /// <summary>
        /// This is the click handler for the 'ScenarioEndScanningInstance1' button.
        /// Initiates the disposal of scanner instance 1.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///
        private void ButtonEndScanningInstance1_Click(object sender, RoutedEventArgs e)
        {
            if (claimedBarcodeScannerInstance1 != null)
            {
                //remove the event handlers
                claimedBarcodeScannerInstance1.DataReceived           -= claimedBarcodeScannerInstance1_DataReceived;
                claimedBarcodeScannerInstance1.ReleaseDeviceRequested -= claimedBarcodeScannerInstance1_ReleaseDeviceRequested;

                //dispose the instance
                claimedBarcodeScannerInstance1.Dispose();
                claimedBarcodeScannerInstance1 = null;
            }

            if (barcodeScannerInstance1 != null)
            {
                barcodeScannerInstance1.Dispose();
                barcodeScannerInstance1 = null;
            }

            //reset the UI

            ResetUI();

            rootPage.NotifyUser("Click a start scanning button to begin.", NotifyType.StatusMessage);
        }
        /// <summary>
        /// Reset the Scenario state
        /// </summary>
        private void ResetTheScenarioState()
        {
            if (claimedScanner != null)
            {
                // Detach the event handlers
                claimedScanner.DataReceived           -= claimedScanner_DataReceived;
                claimedScanner.ReleaseDeviceRequested -= claimedScanner_ReleaseDeviceRequested;
                // Release the Barcode Scanner and set to null
                claimedScanner.Dispose();
                claimedScanner = null;
            }

            if (scanner != null)
            {
                scanner.Dispose();
                scanner = null;
            }

            // Reset the strings in the UI
            rootPage.NotifyUser("Click the start scanning button to begin.", NotifyType.StatusMessage);
            this.ScenarioOutputScanData.Text      = "No data";
            this.ScenarioOutputScanDataLabel.Text = "No data";
            this.ScenarioOutputScanDataType.Text  = "No data";

            // reset the button state
            SetActiveSymbologiesButton.IsEnabled = false;
            ScenarioEndScanButton.IsEnabled      = false;
            ScenarioStartScanButton.IsEnabled    = true;

            // reset symbology list
            listOfSymbologies.Clear();
        }
Example #18
0
        /// <summary>
        /// Reset the Scenario state
        /// </summary>
        private void ResetTheScenarioState()
        {
            if (claimedBarcodeScannerInstance1 != null)
            {
                claimedBarcodeScannerInstance1.Dispose();
                claimedBarcodeScannerInstance1 = null;
            }

            if (barcodeScannerInstance1 != null)
            {
                barcodeScannerInstance1.Dispose();
                barcodeScannerInstance1 = null;
            }

            if (claimedBarcodeScannerInstance2 != null)
            {
                claimedBarcodeScannerInstance2.Dispose();
                claimedBarcodeScannerInstance2 = null;
            }

            if (barcodeScannerInstance2 != null)
            {
                barcodeScannerInstance2.Dispose();
                barcodeScannerInstance2 = null;
            }

            ResetUI();
        }
Example #19
0
        private async void OnBarcodeDetected(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
        {
            string regId = "<undefined>";
            string ek    = "<undefined>";

            // Parse the data
            string  decodedText = BarcodeDecoder.DecodeLabel(args.Report.ScanDataLabel);
            JObject jsonData    = (JObject)JsonConvert.DeserializeObject(decodedText);

            if (jsonData.ContainsKey(JsonRegId))
            {
                regId = (string)jsonData[JsonRegId];
            }

            if (jsonData.ContainsKey(JsonEK))
            {
                ek = (string)jsonData[JsonEK];
            }

            // Update the UI
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                RegIdBox.Text = regId;
                EKBox.Text    = ek;
            });
        }
        /// <summary>
        /// Reset the Scenario state
        /// </summary>
        private async void ResetTheScenarioState()
        {
            if (claimedScanner != null)
            {
                // Detach the event handlers
                claimedScanner.DataReceived           -= claimedScanner_DataReceived;
                claimedScanner.ReleaseDeviceRequested -= claimedScanner_ReleaseDeviceRequested;
                // Release the Barcode Scanner and set to null
                claimedScanner.Dispose();
                claimedScanner = null;
            }

            scanner = null;

            await CleanupCameraAsync();

            // Reset the strings in the UI
            rootPage.NotifyUser("Click the start scanning button to begin.", NotifyType.StatusMessage);
            this.ScenarioOutputScanData.Text      = "No data";
            this.ScenarioOutputScanDataLabel.Text = "No data";
            this.ScenarioOutputScanDataType.Text  = "No data";

            // reset the button state
            ScenarioEndScanButton.IsEnabled        = false;
            ScenarioStartSWTriggerButton.IsEnabled = false;
            ScenarioStopSWTriggerButton.IsEnabled  = false;
            ScenarioStartScanButton.IsEnabled      = true;
        }
Example #21
0
        /// <summary>
        /// Close the scanners and stop the preview.
        /// </summary>
        private async Task CloseScannerResourcesAsync()
        {
            claimedScanner?.Dispose();
            claimedScanner = null;

            selectedScanner?.Dispose();
            selectedScanner = null;

            SoftwareTriggerStarted = false;
            RaisePropertyChanged(nameof(SoftwareTriggerStarted));

            if (IsPreviewing)
            {
                if (mediaCapture != null)
                {
                    await mediaCapture.StopPreviewAsync();

                    mediaCapture.Dispose();
                    mediaCapture = null;
                }

                // Allow the display to go to sleep.
                displayRequest.RequestRelease();

                IsPreviewing = false;
                RaisePropertyChanged(nameof(IsPreviewing));
            }
        }
Example #22
0
        /// <summary>
        /// Reset the Scenario state
        /// </summary>
        private void ResetTheScenarioState()
        {
            if (claimedScanner != null)
            {
                // Detach the event handlers
                claimedScanner.DataReceived           -= claimedScanner_DataReceived;
                claimedScanner.ReleaseDeviceRequested -= claimedScanner_ReleaseDeviceRequested;
                // Release the Barcode Scanner and set to null
                claimedScanner.Dispose();
                claimedScanner = null;
            }

            if (scanner != null)
            {
                scanner.Dispose();
                scanner = null;
            }

            // Reset the UI if we are still the current page.
            if (Frame.Content == this)
            {
                rootPage.NotifyUser("Click the start scanning button to begin.", NotifyType.StatusMessage);
                this.ScenarioOutputScanData.Text      = "No data";
                this.ScenarioOutputScanDataLabel.Text = "No data";
                this.ScenarioOutputScanDataType.Text  = "No data";

                // reset the button state
                ScenarioEndScanButton.IsEnabled   = false;
                ScenarioStartScanButton.IsEnabled = true;
            }
        }
        /// <summary>
        /// Event Handler for Start Scan Button Click.
        /// Sets up the barcode scanner to be ready to receive the data events from the scan.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ScenarioStartScanButton_Click(object sender, RoutedEventArgs e)
        {
            ScenarioStartScanButton.IsEnabled = false;

            rootPage.NotifyUser("Acquiring barcode scanner object.", NotifyType.StatusMessage);

            // create the barcode scanner.
            scanner = await DeviceHelpers.GetFirstBarcodeScannerAsync();

            if (scanner != null)
            {
                // claim the scanner for exclusive use and enable it so that data received events are received.
                claimedScanner = await scanner.ClaimScannerAsync();

                if (claimedScanner != null)
                {
                    // It is always a good idea to have a release device requested event handler. If this event is not handled, there are chances of another app can
                    // claim ownership of the barcode scanner.
                    claimedScanner.ReleaseDeviceRequested += claimedScanner_ReleaseDeviceRequested;

                    // after successfully claiming, attach the datareceived event handler.
                    claimedScanner.DataReceived += claimedScanner_DataReceived;

                    // Ask the API to decode the data by default. By setting this, API will decode the raw data from the barcode scanner and
                    // send the ScanDataLabel and ScanDataType in the DataReceived event
                    claimedScanner.IsDecodeDataEnabled = true;

                    // enable the scanner.
                    // Note: If the scanner is not enabled (i.e. EnableAsync not called), attaching the event handler will not be any useful because the API will not fire the event
                    // if the claimedScanner has not been Enabled
                    await claimedScanner.EnableAsync();

                    // after successful claim, list supported symbologies
                    IReadOnlyList <uint> supportedSymbologies = await scanner.GetSupportedSymbologiesAsync();

                    foreach (uint symbology in supportedSymbologies)
                    {
                        listOfSymbologies.Add(new SymbologyListEntry(symbology));
                    }

                    // reset the button state
                    ScenarioEndScanButton.IsEnabled = true;

                    rootPage.NotifyUser("Ready to scan. Device ID: " + claimedScanner.DeviceId, NotifyType.StatusMessage);
                }
                else
                {
                    scanner.Dispose();
                    scanner = null;
                    ScenarioStartScanButton.IsEnabled = true;
                    rootPage.NotifyUser("Claim barcode scanner failed.", NotifyType.ErrorMessage);
                }
            }
            else
            {
                ScenarioStartScanButton.IsEnabled = true;
                rootPage.NotifyUser("Barcode scanner not found. Please connect a barcode scanner.", NotifyType.ErrorMessage);
            }
        }
        void claimedBarcodeScanner_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
        {
            string symbologyName       = BarcodeSymbologies.GetName(args.Report.ScanDataType);
            var    scanDataLabelReader = DataReader.FromBuffer(args.Report.ScanDataLabel);
            string barcode             = scanDataLabelReader.ReadString(args.Report.ScanDataLabel.Length);

            scannerData.TryAddBarcode(barcode);
        }
Example #25
0
        private void ClaimedBarcode_DataRecieved(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
        {
            string symbologyName       = BarcodeSymbologies.GetName(args.Report.ScanDataType);
            var    scanDataLabelReader = DataReader.FromBuffer(args.Report.ScanDataLabel);
            string barcode             = scanDataLabelReader.ReadString(args.Report.ScanDataLabel.Length);

            ScanningData = barcode;
        }
Example #26
0
        /// <summary>
        /// Makes sure the application retains the claim on the _BarcodeScanner if another application trys to claim it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _ClaimedBarcodeScanner_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
        {
            Class1.doLog("Event ReleaseDeviceRequested received.");
//           await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
//            {
            // always retain the device
            //e.RetainDevice();
//            });
        }
Example #27
0
 private void DisableScanner()
 {
     if (claimedScanner != null)
     {
         claimedScanner.Dispose();
         claimedScanner = null;
     }
     changeButtonEnable(false);
 }
Example #28
0
 /// <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);
     });
 }
Example #29
0
        async void claimedScanner_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
        {
            await CoreApplication.GetCurrentView().CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                // always retain the device
                e.RetainDevice();

                Debug.WriteLine("Event ReleaseDeviceRequested received. Retaining the barcode scanner.");
            });
        }
        /// <summary>
        /// Event handler for the Release Device Requested event fired when barcode scanner receives Claim request from another application
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"> Contains the ClamiedBarcodeScanner that is sending this request</param>
        async void claimedScanner_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                // always retain the device
                e.RetainDevice();

                rootPage.NotifyUser("Event ReleaseDeviceRequested received. Retaining the barcode scanner.", NotifyType.StatusMessage);
            });
        }
        /// <summary>
        /// Event handler for the Release Device Requested event fired when barcode scanner receives Claim request from another application
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"> Contains the ClamiedBarcodeScanner that is sending this request</param>
        async void claimedScanner_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                // alsways retain the device
                e.RetainDevice();

                UpdateOutput("Event ReleaseDeviceRequest received. Retaining the Barcode Scanner.");
            });
        }
        /// <summary>
        /// This method claims the barcode scanner 
        /// </summary>
        /// <returns>true if claim is successful. Otherwise returns false</returns>
        private async Task<bool> ClaimScanner()
        {
            if (claimedScanner == null)
            {
                // claim the barcode scanner
                claimedScanner = await scanner.ClaimScannerAsync();

                // enable the claimed barcode scanner
                if (claimedScanner == null)
                {
                    rootPage.NotifyUser("Claim barcode scanner failed.", NotifyType.ErrorMessage);
                    return false;
                }
            }
            return true;
        }
Example #33
0
        /// <summary>
        /// This method claims the barcode scanner 
        /// </summary>
        /// <returns>true if claim is successful. Otherwise returns false</returns>
        private async Task<bool> ClaimScanner()
        {
            if (claimedScanner == null)
            {
                // claim the barcode scanner
                claimedScanner = await scanner.ClaimScannerAsync();

                // enable the claimed barcode scanner
                if (claimedScanner != null)
                {
                    UpdateOutput("Claim Barcode Scanner succeeded.");
                   
                }
                else
                {
                    UpdateOutput("Claim Barcode Scanner failed.");
                    return false;
                }
            }
            return true;
        }
 private async void buttonEnable_Click(object sender, RoutedEventArgs e)
 {
     scanner = await BarcodeScanner.GetDefaultAsync();
     if (claimedScanner != null)
         claimedScanner.Dispose();
     claimedScanner = await scanner.ClaimScannerAsync();
     claimedScanner.DataReceived += ClamedScanner_DataReceived;
     await claimedScanner.EnableAsync();
     claimedScanner.IsDecodeDataEnabled = true;
     
     await claimedScanner.SetActiveSymbologiesAsync(new uint[] {
         BarcodeSymbologies.Aztec,
         BarcodeSymbologies.AusPost,
         BarcodeSymbologies.CanPost,
         BarcodeSymbologies.Codabar,
         BarcodeSymbologies.Codablock128,
         BarcodeSymbologies.Code11,
         BarcodeSymbologies.Code128,
         BarcodeSymbologies.Code39,
         BarcodeSymbologies.Code39Ex,
         BarcodeSymbologies.DataMatrix,
         BarcodeSymbologies.Ean13,
         BarcodeSymbologies.Ean8,
         BarcodeSymbologies.Gs1128,
         BarcodeSymbologies.Gs1DatabarType1 ,
         BarcodeSymbologies.Gs1DatabarType2,
         BarcodeSymbologies.Gs1DatabarType3,
         BarcodeSymbologies.Pdf417,
         BarcodeSymbologies.Qr,
         BarcodeSymbologies.OcrB,
         BarcodeSymbologies.UccEan128,
         BarcodeSymbologies.Upca,
         BarcodeSymbologies.Upce,
         BarcodeSymbologies.UsPostNet,
     });
     changeButtonEnable(true);
 }
        async public void Enable(string options)
        {
            PluginResult result;

            if (barcodeScanner == null)
            {
                barcodeScanner = await Windows.Devices.PointOfService.BarcodeScanner.GetDefaultAsync();

                if (claimedBarcodeScanner == null)
                {
                    claimedBarcodeScanner = await barcodeScanner.ClaimScannerAsync();

                    if (claimedBarcodeScanner != null)
                    {
                        await claimedBarcodeScanner.EnableAsync();
                        claimedBarcodeScanner.DataReceived += DataReceived;

                        result = new PluginResult(PluginResult.Status.NO_RESULT);
                        result.KeepCallback = true;
                    }
                    else
                    {
                        result = new PluginResult(PluginResult.Status.ERROR, "Barcode Scanner could not get claimed");
                    }
                }
                else
                {
                    result = new PluginResult(PluginResult.Status.ERROR, "Claimed Barcode Scanner Object already there");
                }
            }
            else
            {
                result = new PluginResult(PluginResult.Status.ERROR, "Barcode Scanner Object already there");
            }

            DispatchCommandResult(result);
        }
 private void DisableScanner()
 {
     if (claimedScanner != null)
     {
         claimedScanner.Dispose();
         claimedScanner = null;
     }
     changeButtonEnable(false);
 }
        /// <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)
        {
            // Grab the data from the IBuffers
            string scanData = String.Empty;
            string scanDataLabel = String.Empty;

            if (args.Report.ScanData != null)
            {
                scanData = GetDataString(args.Report.ScanData);
            }

            if (args.Report.ScanDataLabel != null)
            {
                scanDataLabel = GetDataLabelString(args.Report.ScanDataLabel, args.Report.ScanDataType);
            }

            await MainPage.Current.Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                () =>
                {
                    // Symbology
                    ScanDataType2.Text = String.Format("{0}", BarcodeSymbologies.GetName(args.Report.ScanDataType));

                    // DataLabel
                    DataLabel2.Text = String.Format("{0}", scanDataLabel);

                    // Data
                    ScanData2.Text = String.Format("{0}", scanData);

                    rootPage.NotifyUser("Instance 2 received data from the barcode scanner.", NotifyType.StatusMessage);
                }
            );
        }
        /// <summary>
        /// Reset the Scenario state
        /// </summary>
        private void ResetTheScenarioState()
        {
            if (claimedBarcodeScannerInstance1 != null)
            {
                claimedBarcodeScannerInstance1.Dispose();
                claimedBarcodeScannerInstance1 = null;
            }

            scannerInstance1 = null;

            if (claimedBarcodeScannerInstance2 != null)
            {
                claimedBarcodeScannerInstance2.Dispose();
                claimedBarcodeScannerInstance2 = null;
            }

            scannerInstance2 = null;

            ResetUI();
        }
        /// <summary>
        /// This method claims the connected scanner.
        /// </summary>
        /// <returns>a boolean based on whether it was able to claim the scanner.</returns>
        private async Task<bool> ClaimBarcodeScannerAsync(BarcodeScannerInstance instance)
        {
            bool bClaimAsyncStatus = false;
            //select the instance to claim
            switch (instance)
            {
                case BarcodeScannerInstance.Instance1:

                    claimedBarcodeScannerInstance1 = await scannerInstance1.ClaimScannerAsync();
                    if (claimedBarcodeScannerInstance1 == null)
                        rootPage.NotifyUser("Instance 1 claim barcode scanner failed.", NotifyType.ErrorMessage);
                    else
                        bClaimAsyncStatus = true;
                    break;

                case BarcodeScannerInstance.Instance2:

                    claimedBarcodeScannerInstance2 = await scannerInstance2.ClaimScannerAsync();
                    if (claimedBarcodeScannerInstance2 == null)
                        rootPage.NotifyUser("Instance 2 claim barcode scanner failed.", NotifyType.ErrorMessage);
                    else
                        bClaimAsyncStatus = true;
                    break;

                default:
                    return bClaimAsyncStatus;
            }
            return bClaimAsyncStatus;
        }
        /// <summary>
        /// This is the click handler for the 'ScenarioEndScanningInstance2' button.  
        /// Initiates the disposal fo scanner instance 2.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 
        private void ButtonEndScanningInstance2_Click(object sender, RoutedEventArgs e)
        {
            //remove the event handlers
            claimedBarcodeScannerInstance2.DataReceived -= claimedBarcodeScannerInstance2_DataReceived;
            claimedBarcodeScannerInstance2.ReleaseDeviceRequested -= claimedBarcodeScannerInstance2_ReleaseDeviceRequested;

            //dispose the instance
            claimedBarcodeScannerInstance2.Dispose();
            claimedBarcodeScannerInstance2 = null;
            scannerInstance2 = null;

            //reset the UI
            ResetUI();

            rootPage.NotifyUser("Click a start scanning button to begin.", NotifyType.StatusMessage);
        }
        /// <summary>
        /// This method is called upon when a claim request is made on instance 2. If a retain request was placed on the device it rejects the new claim.
        /// </summary>
        /// <param name="instance"></param>
        /// <returns></returns>
        async void claimedBarcodeScannerInstance2_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
        {
            await MainPage.Current.Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                () =>
                {
                    //check if the instance wants to retain the device
                    if (Retain2.IsChecked == true)
                    {
                        try
                        {
                            //Retain the device
                            claimedBarcodeScannerInstance2.RetainDevice();
                        }
                        catch (Exception exception)
                        {
                            rootPage.NotifyUser("Retain instance 1 failed: " + exception.Message, NotifyType.ErrorMessage);
                        }
                    }
                    //Release the device
                    else
                    {
                        claimedBarcodeScannerInstance2.Dispose();
                        claimedBarcodeScannerInstance2 = null;
                    }

                }
            );
        }
 void DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
 {
     PluginResult result = new PluginResult(PluginResult.Status.OK, this.GetDataString(args.Report.ScanData));
     result.KeepCallback = true;
     DispatchCommandResult(result);
 }
        /// <summary>
        /// This is the click handler for the 'ScenarioEndScanningInstance2' button.  
        /// Initiates the disposal fo scanner instance 2.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 
        private void ButtonEndScanningInstance2_Click(object sender, RoutedEventArgs e)
        {
            //remove the event handlers
            claimedBarcodeScannerInstance2.DataReceived -= claimedBarcodeScannerInstance2_DataReceived;
            claimedBarcodeScannerInstance2.ReleaseDeviceRequested -= claimedBarcodeScannerInstance2_ReleaseDeviceRequested;

            //dispose the instance
            claimedBarcodeScannerInstance2.Dispose();
            claimedBarcodeScannerInstance2 = null;
            scannerInstance2 = null;

            //reset the UI
            ResetUI();

            UpdateOutput("Scanner Instance 1 Destroyed\n");
        }
        /// <summary>
        /// Reset the Scenario state
        /// </summary>
        private void ResetTheScenarioState()
        {
            if (claimedScanner != null)
            {
                // Detach the event handlers
                claimedScanner.DataReceived -= claimedScanner_DataReceived;
                claimedScanner.ReleaseDeviceRequested -= claimedScanner_ReleaseDeviceRequested;
                // Release the Barcode Scanner and set to null
                claimedScanner.Dispose();
                claimedScanner = null;
            }

            scanner = null;

            // Reset the strings in the UI
            rootPage.NotifyUser("Click the start scanning button to begin.", NotifyType.StatusMessage);
            this.ScenarioOutputScanData.Text = "No data";
            this.ScenarioOutputScanDataLabel.Text = "No data";
            this.ScenarioOutputScanDataType.Text = "No data";

            // reset the button state
            ScenarioEndScanButton.IsEnabled = false;
            ScenarioStartScanButton.IsEnabled = true;
        }
        /// <summary>
        /// This method claims the connected scanner.
        /// </summary>
        /// <returns>a boolean based on whether it was able to claim the scanner.</returns>
        private async Task<bool> ClaimBarcodeScannerAsync(BarcodeScannerInstance instance)
        {
            bool bClaimAsyncStatus = false;
            //select the instance to claim
            switch (instance)
            {
                case BarcodeScannerInstance.Instance1:

                    claimedBarcodeScannerInstance1 = await scannerInstance1.ClaimScannerAsync();
                    if (claimedBarcodeScannerInstance1 != null)
                    {
                        UpdateOutput("Instance1 Claim Barcode Scanner succeeded.");
                        bClaimAsyncStatus = true;
                    }
                    else
                    {
                        UpdateOutput("Instance1 Claim Barcode Scanner failed.");                     
                    }
                    break;

                case BarcodeScannerInstance.Instance2:

                    claimedBarcodeScannerInstance2 = await scannerInstance2.ClaimScannerAsync();
                    if (claimedBarcodeScannerInstance2 != null)
                    {
                        UpdateOutput("Instance2 Claim Barcode Scanner succeeded.");
                        bClaimAsyncStatus = true;
                    }
                    else
                    {
                        UpdateOutput("Instance2 Claim Barcode Scanner failed.");                                                
                    }
                    break;

                default:                    
                    return bClaimAsyncStatus;
            }
            return bClaimAsyncStatus;            
        }
        /// <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 = GetDataLabelString(args.Report.ScanDataLabel, args.Report.ScanDataType);

                ScenarioOutputScanData.Text = GetDataString(args.Report.ScanData);

                ScenarioOutputScanDataType.Text = BarcodeSymbologies.GetName(args.Report.ScanDataType);
            });
        }
        /// <summary>
        /// Event handler for the Release Device Requested event fired when barcode scanner receives Claim request from another application
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"> Contains the ClamiedBarcodeScanner that is sending this request</param>
        async void claimedScanner_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
        {
            // always retain the device
            e.RetainDevice();

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                rootPage.NotifyUser("Event ReleaseDeviceRequested received. Retaining the barcode scanner.", NotifyType.StatusMessage);
            });
        }
        /// <summary>
        /// This is an event handler for the claimed scanner Instance 1 when it scans and recieves data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void claimedBarcodeScannerInstance1_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
        {
            // Grab the data from the IBuffers
            string scanData = String.Empty;
            string scanDataLabel = String.Empty;

            if (args.Report.ScanData != null)
            {
                scanData = GetDataString(args.Report.ScanData);
            }

            if (args.Report.ScanDataLabel != null)
            {
                scanDataLabel = GetDataLabelString(args.Report.ScanDataLabel, args.Report.ScanDataType);
            }

            await MainPage.Current.Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                () =>
                {
                    ScanDataType1.Text = String.Format("{0}", BarcodeSymbologies.GetName(args.Report.ScanDataType));

                    // DataLabel
                    DataLabel1.Text = String.Format("{0}", scanDataLabel);

                    // Data
                    ScanData1.Text = String.Format("{0}", scanData);

                    UpdateOutput("Instance1 Data Received from Barcode Scanner.");
                }
            );
        }
Example #49
0
        /// <summary>
        /// Event handler for the Release Device Requested event fired when barcode scanner receives Claim request from another application
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"> Contains the ClamiedBarcodeScanner that is sending this request</param>
        async void claimedScanner_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                // alsways retain the device
                e.RetainDevice();

                UpdateOutput("Event ReleaseDeviceRequest received. Retaining the Barcode Scanner.");
            }); 
        }
        /// <summary>
        /// This method is called upon when a claim request is made on instance 2. If a retain request was placed on the device it rejects the new claim.
        /// </summary>
        /// <param name="instance"></param>
        /// <returns></returns>
        async void claimedBarcodeScannerInstance2_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
        {          
            await MainPage.Current.Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                () =>
                {
                    UpdateOutput(String.Format("\nReleaseDeviceRequested ({0})", claimedBarcodeScannerInstance2.DeviceId));
                    //check if the instance wants to retain the device
                    if (Retain2.IsChecked == true)
                    {
                        try
                        {
                            //Retain the device
                            claimedBarcodeScannerInstance2.RetainDevice();
                            UpdateOutput(String.Format("\t(Scanner Retained)"));
                        }
                        catch (Exception exception)
                        {
                            UpdateOutput(String.Format("\t(retain failed) ({0})", exception.ToString()));
                        }
                    }
                    //Release the device
                    else 
                    {
                        claimedBarcodeScannerInstance2.Dispose();
                        claimedBarcodeScannerInstance2 = null;
                        UpdateOutput("Scanner Released.");                    
                    }

                }
            );
        }
 public ClaimedBarcodeScannerEvents(ClaimedBarcodeScanner This)
 {
     this.This = This;
 }
        async private void ClamedScanner_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
        {
            UInt32 symbology;
            string label;
            string data;
            symbology = args.Report.ScanDataType;

            using(var datareader = Windows.Storage.Streams.DataReader.FromBuffer(args.Report.ScanDataLabel))
            {
                label = datareader.ReadString(args.Report.ScanDataLabel.Length);
            }
            using (var datareader = Windows.Storage.Streams.DataReader.FromBuffer(args.Report.ScanData))
            {
                data = datareader.ReadString(args.Report.ScanData.Length);
            }
            
            await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                textBoxSymbology.Text = BarcodeSymbologies.GetName(symbology); //Send the data to the UI through the dispatcher. tbData is a textbox in the UI
                textBoxData.Text = label; //Send the data to the UI through the dispatcher. tbLabel is a textbox in the UI
            });
        }