private async static void ConnectedDevicesWithServiceGuidAsync(Guid guid) { List <GattDevice> returnDevices = new List <GattDevice>(); DeviceInformationCollection infos = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(guid)); if (infos.Count > 0) { Debug.Log("Found " + infos.Count + " Devices"); foreach (DeviceInformation info in infos) { string deviceID = info.Id; Debug.Log("Device Name: " + info.Name); try { BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceID); GattDevice d = GattDevice.Create(device); returnDevices.Add(d); } catch { } } } OnDevicesAcquired?.Invoke(returnDevices); }
private async static void DevicesWithConnectionStatusAsync(bool Connected) { List <GattDevice> returnDevices = new List <GattDevice>(); string filter = BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(Connected ? BluetoothConnectionStatus.Connected : BluetoothConnectionStatus.Disconnected); DeviceInformationCollection infos = await DeviceInformation.FindAllAsync(filter); if (infos.Count > 0) { Debug.Log("Found " + infos.Count + " Devices"); foreach (DeviceInformation info in infos) { string deviceID = info.Id; Debug.Log("Device Name: " + info.Name); try { BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceID); GattDevice d = GattDevice.Create(device); returnDevices.Add(d); } catch { } } } OnDevicesAcquired?.Invoke(returnDevices); /*Debug.Log("Found " + infos.Count + " Devices"); * foreach (DeviceInformation info in infos) * { * Debug.Log("Device Name: " + info.Name); * }*/ }
/// <summary> /// Gets all devices based on their pairing state. Takes much longer to find unpaired devices than paired devices /// </summary> /// <param name="Connected">True to look for paired devices, false to look for unpaired devices</param> public static void DevicesWithPairingStatus(bool Paired) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { List <GattDevice> returnDevices = new List <GattDevice>(); string filter = BluetoothLEDevice.GetDeviceSelectorFromPairingState(Paired); DeviceInformationCollection infos = await DeviceInformation.FindAllAsync(filter); if (infos.Count > 0) { Debug.Log("Found " + infos.Count + " Devices"); foreach (DeviceInformation info in infos) { string deviceID = info.Id; Debug.Log("Device Name: " + info.Name); try { BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceID); GattDevice d = GattDevice.Create(device); returnDevices.Add(d); } catch { } } } OnDevicesAcquired?.Invoke(returnDevices); } ); }
private static async void GetDeviceAsync(GattInformation info) { GattDevice dev = null; // We must update the collection on the UI thread await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(info.Id); dev = GattDevice.Create(device); }); if (dev != null) { OnDeviceCreated?.Invoke(dev); } }