Ejemplo n.º 1
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.º 2
0
        /// <summary>
        /// This method returns the first available Barcode Scanner. To enumerate and find a particular device use the device enumeration code.
        /// </summary>
        /// <returns>a boolean value based on whether it found a compatible scanner connected</returns>
        private async Task <bool> CreateDefaultScannerObjectAsync(BarcodeScannerInstance instance)
        {
            BarcodeScanner scanner = null;

            scanner = await DeviceHelpers.GetFirstBarcodeScannerAsync();

            if (scanner == null)
            {
                rootPage.NotifyUser("Barcode scanner not found. Please connect a barcode scanner.", NotifyType.ErrorMessage);
                return(false);
            }

            switch (instance)
            {
            case BarcodeScannerInstance.Instance1:
                barcodeScannerInstance1 = scanner;
                break;

            case BarcodeScannerInstance.Instance2:
                barcodeScannerInstance2 = scanner;
                break;

            default:
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the default cash drawer.
        /// </summary>
        /// <param name="instance">Specifies the cash drawer instance that should be used.</param>
        /// <returns>True if the cash drawer was created, false otherwise.</returns>
        private async Task <bool> CreateDefaultCashDrawerObject(CashDrawerInstance instance)
        {
            rootPage.NotifyUser("Creating cash drawer object.", NotifyType.StatusMessage);

            CashDrawer tempDrawer = null;

            tempDrawer = await DeviceHelpers.GetFirstCashDrawerAsync();

            if (tempDrawer == null)
            {
                rootPage.NotifyUser("Cash drawer not found. Please connect a cash drawer.", NotifyType.ErrorMessage);
                return(false);
            }

            switch (instance)
            {
            case CashDrawerInstance.Instance1:
                cashDrawerInstance1 = tempDrawer;
                break;

            case CashDrawerInstance.Instance2:
                cashDrawerInstance2 = tempDrawer;
                break;

            default:
                return(false);
            }

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

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

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

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

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

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

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

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

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

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

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

                    rootPage.NotifyUser("Ready to scan. Device ID: " + claimedScanner.DeviceId, NotifyType.StatusMessage);
                }
                else
                {
                    scanner.Dispose();
                    scanner = null;
                    ScenarioStartScanButton.IsEnabled = true;
                    rootPage.NotifyUser("Claim barcode scanner failed.", NotifyType.ErrorMessage);
                }
            }
            else
            {
                ScenarioStartScanButton.IsEnabled = true;
                rootPage.NotifyUser("Barcode scanner not found. Please connect a barcode scanner.", NotifyType.ErrorMessage);
            }
        }
Ejemplo n.º 5
0
 // By default, use all connections types.
 public static async Task <PosPrinter> GetFirstReceiptPrinterAsync(PosConnectionTypes connectionTypes = PosConnectionTypes.All)
 {
     return(await DeviceHelpers.GetFirstDeviceAsync(PosPrinter.GetDeviceSelector(connectionTypes),
                                                    async (id) =>
     {
         PosPrinter printer = await PosPrinter.FromIdAsync(id);
         if (printer != null && printer.Capabilities.Receipt.IsPrinterPresent)
         {
             return printer;
         }
         // Dispose the unwanted printer.
         printer?.Dispose();
         return null;
     }));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates the default cash drawer.
        /// </summary>
        /// <returns>True if the cash drawer was created, false otherwise.</returns>
        private async Task <bool> CreateDefaultCashDrawerObject()
        {
            rootPage.NotifyUser("Creating cash drawer object.", NotifyType.StatusMessage);

            if (drawer == null)
            {
                drawer = await DeviceHelpers.GetFirstCashDrawerAsync();

                if (drawer == null)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 7
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;
            }
        }
Ejemplo n.º 8
0
        async void FindPrinter_Click()
        {
            isBusy = true;
            UpdateButtons();
            rootPage.NotifyUser("Finding printer", NotifyType.StatusMessage);
            rootPage.Printer = await DeviceHelpers.GetFirstReceiptPrinterAsync();

            if (rootPage.Printer != null)
            {
                rootPage.NotifyUser("Found receipt printer.", NotifyType.StatusMessage);
            }
            else
            {
                rootPage.NotifyUser("No receipt printer found", NotifyType.ErrorMessage);
            }
            isBusy = false;
            UpdateButtons();
        }
Ejemplo n.º 9
0
        private async Task <bool> FindReceiptPrinter()
        {
            if (printer == null)
            {
                rootPage.NotifyUser("Finding printer", NotifyType.StatusMessage);
                printer = await DeviceHelpers.GetFirstReceiptPrinterAsync();

                if (printer != null)
                {
                    rootPage.NotifyUser("Got Printer with Device Id : " + printer.DeviceId, NotifyType.StatusMessage);
                    return(true);
                }
                else
                {
                    rootPage.NotifyUser("No Printer found", NotifyType.ErrorMessage);
                    return(false);
                }
            }
            return(true);
        }
        /// <summary>
        /// Find the first receipt printer and create two instances of it.
        /// </summary>
        /// <returns></returns>
        private async Task <bool> FindReceiptPrinterInstances()
        {
            if (printerInstance1 == null || printerInstance2 == null)
            {
                rootPage.NotifyUser("Finding printer", NotifyType.StatusMessage);
                printerInstance1 = await DeviceHelpers.GetFirstReceiptPrinterAsync();

                if (printerInstance1 != null)
                {
                    rootPage.NotifyUser("Got Printer Instance 1 with Device Id : " + printerInstance1.DeviceId, NotifyType.StatusMessage);

                    // Create another instance of the same printer.
                    if (printerInstance2 != null)
                    {
                        printerInstance2.Dispose();
                        printerInstance2 = null;
                    }
                    printerInstance2 = await PosPrinter.FromIdAsync(printerInstance1.DeviceId);

                    if (printerInstance2 != null)
                    {
                        rootPage.NotifyUser("Got Printer Instance 2 with Device Id : " + printerInstance2.DeviceId, NotifyType.StatusMessage);
                        return(true);
                    }
                    else
                    {
                        rootPage.NotifyUser("Couldn't create second instance of printer.", NotifyType.StatusMessage);
                    }
                    return(false);
                }
                else
                {
                    rootPage.NotifyUser("No Printer found", NotifyType.ErrorMessage);
                    return(false);
                }
            }

            return(true);
        }
 public static async Task <BarcodeScanner> GetFirstBarcodeScannerAsync(PosConnectionTypes connectionTypes = PosConnectionTypes.All)
 {
     return(await DeviceHelpers.GetFirstDeviceAsync(BarcodeScanner.GetDeviceSelector(connectionTypes), async (id) => await BarcodeScanner.FromIdAsync(id)));
 }
Ejemplo n.º 12
0
 // By default, use all connections types.
 public static async Task <CashDrawer> GetFirstCashDrawerAsync(PosConnectionTypes connectionTypes = PosConnectionTypes.All)
 {
     return(await DeviceHelpers.GetFirstDeviceAsync(CashDrawer.GetDeviceSelector(connectionTypes), async (id) => await CashDrawer.FromIdAsync(id)));
 }
 // By default, use all connections types.
 public static async Task <MagneticStripeReader> GetFirstMagneticStripeReaderAsync(PosConnectionTypes connectionTypes = PosConnectionTypes.All)
 {
     return(await DeviceHelpers.GetFirstDeviceAsync(MagneticStripeReader.GetDeviceSelector(connectionTypes), async (id) => await MagneticStripeReader.FromIdAsync(id)));
 }
Ejemplo n.º 14
0
 public static async Task <MagneticStripeReader> GetFirstMagneticStripeReaderAsync()
 {
     return(await DeviceHelpers.GetFirstDeviceAsync(MagneticStripeReader.GetDeviceSelector(), async (id) => await MagneticStripeReader.FromIdAsync(id)));
 }
 public static async Task <BarcodeScanner> GetFirstBarcodeScannerAsync()
 {
     return(await DeviceHelpers.GetFirstDeviceAsync(BarcodeScanner.GetDeviceSelector(), async (id) => await BarcodeScanner.FromIdAsync(id)));
 }