简体   繁体   English

用于Windows桌面C#应用程序的蓝牙4.0(低能耗)API

[英]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.) 我正在寻找一种与Adafruit蓝莓LE(nRF8001芯片组)板接口的方法,在Windows桌面应用程序中使用c#(从我所见,我不能使用Windows.Devices命名空间而不进行黑客入侵。)

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. 必须有一种方法可以做到这一点,我不能认为微软会限制只使用蓝牙到Metro应用程序,我只是无法找到它。

So, for posterity: 因此,后人:

  1. Everywhere on the net says to put the below in your csproj file: 网上的任何地方都说将以下内容放在你的csproj文件中:

    <PropertyGroup> <TargetPlatformVersion>8.0</TargetPlatformVersion> </PropertyGroup> <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. 如果您运行的是Windows 8.1,则实际上这是不正确的,您必须将8.1放在那里而不是8.0。 This change will allow you to reference the "Windows" assembly in the windows -> core section of the references dialog. 此更改将允许您在引用对话框的窗口 - >核心部分中引用“Windows”程序集。 Putting 8.0 there gets you a bunch of other things there that you don't want. 将8.0放在那里可以获得一些你不想要的其他东西。

  1. you also have to reference this dll: 你还必须引用这个DLL:

C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETCore\\v4.5.1\\System.Runtime.WindowsRuntime.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. 其中包含允许您在Windows.Foundation.IAsyncOperation实例上使用常规等待调用的扩展方法。 This is required because those instances don't contain the GetAwaiter method that the await keyword looks for. 这是必需的,因为这些实例不包含await关键字查找的GetAwaiter方法。

After that you should be able to use the WinRT API in your desktop application. 之后,您应该能够在桌面应用程序中使用WinRT API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM