Example #1
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);
            }
        }