public static async Task <ImbleDevice> ConnectAsync(BluetoothLEDevice device, CancellationToken cancellationToken) { var imble = new ImbleDevice(); await imble.Initialize(device.DeviceInformation, device.BluetoothAddress, cancellationToken); return(imble); }
/// <summary> /// Connect to an unconnected IMBLE device. /// </summary> /// <param name="device">An UnconnectedImbleDevice instance corresponding to the IMBLE device to connect to.</param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task <ImbleDevice> ConnectAsync(UnconnectedImbleDevice device, CancellationToken cancellationToken) { var imble = new ImbleDevice(); // I tried to use DeviceInformation.FindAllAsync combined with BluetoothLEDevice.GetDeviceSelectorFromBluetoothAddress // to obtain a device information corresponding to a Bluetooth address. // But this implementation is not feasible because DeviceInformation.FindAllAsync takes 10 to 20 seconds. // Thus, I've decided to use BluetoothLEDevice.FromBluetoothAddressAsync instead of DeviceInformation.FindAllAsync. var bleDevice = await BluetoothLEDevice.FromBluetoothAddressAsync(device.Address); var deviceInformation = bleDevice.DeviceInformation; bleDevice.Dispose(); // Do not forget to dispose BLE related objects. await imble.Initialize(deviceInformation, device.Address, cancellationToken); return(imble); }
public static async Task<ImbleDevice> ConnectAsync(BluetoothLEDevice device, CancellationToken cancellationToken) { var imble = new ImbleDevice(); await imble.Initialize(device.DeviceInformation, device.BluetoothAddress, cancellationToken); return imble; }
/// <summary> /// Connect to an unconnected IMBLE device. /// </summary> /// <param name="device">An UnconnectedImbleDevice instance corresponding to the IMBLE device to connect to.</param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task<ImbleDevice> ConnectAsync(UnconnectedImbleDevice device, CancellationToken cancellationToken) { var imble = new ImbleDevice(); // I tried to use DeviceInformation.FindAllAsync combined with BluetoothLEDevice.GetDeviceSelectorFromBluetoothAddress // to obtain a device information corresponding to a Bluetooth address. // But this implementation is not feasible because DeviceInformation.FindAllAsync takes 10 to 20 seconds. // Thus, I've decided to use BluetoothLEDevice.FromBluetoothAddressAsync instead of DeviceInformation.FindAllAsync. var bleDevice = await BluetoothLEDevice.FromBluetoothAddressAsync(device.Address); var deviceInformation = bleDevice.DeviceInformation; bleDevice.Dispose(); // Do not forget to dispose BLE related objects. await imble.Initialize(deviceInformation, device.Address, cancellationToken); return imble; }