How do I connect to a Bluetooth LE device from a DLL

1

How do I connect to a Bluetooth LE device from a DLL I am using VS2015 to build a dll in a .net Framework project on a Windows 10 machine I will eventually call the dll from LabVIEW I can discover BLE (Bluetooth Low Energy) devices by creating a deviceWatcher From the DeviceWatcher I select a Device which gives me a DeviceInfo.Id like "BluetoothLE#BluetoothLE9c:b6:d0:ca:1f:14-80:1f:12:b5:d8:dc" When I try to connect using: BluetoothLEDevice = await BluetoothLEDevice.FromIdAsync(DeviceInfo.Id) I get the following error: System.InvalidOperationException, HResult=0x8000000E, A method was called at an unexpected time. Could not create a new view because the main window has not yet been created

When I try to connect using:

Await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunTaskAsync(async () =>
{ BluetoothLEDevice = await BluetoothLEDevice.FromIdAsync(DeviceInfo.Id); });

I get the same error.

It looks as if I need to have a “main window”, which the dll does not. How do I create a main window for the FromIdAsync to run in?

Useful links I have found, BluetoothLEExplorer https://github.com/Microsoft/BluetoothLEExplorer UWP App that demonstrates BLE connectivity BLEConsole https://sensboston.github.io/BLEConsole/ Console App with scripting Both the above use BluetoothLEDevice.FromIdAsync to create the connection

windows
bluetooth
asked on Stack Overflow Jan 14, 2020 by SteveE • edited Jan 14, 2020 by Vadim Kotov

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0