Пример #1
0
        /// <summary>
        /// Close the scanner device
        /// </summary>
        public void Close()
        {
            if (timeout != null)
            {
                timeout.Dispose();
            }

            if (scannerStatus == ScannerStatus.Closed)
            {
                return;
            }

            if (reader != null)
            {
                reader.ScannerOn     = false;
                reader.ScannerEnable = false;
                reader.BarcodeRead  -= scanEvent;
                reader.CancelRead(true);
                reader.Dispose();
                reader = null;
            }

            scannedData   = null;
            scannerStatus = ScannerStatus.Closed;
        }
Пример #2
0
        /// <summary>
        /// Used to start Scanning
        /// </summary>
        /// <param name="callback"></param>
        public void Scan(Action <string, string> callback)
        {
            if (Callback != null)
            {
                Log.Warning(this + " Already Scan");
                return;
            }
            Callback = callback;

            Log.Info(this + " SimpleScanner -> Start Scan");
            Status = ScannerStatus.Running;

                        #if !UNITY_WEBGL
            if (Settings.ScannerBackgroundThread)
            {
                if (CodeScannerThread != null)
                {
                    Stop(true);
                }

                forceStopScanning = false;
                CodeScannerThread = new Thread(ThreadDecodeQR);
                CodeScannerThread.Start();
            }
                        #endif
        }
Пример #3
0
        /// <summary>
        /// Used to Stop Scanning internaly (can be forced)
        /// </summary>
        private void Stop(bool forced)
        {
            if (!forced && Callback == null)
            {
                Log.Warning(this + " No Scan running");
                return;
            }

            // Stop thread / Clean callback
            Log.Info(this + " SimpleScanner -> Stop Scan");
                        #if WINDOWS_UWP
            if (CodeScannerThread != null)
            {
                decodeInterrupted = true;
                CodeScannerThread.Wait();
                CodeScannerThread = null;
            }
                        #elif !UNITY_WEBGL
            if (CodeScannerThread != null)
            {
                decodeInterrupted = true;
                CodeScannerThread.Join();
                CodeScannerThread = null;
            }
                        #endif

            Callback = null;
            Status   = ScannerStatus.Paused;
        }
Пример #4
0
        /// <summary>
        /// Open the scanner device
        /// </summary>
        public void Open()
        {
            if (scannerStatus == ScannerStatus.Opened)
            {
                return;
            }

            try
            {
                if (reader == null)
                {
                    reader = new IntermecBarcodeReader {
                        ScannerOn = false, ScannerEnable = false
                    }
                }
                ;

                reader.BarcodeRead  += scanEvent;
                reader.ScannerEnable = true;
                reader.ThreadedRead(true);

                scannedData   = new string[1];
                scannerStatus = ScannerStatus.Opened;
            }
            catch
            {
                Close();
                throw;
            }
        }
Пример #5
0
        private async void OnScannerStatusChangedAsync(object sender, ScannerStatus e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Model.IsScanning = e == ScannerStatus.Started);

            if (e == ScannerStatus.Aborted && _bluetoothNotOnDialogOperation == null)
            {
                if (Util.IsIoT)
                {
                    return;
                }
                MessageDialog messageDialog = new MessageDialog(
                    "Do you wish to enable Bluetooth on this device?",
                    "Failed to start Bluetooth LE advertisement watcher");

                messageDialog.Commands.Add(new UICommand("Yes",
                                                         command =>
                {
                    Model.SdkManager.LaunchBluetoothSettingsAsync();
                }));

                messageDialog.Commands.Add(new UICommand("No",
                                                         command =>
                {
                    Model.SdkManager.StopScanner();
                }));

                _bluetoothNotOnDialogOperation = messageDialog.ShowAsync();
            }
        }
Пример #6
0
        /// <summary>
        ///     Open the scanner device
        /// </summary>
        public void Open()
        {
            if (scannerStatus == ScannerStatus.Opened)
            {
                return;
            }

            try
            {
                reader     = new Reader();
                readerData = new ReaderData(ReaderDataTypes.Text, ReaderDataLengths.MaximumLabel);
                reader.Actions.Enable();

                // SuperGros ProductNumber
                reader.Decoders.I2OF5.MinimumLength = 6;
                reader.Decoders.I2OF5.MaximumLength = 14;

                StartRead();

                scannerStatus = ScannerStatus.Opened;
            }
            catch
            {
                Close();
                throw;
            }
        }
Пример #7
0
        /// <summary>
        /// Opens the connection to the scanner
        /// </summary>
        public void Open()
        {
            if (Status == ScannerStatus.Opened)
            {
                return;
            }

            lock (syncLock)
            {
                //var result = OBReadLibNet.Api.OBROpen(Handle.GetValueOrDefault(IntPtr.Zero),
                //                                      OBReadLibNet.Def.OBR_ALL | OBReadLibNet.Def.OBR_OUT_ON);
                //CheckCasioResult(result);

                var result = OBReadLibNet.Api.OBRLoadConfigFile(); //ini File read default value set
                CheckCasioResult(result);

                result = OBReadLibNet.Api.OBRSetDefaultSymbology(); //1D(OBR) driver mode will be ini File vallue
                CheckCasioResult(result);

                result =
                    OBReadLibNet.Api.OBRSetScanningKey(OBReadLibNet.Def.OBR_TRIGGERKEY_L |
                                                       OBReadLibNet.Def.OBR_TRIGGERKEY_R |
                                                       OBReadLibNet.Def.OBR_CENTERTRIGGER);
                CheckCasioResult(result);

                result = OBReadLibNet.Api.OBRSetScanningCode(OBReadLibNet.Def.OBR_ALL);
                CheckCasioResult(result);

                result = OBReadLibNet.Api.OBRSetBuffType(OBReadLibNet.Def.OBR_BUFOBR);
                //1D(OBR) driver mode will be OBR_BUFOBR
                CheckCasioResult(result);

                result = OBReadLibNet.Api.OBRSetScanningNotification(OBReadLibNet.Def.OBR_EVENT, Handle);
                //1D(OBR) driver mode will be OBR_EVENT
                CheckCasioResult(result);

                result = OBReadLibNet.Api.OBRSetBuzzer(OBReadLibNet.Def.OBR_BUZON); //enable sound notification
                CheckCasioResult(result);

                result = OBReadLibNet.Api.OBRSetVibrator(OBReadLibNet.Def.OBR_VIBON); //enable sound notification
                CheckCasioResult(result);

                result = OBReadLibNet.Api.OBROpen(Handle, 0); //OBRDRV open
                CheckCasioResult(result);

                result = OBReadLibNet.Api.OBRClearBuff();
                CheckCasioResult(result);

                OBReadLibNet.Api.OBRSaveConfigFile();

                Status = ScannerStatus.Opened;

                scanningThread = new Thread(GetScannerStatusWorker)
                {
                    IsBackground = true
                };
                scanningThread.Start();
            }
        }
Пример #8
0
        /// <summary>
        /// Creates an instance of the Intermec barcode scanner device
        /// </summary>
        public IntermecScanner()
        {
            scanEvent     = OnBarcodeRead;
            scannerStatus = ScannerStatus.Closed;

            reader = new IntermecBarcodeReader {
                ScannerOn = false, ScannerEnable = false
            };
        }
Пример #9
0
        /// <summary>
        /// Creates an instance of the Intermec barcode scanner device
        /// </summary>
        public IntermecScanner()
        {
            scanEvent     = new BarcodeReadEventHandler(OnBarcodeRead);
            scannerStatus = Barcode.ScannerStatus.Closed;

            reader = new IntermecBarcodeReader {
                ScannerOn = false, ScannerEnable = false
            };
        }
Пример #10
0
        /// <summary>
        /// This Update Loop is used to :
        /// * Wait the Camera is really ready
        /// * Bring back Callback to the main thread when using Background Thread
        /// * To execute image Decoding When not using the background Thread
        /// </summary>
        public void Update()
        {
            // If not ready, wait
            if (!Camera.IsReady())
            {
                Log.Warning(this + " Camera Not Ready Yet ...");
                if (status != ScannerStatus.Initialize)
                {
                    Status = ScannerStatus.Initialize;
                }
                return;
            }

            // If the app start for the first time (select size & onReady Event)
            if (Status == ScannerStatus.Initialize)
            {
                if (WebcamInitialized())
                {
                    Log.Info(this + " Camera is Ready ", Camera);

                    Status = ScannerStatus.Paused;

                    if (OnReady != null)
                    {
                        OnReady.Invoke(this, EventArgs.Empty);
                    }
                }
            }

            if (Status == ScannerStatus.Running)
            {
                // Call the callback if a result is there
                if (Result != null)
                {
                    //
                    Log.Info(Result);
                    Callback(Result.Type, Result.Value);

                    // clean and return
                    Result = null;
                    parserPixelAvailable = false;
                    return;
                }

                // Get the image as an array of Color32
                pixels = Camera.GetPixels(pixels);
                parserPixelAvailable = true;

                // If background thread OFF, do the decode main thread with 500ms of pause for UI
                if (!Settings.ScannerBackgroundThread && mainThreadLastDecode < Time.realtimeSinceStartup - Settings.ScannerDecodeInterval)
                {
                    DecodeQR();
                    mainThreadLastDecode = Time.realtimeSinceStartup;
                }
            }
        }
Пример #11
0
        private void OnBarcodeRead(object sender, BarcodeReadEventArgs bre)
        {
            scannedData[0] = bre.strDataBuffer;

            if (Scanned != null)
            {
                Scanned.Invoke(this, new ScannedDataEventArgs(scannedData));
            }

            reader.ScannerOn = false;
            scannerStatus    = ScannerStatus.Opened;
        }
Пример #12
0
        private void OnWatcherStopped(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementWatcherStoppedEventArgs args)
        {
            if (_bluetoothLeAdvertisementWatcher != null)
            {
                Logger.Debug("Scanner: .OnWatcherStopped(): Status: " + _bluetoothLeAdvertisementWatcher.Status);

                Status = _bluetoothLeAdvertisementWatcher.Status == BluetoothLEAdvertisementWatcherStatus.Aborted ? ScannerStatus.Aborted : ScannerStatus.Stopped;

                _bluetoothLeAdvertisementWatcher.Received -= OnAdvertisementReceived;
                _bluetoothLeAdvertisementWatcher.Stopped  -= OnWatcherStopped;
                _bluetoothLeAdvertisementWatcher           = null;
            }
        }
Пример #13
0
        /// <summary>
        /// Start Scanning
        /// </summary>
        public void Scan()
        {
            if (reader == null || Status != ScannerStatus.Opened)
            {
                return;
            }

            scannerStatus = ScannerStatus.Scanning;
            Thread.Sleep(10);

            reader.Actions.ToggleSoftTrigger();
            timeout = new Timer(TimeoutCallback, this, TimeoutMilliseconds, Timeout.Infinite);
        }
Пример #14
0
        private void HandleData(ReaderData reader)
        {
            List <string> list = new List <string>();

            list.Add(reader.Text);

            if (Scanned != null)
            {
                Scanned.Invoke(this, new ScannedDataEventArgs(list.ToArray()));
            }

            scannerStatus = ScannerStatus.Opened;
        }
Пример #15
0
        /// <summary>
        /// This Update Loop is used to :
        /// * Wait the Camera is really ready
        /// * Bring back Callback to the main thread when using Background Thread
        /// * To execute image Decoding When not using the background Thread
        /// </summary>
        public void Update()
        {
            // If not ready, wait
            if (!Camera.IsReady())
            {
                Log.Warning("Camera Not Ready Yet ...");
                if (status != ScannerStatus.Initialize)
                {
                    Status = ScannerStatus.Initialize;
                }
                return;
            }

            // If the app start for the first time (select size & onReady Event)
            if (Status == ScannerStatus.Initialize)
            {
                Status = ScannerStatus.Paused;

                Camera.SetSize();
                if (OnReady != null)
                {
                    OnReady.Invoke(this, EventArgs.Empty);
                }
            }

            if (Status == ScannerStatus.Running)
            {
                // Call the callback if a result is there
                if (Result != null)
                {
                    //
                    Log.Info(Result);
                    Callback(Result.Type, Result.Value);

                    // clean and return
                    Result = null;
                    pixels = new Color32[0];
                    return;
                }

                // Get the image as an array of Color32
                pixels = Camera.GetPixels();

                // If background thread OFF, do the decode main thread with 500ms of pause for UI
                if (!useBackgroundThread && mainThreadLastDecode < Time.realtimeSinceStartup - 0.5f)
                {
                    DecodeQR();
                    mainThreadLastDecode = Time.realtimeSinceStartup;
                }
            }
        }
Пример #16
0
        private void HandleData(ReaderData data)
        {
            if (Scanned != null)
            {
                var barcodeData = new BarcodeData
                {
                    Text        = data.Text,
                    BarcodeType = (BarcodeTypes)data.Type
                };
                Scanned.Invoke(this, new ScannedDataEventArgs(new[] { barcodeData }));
            }

            scannerStatus = ScannerStatus.Opened;
        }
Пример #17
0
        public Scanner(ScannerSettings settings, IParser parser, IWebcam webcam)
        {
            Status = ScannerStatus.Initialize;

            // Default Properties
            Settings = (settings == null) ? new ScannerSettings() : settings;
            Parser   = (parser == null) ? new ZXingParser(Settings) : parser;
            Camera   = (webcam == null) ? new UnityWebcam(Settings) : webcam;
            // Check Device Authorization
            if (!Application.HasUserAuthorization(UserAuthorization.WebCam))
            {
                throw new Exception("This Webcam Library can't work without the webcam authorization");
            }
        }
Пример #18
0
        public Scanner(IParser parser = null, IWebcam webcam = null)
        {
            // Check Device Authorization
            if (!Application.HasUserAuthorization(UserAuthorization.WebCam))
            {
                throw new Exception("This Webcam Library can't work without the webcam authorization");
            }

            Status = ScannerStatus.Initialize;
            Parser = (parser == null) ? new ZXingParser() : parser;
            Camera = (webcam == null) ? new UnityWebcam() : webcam;

                        #if UNITY_WEBGL
            useBackgroundThread = false;
                        #endif
        }
Пример #19
0
        private void OnScannerStatusChanged(object sender, ScannerStatus e)
        {
            if (_startScannerTimer != null)
            {
                _startScannerTimer.Dispose();
                _startScannerTimer = null;
            }

            if (e != ScannerStatus.Started)
            {
                if (Configuration.AutoStartScanner)
                {
                    _startScannerTimer = new Timer(StartScannerTimerCallback, null, _startScannerIntervalInMilliseconds, Timeout.Infinite);
                }
            }
        }
Пример #20
0
        /// <summary>
        /// Called when the status of the scanner is changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OnScannerStatusChangedAsync(object sender, ScannerStatus e)
        {
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                AddLogEntry("Scanner status changed: " + e);

                switch (e)
                {
                case ScannerStatus.Stopped:
                    break;

                case ScannerStatus.Started:
                    if (_bluetoothNotOnDialogOperation != null)
                    {
                        _bluetoothNotOnDialogOperation.Cancel();
                        _bluetoothNotOnDialogOperation = null;
                    }

                    break;

                case ScannerStatus.Aborted:
                    if (_bluetoothNotOnDialogOperation == null)
                    {
                        MessageDialog messageDialog = new MessageDialog(
                            "Do you wish to enable Bluetooth on this device?",
                            "Failed to start Bluetooth LE advertisement watcher");

                        messageDialog.Commands.Add(new UICommand("Yes",
                                                                 new UICommandInvokedHandler((command) =>
                        {
                            _sdkManager.LaunchBluetoothSettingsAsync();
                        })));

                        messageDialog.Commands.Add(new UICommand("No",
                                                                 new UICommandInvokedHandler((command) =>
                        {
                            _sdkManager.StopScanner();
                        })));

                        _bluetoothNotOnDialogOperation = messageDialog.ShowAsync();
                    }

                    break;
                }
            });
        }
Пример #21
0
        /// <summary>
        /// Start Scanning
        /// </summary>
        public void Scan()
        {
            if (reader == null || scannerStatus != ScannerStatus.Opened)
            {
                return;
            }

            if (!reader.ScannerEnable)
            {
                return;
            }

            scannerStatus = ScannerStatus.Scanning;
            Thread.Sleep(10);

            reader.ScannerOn = true;
            timeout          = new Timer(TimeoutCallback, this, TIMEOUT_MS, Timeout.Infinite);
        }
Пример #22
0
        /// <summary>
        /// Close the scanner device
        /// </summary>
        public void Close()
        {
            if (reader == null)
            {
                scannerStatus = ScannerStatus.Closed;
                return;
            }

            StopRead();

            reader.Actions.Disable();
            reader.Dispose();
            reader = null;
            readerData.Dispose();
            readerData = null;

            scannerStatus = ScannerStatus.Closed;
        }
Пример #23
0
        /// <summary>
        /// Used to Stop Scanning internaly (can be forced)
        /// </summary>
        private void Stop(bool forced)
        {
            if (!forced && Callback == null)
            {
                Log.Warning("No Scan running");
                return;
            }

            // Stop thread / Clean callback
            Log.Info("SimpleScanner -> Stop Scan");
                        #if !UNITY_WEBGL
            if (CodeScannerThread != null)
            {
                CodeScannerThread.Abort();
            }
                        #endif
            Callback = null;
            Status   = ScannerStatus.Paused;
        }
Пример #24
0
        /// <summary>
        /// Closes the connection to the scanner
        /// </summary>
        public void Close()
        {
            if (Status != ScannerStatus.Opened)
            {
                return;
            }

            lock (syncLock)
            {
                running = false;
                scanningThread.Abort();
                scanningThread = null;

                var result = OBReadLibNet.Api.OBRClose();
                CheckCasioResult(result);

                Status = ScannerStatus.Closed;
            }
        }
Пример #25
0
        /// <summary>
        /// Used to start Scanning
        /// </summary>
        /// <param name="callback"></param>
        public void Scan(Action <string, string> callback)
        {
            if (Callback != null)
            {
                Log.Warning("Already Scan");
                return;
            }
            Callback = callback;

            Log.Info("SimpleScanner -> Start Scan");
            Status = ScannerStatus.Running;

                        #if !UNITY_WEBGL
            if (useBackgroundThread)
            {
                CodeScannerThread = new Thread(ThreadDecodeQR);
                CodeScannerThread.Start();
            }
                        #endif
        }
Пример #26
0
        /// <summary>
        /// Starts the watcher and hooks its events to callbacks.
        /// </summary>
        /// <param name="manufacturerId">The manufacturer ID.</param>
        /// <param name="beaconCode">The beacon code.</param>
        /// <param name="beaconExitTimeoutInMiliseconds">Time in miliseconds after beacon will be trated as lost.</param>
        /// <param name="rssiEnterThreshold">Optional rssi threshold which will trigger beacon discover event. Value must be between -128 and 127.</param>
        /// <param name="enterDistanceThreshold">Optional minimal distance in meters that will trigger beacon discover event.</param>
        public void StartWatcher(ushort manufacturerId, ushort beaconCode, ulong beaconExitTimeoutInMiliseconds, short?rssiEnterThreshold = null,
                                 ulong?enterDistanceThreshold = null)
        {
            _beaconExitTimeout      = beaconExitTimeoutInMiliseconds;
            _enterDistanceThreshold = enterDistanceThreshold;
            _beaconExitTimeout      = 30000;
            if (_beaconExitTimeout < 1000)
            {
                _beaconExitTimeout = 1000;
            }

            if (Status != ScannerStatus.Started)
            {
                if (_bluetoothLeAdvertisementWatcher == null)
                {
                    _bluetoothLeManufacturerData     = BeaconFactory.BeaconManufacturerData(manufacturerId, beaconCode);
                    _bluetoothLeAdvertisementWatcher = new BluetoothLEAdvertisementWatcher();
                    if (rssiEnterThreshold != null && rssiEnterThreshold.Value >= -128 && rssiEnterThreshold.Value <= 127)
                    {
                        _bluetoothLeAdvertisementWatcher.SignalStrengthFilter = new BluetoothSignalStrengthFilter()
                        {
                            InRangeThresholdInDBm = rssiEnterThreshold.Value
                        };
                    }
                    _bluetoothLeAdvertisementWatcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(_bluetoothLeManufacturerData);
                    _bluetoothLeAdvertisementWatcher.SignalStrengthFilter.SamplingInterval  = TimeSpan.FromMilliseconds(0);
                    _bluetoothLeAdvertisementWatcher.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(_beaconExitTimeout);
                    _bluetoothLeAdvertisementWatcher.ScanningMode = BluetoothLEScanningMode.Active;
                }

                _bluetoothLeAdvertisementWatcher.Received += OnAdvertisementReceived;
                _bluetoothLeAdvertisementWatcher.Stopped  += OnWatcherStopped;

                ServiceManager.LayoutManager?.VerifyLayoutAsync();

                _bluetoothLeAdvertisementWatcher.Start();

                Status = ScannerStatus.Started;
                Logger.Debug("Scanner.StartWatcher(): Watcher started");
            }
        }
Пример #27
0
        /// <summary>
        /// Open the scanner device
        /// </summary>
        public void Open()
        {
            if (scannerStatus == ScannerStatus.Opened)
            {
                return;
            }

            try
            {
                reader     = new Reader();
                readerData = new ReaderData(ReaderDataTypes.Text, ReaderDataLengths.MaximumLabel);
                reader.Actions.Enable();

                StartRead();

                scannerStatus = ScannerStatus.Opened;
            }
            catch
            {
                Close();
                throw;
            }
        }
Пример #28
0
        private void OnScannerStatusChanged(object sender, ScannerStatus e)
        {
            if (_startScannerTimer != null)
            {
                _startScannerTimer.Dispose();
                _startScannerTimer = null;
            }

            if (e != ScannerStatus.Started)
            {
                Scanner.BeaconEvent -= OnBeaconEventAsync;
                
                if (_scannerShouldBeRunning)
                {
                    _startScannerTimer = new Timer(StartScannerTimerCallback, null, StartScannerIntervalInMilliseconds, Timeout.Infinite);
                }
            }
        }
Пример #29
0
 /// <summary>
 ///     Create an instance of the Symbol Barcode Scanner device
 /// </summary>
 public SymbolScanner()
 {
     scanEvent     = ScannedDataEvent;
     scannerStatus = ScannerStatus.Closed;
 }
Пример #30
0
 void mScanner_Scanner(ScannerStatus s)
 {
     try
     {
         Invoke(new ConnectedDelegate(SetStatus), s);
     }
     catch (Exception e)
     {
         Logger.Instance.Log(e);
     }
 }
Пример #31
0
        /// <summary>
        /// Starts the watcher and hooks its events to callbacks.
        /// </summary>
        /// <param name="manufacturerId">The manufacturer ID.</param>
        /// <param name="beaconCode">The beacon code.</param>
        /// <param name="beaconExitTimeoutInMiliseconds">Time in miliseconds after beacon will be trated as lost.</param>
        /// <param name="rssiEnterThreshold">Optional rssi threshold which will trigger beacon discover event. Value must be between -128 and 127.</param>
        /// <param name="enterDistanceThreshold">Optional minimal distance in meters that will trigger beacon discover event.</param>
        public void StartWatcher(ushort manufacturerId, ushort beaconCode, ulong beaconExitTimeoutInMiliseconds, short? rssiEnterThreshold = null,
            ulong? enterDistanceThreshold = null)
        {
            _beaconExitTimeout = beaconExitTimeoutInMiliseconds;
            _enterDistanceThreshold = enterDistanceThreshold;
            _beaconExitTimeout = 30000;
            if (_beaconExitTimeout < 1000)
            {
                _beaconExitTimeout = 1000;
            }

            if (Status != ScannerStatus.Started)
            {
                if (_bluetoothLeAdvertisementWatcher == null)
                {
                    _bluetoothLeManufacturerData = BeaconFactory.BeaconManufacturerData(manufacturerId, beaconCode);
                    _bluetoothLeAdvertisementWatcher = new BluetoothLEAdvertisementWatcher();
                    if (rssiEnterThreshold != null && rssiEnterThreshold.Value >= -128 && rssiEnterThreshold.Value <= 127)
                    {
                        _bluetoothLeAdvertisementWatcher.SignalStrengthFilter = new BluetoothSignalStrengthFilter() { InRangeThresholdInDBm = rssiEnterThreshold.Value };
                    }
                    _bluetoothLeAdvertisementWatcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(_bluetoothLeManufacturerData);
                    _bluetoothLeAdvertisementWatcher.SignalStrengthFilter.SamplingInterval = TimeSpan.FromMilliseconds(0);
                    _bluetoothLeAdvertisementWatcher.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(_beaconExitTimeout);
                    _bluetoothLeAdvertisementWatcher.ScanningMode = BluetoothLEScanningMode.Active;
                }

                _bluetoothLeAdvertisementWatcher.Received += OnAdvertisementReceived;
                _bluetoothLeAdvertisementWatcher.Stopped += OnWatcherStopped;

                ServiceManager.LayoutManager?.VerifyLayoutAsync();

                _bluetoothLeAdvertisementWatcher.Start();

                Status = ScannerStatus.Started;
                Logger.Debug("Scanner.StartWatcher(): Watcher started");
            }
        }
Пример #32
0
        private void OnWatcherStopped(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementWatcherStoppedEventArgs args)
        {
            if (_bluetoothLeAdvertisementWatcher != null)
            {
                Logger.Debug("Scanner: .OnWatcherStopped(): Status: " + _bluetoothLeAdvertisementWatcher.Status);

                Status = _bluetoothLeAdvertisementWatcher.Status == BluetoothLEAdvertisementWatcherStatus.Aborted ? ScannerStatus.Aborted : ScannerStatus.Stopped;

                _bluetoothLeAdvertisementWatcher.Received -= OnAdvertisementReceived;
                _bluetoothLeAdvertisementWatcher.Stopped -= OnWatcherStopped;
                _bluetoothLeAdvertisementWatcher = null;
            }
        }
Пример #33
0
 /// <summary>
 /// Create new Scanner Object.
 /// </summary>
 public Scanner()
 {
     _status = ScannerStatus.Stopped;
 }
Пример #34
0
 /// <summary>
 /// Create new Scanner Object.
 /// </summary>
 public Scanner()
 {
     _status = ScannerStatus.Stopped;
 }
Пример #35
0
        /// <summary>
        /// Called when the status of the scanner is changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OnScannerStatusChangedAsync(object sender, ScannerStatus e)
        {
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                AddLogEntry("Scanner status changed: " + e);

                switch (e)
                {
                    case ScannerStatus.Stopped:
                        break;

                    case ScannerStatus.Started:
                        if (_bluetoothNotOnDialogOperation != null)
                        {
                            _bluetoothNotOnDialogOperation.Cancel();
                            _bluetoothNotOnDialogOperation = null;
                        }

                        break;

                    case ScannerStatus.Aborted:
                        if (_bluetoothNotOnDialogOperation == null)
                        {
                            MessageDialog messageDialog = new MessageDialog(
                                "Do you wish to enable Bluetooth on this device?",
                                "Failed to start Bluetooth LE advertisement watcher");

                            messageDialog.Commands.Add(new UICommand("Yes",
                                new UICommandInvokedHandler((command) =>
                                {
                                    _sdkManager.LaunchBluetoothSettingsAsync();
                                })));

                            messageDialog.Commands.Add(new UICommand("No",
                                new UICommandInvokedHandler((command) =>
                                {
                                    _sdkManager.StopScanner();
                                })));

                            _bluetoothNotOnDialogOperation = messageDialog.ShowAsync();
                        }

                        break;
                }
            });
        }
        private async void OnScannerStatusChangedAsync(object sender, ScannerStatus e)
        {
            System.Diagnostics.Debug.WriteLine("MainPage.OnScannerStatusChangedAsync(): " + e);

            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                IsScanning = (e == ScannerStatus.Started);

                switch (e)
                {
                    case ScannerStatus.Stopped:
                        toggleScanButton.IsChecked = true;
                        toggleScanButton.Label = "start scanner";
                        UnhookScannerEvents();
                        break;

                    case ScannerStatus.Started:
                        if (_bluetoothNotOnDialogOperation != null)
                        {
                            _bluetoothNotOnDialogOperation.Cancel();
                            _bluetoothNotOnDialogOperation = null;
                        }

                        toggleScanButton.IsChecked = false;
                        toggleScanButton.Label = "stop scanner";
                        break;

                    case ScannerStatus.Aborted:
                        toggleScanButton.IsChecked = true;
                        toggleScanButton.Label = "start scanner";

                        if (_bluetoothNotOnDialogOperation == null)
                        {
                            MessageDialog messageDialog = new MessageDialog(
                                "Do you wish to enable Bluetooth on this device?",
                                "Failed to start Bluetooth LE advertisement watcher");

                            messageDialog.Commands.Add(new UICommand("Yes",
                                new UICommandInvokedHandler((command) =>
                                {
                                    _sdkManager.LaunchBluetoothSettingsAsync();
                                })));

                            messageDialog.Commands.Add(new UICommand("No",
                                new UICommandInvokedHandler((command) =>
                                {
                                    _sdkManager.StopScanner();
                                    _bluetoothNotOnDialogOperation = null;
                                })));

                            _bluetoothNotOnDialogOperation = messageDialog.ShowAsync();
                        }

                        break;
                }

                toggleScanButton.IsEnabled = true;
            });
        }
Пример #37
0
 /// <summary>
 /// Create an instance of the Symbol Barcode Scanner device
 /// </summary>
 public SymbolScanner()
 {
     scanEvent     = new EventHandler(ScannedDataEvent);
     scannerStatus = ScannerStatus.Closed;
 }
Пример #38
0
        private void OnScannerStatusChanged(object sender, ScannerStatus e)
        {
            if (_startScannerTimer != null)
            {
                _startScannerTimer.Dispose();
                _startScannerTimer = null;
            }

            if (e != ScannerStatus.Started)
            {
                if (Configuration.AutoStartScanner)
                {
                    _startScannerTimer = new Timer(StartScannerTimerCallback, null, _startScannerIntervalInMilliseconds, Timeout.Infinite);
                }
            }
        }