Create a BluetoothLEDevice from DeviceInformation?

0

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)"}

c#
bluetooth
bluetooth-lowenergy
uwp
asked on Stack Overflow May 18, 2016 by LAK132

2 Answers

1

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!

answered on Stack Overflow May 20, 2016 by Christopher Brown
0

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);
answered on Stack Overflow May 24, 2016 by Carter

User contributions licensed under CC BY-SA 3.0