Ejemplo n.º 1
0
        private async void OnInitializeScannerAsync()
        {
            string selector = BarcodeScanner.GetDeviceSelector(PosConnectionTypes.Local);
            DeviceInformationCollection deviceCollection = await DeviceInformation.FindAllAsync(selector);

            foreach (var device in deviceCollection)
            {
                BarcodeScanner scanner = await BarcodeScanner.FromIdAsync(device.Id);

                if (scanner != null && scanner.VideoDeviceId != null)
                {
                    _claimedScanner = await scanner.ClaimScannerAsync();

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

                        _claimedScanner.DataReceived += OnBarcodeDetected;

                        await _videoPreview.StartStreamingAsync(scanner.VideoDeviceId);

                        await _claimedScanner.StartSoftwareTriggerAsync();

                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }
Ejemplo n.º 3
0
        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;
            }
        }
        /// <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);
            }
        }
Ejemplo n.º 5
0
        private async void GetScanner()
        {
            // only finds the first POS device connected to the pc, ok if only one POS device is connected
            barcodeScanner = await BarcodeScanner.GetDefaultAsync();

            // for later to find a specific device
            //string selector = BarcodeScanner.GetDeviceSelector();
            //DeviceInformationCollection deviceCollection = await DeviceInformation.FindAllAsync(selector);

            //foreach (DeviceInformation devInfo in deviceCollection)
            //{
            //    Debug.WriteLine("{0} {1}", devInfo.Name, devInfo.Id);
            //    if (devInfo.Name.Contains("1202"))
            //    {
            //        Debug.WriteLine("Found one");
            //    }
            //}


            //claim device
            if (barcodeScanner != null)
            {
                try
                {
                    claimedBarcodeScanner = await barcodeScanner.ClaimScannerAsync();

                    if (claimedBarcodeScanner != null)
                    {
                        // keep device claimed no matter what
                        claimedBarcodeScanner.ReleaseDeviceRequested += claimedBarcodeScanner_ReleaseDeviceRequested;
                        // enable decoding properties
                        claimedBarcodeScanner.DataReceived       += claimedBarcodeScanner_DataReceived;
                        claimedBarcodeScanner.IsDecodeDataEnabled = true;
                        await claimedBarcodeScanner.EnableAsync();
                    }
                    Debug.WriteLine("ToString | ClaimedBarcodeObject: " + claimedBarcodeScanner.ToString());
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("EX: ClaimScannerAsync() - " + ex.Message);
                }
            }
            else
            {
                Debug.WriteLine("No POS-Barcode Scanner found.");
            }


            //unclaim a device
            //if (claimedBarcodeScanner != null)
            //{
            //    claimedBarcodeScanner.Dispose();
            //    claimedBarcodeScanner = null;
            //}
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This method claims the barcode _BarcodeScanner
        /// </summary>
        /// <returns>true if claim is successful. Otherwise returns false</returns>
        private async System.Threading.Tasks.Task <bool> ClaimScanner()
        {
            if (_ClaimedBarcodeScanner == null)
            {
                // claim the barcode _BarcodeScanner
                _ClaimedBarcodeScanner = await _BarcodeScanner.ClaimScannerAsync();

                // enable the claimed barcode _BarcodeScanner
                if (_ClaimedBarcodeScanner == null)
                {
                    Class1.doLog("Claim barcode _BarcodeScanner failed.");
                    return(false);
                }
            }
            return(true);
        }
        /// <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);
        }
Ejemplo n.º 8
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 (this.claimedScanner == null)
            {
                // claim the barcode scanner
                this.claimedScanner = await scanner.ClaimScannerAsync();

                // enable the claimed barcode scanner
                if (this.claimedScanner == null)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 9
0
        /// <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);

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

            if (scanner != null)
            {
                // after successful creation, claim the scanner for exclusive use and enable it so that data reveived 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.
                    // The scanner must be enabled in order to receive the DataReceived event.
                    await claimedScanner.EnableAsync();

                    rootPage.NotifyUser("Ready to scan. Device ID: " + claimedScanner.DeviceId, NotifyType.StatusMessage);
                    ScenarioEndScanButton.IsEnabled = true;
                }
                else
                {
                    rootPage.NotifyUser("Claim barcode scanner failed.", NotifyType.ErrorMessage);
                    ScenarioStartScanButton.IsEnabled = true;
                }
            }
            else
            {
                rootPage.NotifyUser("Barcode scanner not found. Please connect a barcode scanner.", NotifyType.ErrorMessage);
                ScenarioStartScanButton.IsEnabled = true;
            }
        }
        //</SnippetCreateBarcodeScanner>

        //<SnippetClaimBarcodeScanner>
        // Claims the barcode scanner for exclusive use.

        private async Task <bool> ClaimScanner()
        {
            if (claimedScanner == null)
            {
                claimedScanner = await scanner.ClaimScannerAsync();

                if (claimedScanner != null)
                {
                    // UpdateOutput("Barcode scanner claimed successfully.");
                }
                else
                {
                    // UpdateOutput("Failed to claim the barcode scanner.");
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        /// <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);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Select the scanner specified by its device ID.
        /// </summary>
        /// <param name="scannerDeviceId"></param>
        private async Task SelectScannerAsync(string scannerDeviceId)
        {
            isSelectionChanging = true;

            await CloseScannerResourcesAsync();

            selectedScanner = await BarcodeScanner.FromIdAsync(scannerDeviceId);

            if (selectedScanner != null)
            {
                claimedScanner = await selectedScanner.ClaimScannerAsync();

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

                    claimedScanner.Closed += ClaimedScanner_Closed;
                    ScannerSupportsPreview = !String.IsNullOrEmpty(selectedScanner.VideoDeviceId);
                    RaisePropertyChanged(nameof(ScannerSupportsPreview));

                    claimedScanner.DataReceived += ClaimedScanner_DataReceived;

                    if (ScannerSupportsPreview)
                    {
                        await StartMediaCaptureAsync(selectedScanner.VideoDeviceId);
                    }
                }
                else
                {
                    rootPage.NotifyUser("Failed to claim the selected barcode scanner", NotifyType.ErrorMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("Failed to create a barcode scanner object", NotifyType.ErrorMessage);
            }

            IsScannerClaimed = claimedScanner != null;
            RaisePropertyChanged(nameof(IsScannerClaimed));

            isSelectionChanging = false;
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        /// <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 barcodeScannerInstance1.ClaimScannerAsync();

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

            case BarcodeScannerInstance.Instance2:

                claimedBarcodeScannerInstance2 = await barcodeScannerInstance2.ClaimScannerAsync();

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

            default:
                return(bClaimAsyncStatus);
            }
            return(bClaimAsyncStatus);
        }
Ejemplo n.º 16
0
 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);
 }
Ejemplo n.º 17
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)
            {
                try
                {
                    // claim the barcode scanner
                    claimedScanner = await scanner.ClaimScannerAsync();

                    return(true);
                }
                catch (Exception)
                {
                }

                // enable the claimed barcode scanner
                if (claimedScanner == null)
                {
                    Debug.WriteLine("Claim barcode scanner failed.");
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 18
0
        private async void CodeScanner_Loaded(object sender, RoutedEventArgs e)
        {
            BarcodeList.ItemsSource = BarcodeHistory = new ObservableCollection <BarcodeItem>();
            ExitLocker = new AutoResetEvent(false);

            string Selector = BarcodeScanner.GetDeviceSelector(PosConnectionTypes.Local);
            DeviceInformationCollection DeviceCollection = await DeviceInformation.FindAllAsync(Selector);

            if (DeviceCollection == null || DeviceCollection.Count == 0)
            {
                Pro.Visibility = Visibility.Collapsed;
                ProText.Text   = "无摄像头可用";
                return;
            }

            if (ApplicationData.Current.LocalSettings.Values["LastSelectedCameraSource"] is string StorageCameraSource)
            {
                foreach (var DeviceID in from Device in DeviceCollection
                         where Device.Name.Contains(StorageCameraSource)
                         select Device.Id)
                {
                    using (BarcodeScanner Scanner = await BarcodeScanner.FromIdAsync(DeviceID))
                    {
                        Capture = new MediaCapture();
                        var InitializeSettings = new MediaCaptureInitializationSettings
                        {
                            VideoDeviceId        = Scanner.VideoDeviceId,
                            StreamingCaptureMode = StreamingCaptureMode.Video,
                            PhotoCaptureSource   = PhotoCaptureSource.VideoPreview
                        };
                        await Capture.InitializeAsync(InitializeSettings);

                        var CameraFocusControl = Capture.VideoDeviceController.FocusControl;
                        if (CameraFocusControl.Supported)
                        {
                            await CameraFocusControl.UnlockAsync();

                            CameraFocusControl.Configure(new FocusSettings {
                                Mode = FocusMode.Continuous, AutoFocusRange = AutoFocusRange.FullRange
                            });
                            await CameraFocusControl.FocusAsync();
                        }
                        PreviewControl.Source = Capture;

                        ClaimedScanner = await Scanner.ClaimScannerAsync();

                        ClaimedScanner.IsDisabledOnDataReceived = false;
                        ClaimedScanner.IsDecodeDataEnabled      = true;
                        ClaimedScanner.DataReceived            += ClaimedScanner_DataReceived;
                        await ClaimedScanner.EnableAsync();

                        await ClaimedScanner.StartSoftwareTriggerAsync();

                        await Capture.StartPreviewAsync();
                    }
                    break;
                }

                if (Capture == null)
                {
                    ContentDialog dialog = new ContentDialog
                    {
                        Title           = "提示",
                        Content         = "    设置所指定的摄像头无法应用于条码识别\r\r    已自动选择最合适的摄像头",
                        CloseButtonText = "确定",
                        Background      = Application.Current.Resources["DialogAcrylicBrush"] as Brush
                    };
                    _ = await dialog.ShowAsync();

                    using (BarcodeScanner Scanner = await BarcodeScanner.FromIdAsync(DeviceCollection.FirstOrDefault().Id))
                    {
                        Capture = new MediaCapture();
                        var InitializeSettings = new MediaCaptureInitializationSettings
                        {
                            VideoDeviceId        = Scanner.VideoDeviceId,
                            StreamingCaptureMode = StreamingCaptureMode.Video,
                            PhotoCaptureSource   = PhotoCaptureSource.VideoPreview
                        };
                        await Capture.InitializeAsync(InitializeSettings);

                        var CameraFocusControl = Capture.VideoDeviceController.FocusControl;
                        if (CameraFocusControl.Supported)
                        {
                            await CameraFocusControl.UnlockAsync();

                            CameraFocusControl.Configure(new FocusSettings {
                                Mode = FocusMode.Continuous, AutoFocusRange = AutoFocusRange.FullRange
                            });
                            await CameraFocusControl.FocusAsync();
                        }
                        PreviewControl.Source = Capture;

                        ClaimedScanner = await Scanner.ClaimScannerAsync();

                        ClaimedScanner.IsDisabledOnDataReceived = false;
                        ClaimedScanner.IsDecodeDataEnabled      = true;
                        ClaimedScanner.DataReceived            += ClaimedScanner_DataReceived;
                        await ClaimedScanner.EnableAsync();

                        await ClaimedScanner.StartSoftwareTriggerAsync();

                        await Capture.StartPreviewAsync();
                    }
                }
            }
            else
            {
                using (BarcodeScanner Scanner = await BarcodeScanner.FromIdAsync(DeviceCollection.FirstOrDefault().Id))
                {
                    Capture = new MediaCapture();
                    var InitializeSettings = new MediaCaptureInitializationSettings
                    {
                        VideoDeviceId        = Scanner.VideoDeviceId,
                        StreamingCaptureMode = StreamingCaptureMode.Video,
                        PhotoCaptureSource   = PhotoCaptureSource.VideoPreview
                    };
                    await Capture.InitializeAsync(InitializeSettings);

                    var CameraFocusControl = Capture.VideoDeviceController.FocusControl;
                    if (CameraFocusControl.Supported)
                    {
                        await CameraFocusControl.UnlockAsync();

                        CameraFocusControl.Configure(new FocusSettings {
                            Mode = FocusMode.Continuous, AutoFocusRange = AutoFocusRange.FullRange
                        });
                        await CameraFocusControl.FocusAsync();
                    }
                    PreviewControl.Source = Capture;

                    ClaimedScanner = await Scanner.ClaimScannerAsync();

                    ClaimedScanner.IsDisabledOnDataReceived = false;
                    ClaimedScanner.IsDecodeDataEnabled      = true;
                    ClaimedScanner.DataReceived            += ClaimedScanner_DataReceived;
                    await ClaimedScanner.EnableAsync();

                    await ClaimedScanner.StartSoftwareTriggerAsync();

                    await Capture.StartPreviewAsync();
                }
            }
            LoadingControl.IsLoading = false;

            ExitLocker.Set();
        }
Ejemplo n.º 19
0
        private async Task <Tuple <bool, string> > InitializeScannerAsync()
        {
            try
            {
                //var wp = new xx.UWP.WriteProfile();
                //var x = await wp.Write(ProfileFileName);


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

                    if (scanner == null)
                    {
                        Windows.Devices.Enumeration.DeviceInformationCollection deviceCollection = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.PointOfService.BarcodeScanner.GetDeviceSelector());

                        if (deviceCollection != null && deviceCollection.Count > 0)
                        {
                            scannerInitComplete = false;
                            foreach (Windows.Devices.Enumeration.DeviceInformation D in deviceCollection)
                            {
                                if (D.Id.Contains("POSBarcodeScanner"))
                                {
                                    scanner = await Windows.Devices.PointOfService.BarcodeScanner.FromIdAsync(D.Id);
                                }
                            }
                        }
                    }
                }
                if (scanner != null)
                {
                    claimedScanner = await scanner.ClaimScannerAsync();
                }
                if (claimedScanner != null)
                {
                    claimedScanner.DataReceived           += ClaimedScanner_DataReceivedAsync;
                    claimedScanner.ReleaseDeviceRequested += OnClaimedScannerReleaseDeviceRequested;
                    claimedScanner.IsDecodeDataEnabled     = true;

                    await claimedScanner.EnableAsync();

                    //await obj.claimedScanner.SetActiveSymbologiesAsync(new List<uint> { 0 });

                    foreach (string ProfileName in scanner.GetSupportedProfiles())
                    {
                        if (ProfileName == "Develok Profile")
                        {
                            await claimedScanner.SetActiveProfileAsync(ProfileName); break;
                        }
                    }
                    scannerInitComplete = true;
                    //mp.BtnSettingsBackground(new SolidColorBrush(Color.FromArgb(120, 0, 255, 0)));
                    //if (!mp.skipUpdate)
                    //{
                    //    mp.successOfScanner = true;
                    //    if (mp.lstLocalScannerSettings.First().restAddress == "olemas")
                    //    {
                    //        if (await mp.DisplayMessageYesNoAsync("Serveri aadress on seadistamata. Kas soovid seda teha?"))
                    //        {
                    //            mp.PrepareSettings();
                    //        }
                    //    }
                    //    else
                    //    {
                    //        CheckNewVersionAvailabilityAsync.Check(mp);
                    //        mp.TxtBkScannedValue.Focus(FocusState.Programmatic);
                    //    }
                    //}
                    return(new Tuple <bool, string>(true, null));
                }
                else
                {
                    //mp.BtnSettingsBackground(new SolidColorBrush(Colors.Red));

                    return(new Tuple <bool, string>(false, "InitializeScannerAsync 1"));
                }
            }
            catch (Exception ex)
            {
                return(new Tuple <bool, string>(false, "InitializeScannerAsync " + ex.Message));
                //mp.SendDebugErrorMessage(this.GetType().Name, "InitializeScannerAsync", ex);
            }
        }