public async void StartScanningForDevices(Guid serviceUuid) { await WaitForState(CBCentralManagerState.PoweredOn); Debug.WriteLine("Adapter: Starting a scan for devices."); CBUUID[] serviceUuids = null; // TODO: convert to list so multiple Uuids can be detected if (serviceUuid != Guid.Empty) { var suuid = CBUUID.FromString(serviceUuid.ToString()); serviceUuids = new CBUUID[] { suuid }; Debug.WriteLine("Adapter: Scanning for " + suuid); } // clear out the list DiscoveredDevices = new List <IDevice>(); // start scanning IsScanning = true; CentralManager.ScanForPeripherals(serviceUuids); // in 10 seconds, stop the scan await Task.Delay(10000); // if we're still scanning if (IsScanning) { Console.WriteLine("Adapter: Scan timeout has elapsed."); IsScanning = false; CentralManager.StopScan(); ScanTimeoutElapsed(this, new EventArgs()); } }
/// <summary> /// Begins the scanning for bluetooth LE devices. Automatically called after 10 seconds /// to prevent battery drain. /// </summary> /// <returns>The scanning for devices.</returns> public async Task BeginScanningForDevices() { Console.WriteLine("BluetoothLEManager: Starting a scan for devices."); // clear out the list DiscoveredDevices = new List <CBPeripheral>(); // start scanning IsScanning = true; CentralManager.ScanForPeripherals(peripheralUuids: null); // in 10 seconds, stop the scan await Task.Delay(10000); // if we're still scanning if (IsScanning) { Console.WriteLine("BluetoothLEManager: Scan timeout has elapsed."); CentralManager.StopScan(); ScanTimeoutElapsed(this, new EventArgs()); } }