示例#1
0
 /// <summary>
 /// This method wraps the traditional scan, but waits for the centralManager to be ready before initiating scan
 /// </summary>
 /// <param name="centralManager">The centralManager to scan with</param>
 /// <param name="restart">Stops any current scan running</param>
 /// <param name="config">ScanConfig parameters you would like to use</param>
 /// <returns></returns>
 public static IObservable <IScanResult> Scan(this ICentralManager centralManager, ScanConfig?config = null, bool restart = false)
 {
     if (restart && centralManager.IsScanning)
     {
         centralManager.StopScan(); // need a pause to wait for scan to end
     }
     return(centralManager.Scan(config));
 }
示例#2
0
        public void GetConnectedDevices()
        {
            _connectedDisposable = _centralManager.GetConnectedPeripherals().Subscribe(scanResult =>
            {
                scanResult.ToList().ForEach(
                    item =>
                {
                    if (!string.IsNullOrEmpty(item.Name))
                    {
                        BluetoothDevices.Add(item);
                    }
                });

                _connectedDisposable?.Dispose();
            });

            if (_centralManager.IsScanning)
            {
                _centralManager.StopScan();
            }
        }