Is there any way to use Bluetooth LE from a c# desktop app in windows 10?

13,213

Solution 1

You can use C# APIs in C# Desktop applications! I have a sample here in GitHub.

In general, to get access to the C# APIS, add two references to your project:

  1. C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
  2. C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll

Note that the #2 version depends on the version of .NET that you're using.

Background tasks will not be supported, but all other Bluetooth C# features should be there.

Solution 2

I have worked with and around the Microsoft partial Bluetooth API solutions since the XP days. I found a library from BTFramework that I have used extensively, on many platforms and in several languages. The Bluetooth Classic and Low Energy API packages from BTFramework have been easy to use, very reliable, and they've been super-responsive to any defects I did find. Our commercial product, as a result, has zero failures arising from the Bluetooth side. The team at BTFramework has taken on the job of working around Microsoft's partial implementations of the standard. We mainly code in C# dot NET, by the way. And we use many threads in the application.

Share:
13,213
Cedric Mamo
Author by

Cedric Mamo

Autodidact

Updated on July 23, 2022

Comments

  • Cedric Mamo
    Cedric Mamo almost 2 years

    Everything I found online regarding bluetooth LE requires a universal windows app, which is completely unsuitable for me.

    Is there a way to use bluetooth LE from c# without having to write my whole app as on UWP?

  • Cedric Mamo
    Cedric Mamo almost 8 years
    I tried that. Worked on windows 8, couldn't get it to work on windows 10 though. I have no idea what I did wrong. Also the bluetooth LE api is severely limited in windows 8. So while I can target the windows 8 ones and still run in windows 10, that just won't work for me. I need to use windows 10's bluetooth LE api
  • Carter
    Carter almost 8 years
    @CedricMamo Just tried doing this myself- updating the answer now!
  • Raven
    Raven about 7 years
    It seems #2 can be found under a different path on my os C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.‌​WindowsRuntime.dll
  • uSlackr
    uSlackr over 5 years
    What would it take to access this from PowerShell?
  • Jake Smith
    Jake Smith over 5 years
    If I add these two references, I still don't have access to Windows.Devices
  • batpox
    batpox over 4 years
    Thanks for the reference. Sometimes a 3rd party solution to a particularly thorny problem is the sensible answer. I will check them out...
  • Amir Mahdi Nassiri
    Amir Mahdi Nassiri almost 3 years
    Looks like the Windows SDK references can be added by installing the Microsoft.Windows.SDK.Contracts NuGet package
  • JustAMartin
    JustAMartin over 2 years
    @AmirMahdiNassiri I tried - it doesn't recognize "Windows.Devices".
  • qwlice
    qwlice over 2 years
    The file C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd is not there also after the latest update
  • Admin
    Admin over 2 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.