Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bluetooth 4.0 (low energy) API for windows desktop C# application

I am looking for a way to interface with an Adafruit bluefruit LE (nRF8001 chipset) board, using c# in a windows desktop app (From what I've seen, I cannot use the Windows.Devices namespace without hacking it in.)

The device is properly paired to my tablet and seems to have no problems there, I'm just looking for a way to receive data from it in my program.

There has to be a way to do this, I cant think that Microsoft would limit using bluetooth to metro apps only, I just cant find it.

like image 222
Patrick Avatar asked Jan 31 '15 20:01

Patrick


People also ask

Does Bluetooth 4.0 have low energy?

Versions 4.0 – 5.0: Bluetooth Low Energy In order to meet the increasing demand for wireless connectivity between small devices, Bluetooth 4.0 was introduced to the market with a new category of Bluetooth: Bluetooth Low Energy (BLE).

Does Windows support Bluetooth Low Energy?

Select Device Manager. Select Bluetooth from the sidebar on the left. This will expand to show Bluetooth drivers. If there is a driver named Microsoft Bluetooth LE Enumerator then your Windows 10 computer supports Bluetooth Low Energy.

Does Windows 7 support Bluetooth Low Energy?

Windows 7 and 8 don't have any Bluetooth Low Energy (BLE) support whatsoever so you will need to use a USB Bluetooth dongle in order to connect the Tracker. The USB Bluetooth dongle must be BLE compatible and must use a CSR8510 A10 chipset.


1 Answers

So, for posterity:

  1. Everywhere on the net says to put the below in your csproj file:

    <PropertyGroup> <TargetPlatformVersion>8.0</TargetPlatformVersion> </PropertyGroup>

This is actually incorrect if you are running windows 8.1, you have to put 8.1 there instead of 8.0. This change will allow you to reference the "Windows" assembly in the windows -> core section of the references dialog. Putting 8.0 there gets you a bunch of other things there that you don't want.

  1. you also have to reference this dll:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5.1\System.Runtime.WindowsRuntime.dll

Which contains extension methods that allow you to use regular await calls on Windows.Foundation.IAsyncOperation instances. This is required because those instances don't contain the GetAwaiter method that the await keyword looks for.

After that you should be able to use the WinRT API in your desktop application.

like image 189
Patrick Avatar answered Nov 07 '22 11:11

Patrick