internal async Task <bool> ObtainBleDevice() { if (BleDevice != null) { return(true); } try { BleDevice = await BluetoothLEDevice.FromIdAsync(BleID); } catch (Exception) { if (BleDevice != null) { BleDevice.Dispose(); } BleDevice = null; } if (BleDevice == null) { return(false); } BleDevice.ConnectionStatusChanged += BleConnectionStatusChanged; BleDevice.NameChanged += BleNameChanged; BleDevice.GattServicesChanged += BleServiceChanged; if (BleDevice.ConnectionStatus == BluetoothConnectionStatus.Connected) { BleConnectionStateChangedObservers?.Invoke(this, BleDevice, BleDevice.ConnectionStatus); } return(true); }
/////////////////////////////////////////////////////////////////////////////////////////////////// // Bluetooth LE Event Handlers private void BleConnectionStatusChanged(BluetoothLEDevice sender, object args) { Log($"BleConnectionStatusChanged({sender.Name}, {sender.ConnectionStatus})"); BleConnectionStateChangedObservers?.Invoke(this, sender, sender.ConnectionStatus); }