예제 #1
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;
            //}
        }