/// <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);
            }
        }
Beispiel #2
0
        public async Task CreateScanner(CoreDispatcher dispatcher)
        {
            //StartWatcher(dispatcher);
            if (await CreateDefaultScannerObject())
            {
                // after successful creation, claim the scanner for exclusive use and enable it so that data reveived events are received.
                if (await ClaimScanner())
                {
                    // 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 ownsership of the barcode scanner.
                    claimedScanner.ReleaseDeviceRequested += claimedScanner_ReleaseDeviceRequested;

                    // after successfully claiming, attach the datareceived event handler.
                    claimedScanner.DataReceived += ClaimedScanner_DataReceived;;  // todo: create 'canreceivedata event'
                    // 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 beed Enabled
                    await claimedScanner.EnableAsync();

                    //rootPage.NotifyUser("Ready to scan. Device ID: " + claimedScanner.DeviceId, NotifyType.StatusMessage);

                    await StartSoftwareTrigger();
                }
            }
        }
        /// <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)
        {
            rootPage.NotifyUser("Creating barcode scanner object.", NotifyType.StatusMessage);

            // create the barcode scanner.
            if (await CreateDefaultScannerObject())
            {
                // after successful creation, claim the scanner for exclusive use and enable it so that data reveived events are received.
                if (await ClaimScanner())
                {
                    // 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 ownsership 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 beed Enabled
                    await claimedScanner.EnableAsync();

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

                    rootPage.NotifyUser("Ready to scan. Device ID: " + claimedScanner.DeviceId, NotifyType.StatusMessage);
                }
            }
        }
        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);
        }
        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);
        }
        /// <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);
            }
        }
        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;
            //}
        }
        //</SnippetClaimBarcodeScanner>

        //<SnippetEnableBarcodeScanner>
        // Enables the barcode scanner to receive data

        private async Task <bool> EnableScanner()
        {
            if (claimedScanner == null)
            {
                return(false);
            }
            else
            {
                await claimedScanner.EnableAsync();

                return(true);
            }
        }
        /// <summary>
        /// This method claims the barcode scanner and enables it
        /// </summary>
        /// <returns>true if enable is successful</returns>
        private async Task <bool> EnableScanner()
        {
            // enable the claimed barcode scanner
            if (claimedScanner == null)
            {
                return(false);
            }
            else
            {
                await claimedScanner.EnableAsync();

                UpdateOutput("Enable Barcode Scanner succeeded.");

                return(true);
            }
        }
Beispiel #11
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;
            }
        }
Beispiel #12
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);
        }
Beispiel #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;
        }
Beispiel #14
0
        /// <summary>
        /// This method enables the connected scanner.
        /// </summary>
        /// <returns>a boolean based on whether it was able to enable the scanner.</returns>
        private async Task <bool> EnableBarcodeScannerAsync(BarcodeScannerInstance instance)
        {
            switch (instance)
            {
            case BarcodeScannerInstance.Instance1:
                await claimedBarcodeScannerInstance1.EnableAsync();

                rootPage.NotifyUser("Instance 1 ready to scan. Device ID: " + claimedBarcodeScannerInstance1.DeviceId, NotifyType.StatusMessage);
                break;

            case BarcodeScannerInstance.Instance2:
                await claimedBarcodeScannerInstance2.EnableAsync();

                rootPage.NotifyUser("Instance 2 ready to scan. Device ID: " + claimedBarcodeScannerInstance2.DeviceId, NotifyType.StatusMessage);
                break;

            default:
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// This method enables the connected scanner.
        /// </summary>
        /// <returns>a boolean based on whether it was able to enable the scanner.</returns>
        private async Task <bool> EnableBarcodeScannerAsync(BarcodeScannerInstance instance)
        {
            switch (instance)
            {
            case BarcodeScannerInstance.Instance1:
                await claimedBarcodeScannerInstance1.EnableAsync();

                UpdateOutput("Instance1 Enable Barcode Scanner succeeded.");
                break;

            case BarcodeScannerInstance.Instance2:
                await claimedBarcodeScannerInstance2.EnableAsync();

                UpdateOutput("Instance2 Enable Barcode Scanner succeeded.");
                break;

            default:
                return(false);
            }
            return(true);
        }
Beispiel #16
0
        private async Task <bool> activateHelper()
        {
            Debug.WriteLine("Creating barcode scanner object.");

            // create the barcode scanner.
            if (await CreateDefaultScannerObject())
            {
                // after successful creation, claim the scanner for exclusive use and enable it so that data reveived events are received.
                if (await ClaimScanner())
                {
                    // 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 ownsership 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 beed Enabled
                    await claimedScanner.EnableAsync();

                    Debug.WriteLine("Barcodescanner is ready. Device ID: " + claimedScanner.DeviceId);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        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);
        }
        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 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);
 }
Beispiel #20
0
        /// <summary>
        /// Instantiates the _BarcodeScanner and sets up the active symbologies
        /// </summary>
        private async System.Threading.Tasks.Task <bool> StartScanner()
        {
            try
            {
                // Waits for the default _BarcodeScanner opjet to be created
                if (await CreateDefaultScannerObject())
                {
                    Class1.doLog("CreateDefaultScannerObject()...");
                    // Waits for the defualt _BarcodeScanner object to be claimed by the application
                    if (await ClaimScanner())
                    {
                        Class1.doLog("ClaimScanner()...");

                        // enable the _BarcodeScanner.
                        // Note: If the _BarcodeScanner 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 _ClaimedBarcodeScanner has not beed Enabled
                        await _ClaimedBarcodeScanner.EnableAsync();

                        Class1.doLog("_ClaimedBarcodeScanner.EnableAsync() done");

                        // 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 ownsership of the barcode _BarcodeScanner.
                        _ClaimedBarcodeScanner.ReleaseDeviceRequested += _ClaimedBarcodeScanner_ReleaseDeviceRequested;

                        // after successfully claiming, attach the datareceived event handler.
                        _ClaimedBarcodeScanner.DataReceived += _ClaimedBarcodeScanner_DataReceived;

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

                        //// enable the _BarcodeScanner.
                        //// Note: If the _BarcodeScanner 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 _ClaimedBarcodeScanner has not beed Enabled
                        //await _ClaimedBarcodeScanner.EnableAsync();
                        //Class1.doLog("_ClaimedBarcodeScanner.EnableAsync() done");

                        // Set all active symbologies to false to start with a clean slate.
                        await _ClaimedBarcodeScanner.SetActiveSymbologiesAsync(new List <uint> {
                            0
                        });

                        List <uint> Symbologies = new List <uint>();
                        Symbologies.Add(BarcodeSymbologies.Upca);
                        Symbologies.Add(BarcodeSymbologies.UpcaAdd2);
                        Symbologies.Add(BarcodeSymbologies.UpcaAdd5);
                        Symbologies.Add(BarcodeSymbologies.Ean13);
                        Symbologies.Add(BarcodeSymbologies.Ean13Add2);
                        Symbologies.Add(BarcodeSymbologies.Ean13Add5);
                        Symbologies.Add(BarcodeSymbologies.Code128);
                        Symbologies.Add(BarcodeSymbologies.Gs1128);
                        Symbologies.Add(BarcodeSymbologies.DataMatrix);
                        Symbologies.Add(BarcodeSymbologies.Code39);
                        Symbologies.Add(BarcodeSymbologies.Code39Ex);
                        Symbologies.Add(BarcodeSymbologies.Pdf417);

                        await _ClaimedBarcodeScanner.SetActiveSymbologiesAsync(Symbologies);

                        Class1.doLog("_ClaimedBarcodeScanner.SetActiveSymbologiesAsync(Symbologies)");
                        Class1.doLog(" Ready to scan.");
                        if (_autoScan)
                        {
                            await _ClaimedBarcodeScanner.StartSoftwareTriggerAsync();
                        }
                    }
                }
            }catch (Exception ex)
            {
                await showMessage("StartScanner " + ex.Message);
            }
            if (_ClaimedBarcodeScanner != null)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
                    //UI code here
                    textBox_Scan.Background = new SolidColorBrush(Windows.UI.Colors.LightGreen);
                });

                return(true);
            }
            else
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
                    //UI code here
                    textBox_Scan.Background = new SolidColorBrush(Windows.UI.Colors.LightPink);
                });

                return(false);
            }
        }
        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();
        }
Beispiel #22
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);
            }
        }