LAK132
LAK132

Reputation: 193

Create a BluetoothLEDevice from DeviceInformation?

Is it possible to create a BluetoothLEDevice from a DeviceInformation object? I've tried using the DeviceInformation's Id property in BluetoothLEDevice .FromIdAsync however that just throws errors

    public static async Task<BluetoothLEDevice> DeviceFromDeviceInfo(DeviceInformation x)
    {
        try {
            string g = x.Id.Substring(x.Id.IndexOf("{") + 1);
            g = g.Remove(g.IndexOf("}"));
            return await BluetoothLEDevice.FromIdAsync(g);
        }
        catch (Exception e){
            throw e;
        }
    }

This throws {"Element not found. (Exception from HRESULT: 0x80070490)"}

Upvotes: 0

Views: 1387

Answers (2)

Carter
Carter

Reputation: 3093

So long as the device you are trying to access is paired, you should be able to access it. I'm not sure why you're modifying the Id. To create the device all you need is:

DeviceInformation deviceInfo = __;
BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceInfo.Id);

Upvotes: 0

Christopher Brown
Christopher Brown

Reputation: 166

I'm running into the same issue with a Heart Rate Device. With a regular Bluetooth (not LE) device your code should work once it's connected. However, with BTLE the goal is to discover the device without the user having to pair it first. I don't have an answer for that part. Using Windows 8.1 it wasn't possible MSDN Forum Post (2014), MVP Blog Post (2014), but I'm hoping it's possible with Windows 10 Universal Apps.

There are a lot of unanswered Bluetooth LE discovery and scanning posts on Stackoverflow which isn't encouraging. Hopefully we get an answer soon!

Upvotes: 1

Related Questions