private async Task OnDevicesChangedAsync() { List <ObservableBluetoothLEDevice> devices = new List <ObservableBluetoothLEDevice>(BLE_HELPER.BluetoothLeDevices); foreach (ObservableBluetoothLEDevice device in devices) { if (string.Equals(device.BluetoothAddressAsString.ToLowerInvariant(), targetMac)) { SetState(BLEScannerState.CONNECTING); BLEDevice bleDevice = await BLEDevice.FromIdAsync(device.DeviceInfo.Id); if (!(bleDevice is null)) { // Try to connect to the device: if (await bleDevice.ConnectAsync()) { // Invoke event: DeviceFound?.Invoke(this, new BLEDeviceEventArgs(bleDevice)); return; } } SetState(BLEScannerState.SCANNING); } } }
private async Task OnDevicesChangedAsync() { List <ObservableBluetoothLEDevice> devices = new List <ObservableBluetoothLEDevice>(BLE_HELPER.BluetoothLeDevices); foreach (ObservableBluetoothLEDevice device in devices) { if (string.Equals(device.BluetoothAddressAsString.ToLowerInvariant(), targetMac)) { BLEDevice bleDevice = await BLEDevice.FromIdAsync(device.DeviceInfo.Id); if (!(bleDevice is null)) { // Try to connect to the device: if (await bleDevice.ConnectAsync()) { // Execute the challenge response mechanism: if (await bleDevice.UnlockAsync()) { // Invoke event: DeviceFound?.Invoke(this, new BLEDeviceEventArgs(bleDevice)); return; } } } } } }