Ejemplo n.º 1
0
 private async void SetActiveSymbologies_Click(object sender, RoutedEventArgs e)
 {
     if (claimedScanner != null)
     {
         var symbologyList = new List <uint>();
         foreach (var symbologyListEntry in listOfSymbologies)
         {
             if (symbologyListEntry.IsEnabled)
             {
                 symbologyList.Add(symbologyListEntry.Id);
             }
         }
         await claimedScanner.SetActiveSymbologiesAsync(symbologyList);
     }
 }
Ejemplo n.º 2
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.º 3
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);
            }
        }
Ejemplo n.º 4
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);
 }