【问题标题】:How do I configure a WPF project to use BLE?如何配置 WPF 项目以使用 BLE?
【发布时间】:2018-10-10 01:03:06
【问题描述】:

更新 2: 以下是我目前所处位置的详细信息,但我不希望这些细节破坏任何可能与在 WPF 中找到通向 BLE / GATT 的任何路径的基本问题有关的一般性答案。

构建系统版本:

Microsoft Visual Studio Community 2017 
Version 15.7.4
VisualStudio.15.Release/15.7.4+27703.2035
Microsoft .NET Framework
Version 4.7.03056

到目前为止,我已将项目文件更改为目标 windows 8.1,<TargetPlatformVersion>8.1</TargetPlatformVersion>

目前,我正在获取本地 BLE 广告,但是当我尝试访问 GATT 服务时:

var _service = await GattDeviceService.FromIdAsync(deviceId);

更新 1: 我试图包括 WinRT。 这是我的参考及其属性:

任何帮助将不胜感激。

【问题讨论】:

  • 事实上WinRT根本没有这样的dll。可能你引用了错误的东西。您是否使用 WinMD 导入了 WinRT?
  • @MikePetrichenko 我在上面做了更新。这能回答你的问题吗?
  • 看来你必须参考一些其他文件:docs.microsoft.com/en-us/windows/uwp/porting/…
  • @MikePetrichenko 谢谢你的链接。我会按照说明处理并尽快回复您。
  • 我的印象是 GATT for BLE 直到 Win10 才可用,甚至一开始也不可用(Creator's Update,2017 年)。见blogs.windows.com/buildingapps/2017/01/13/…。请注意,LE 外设支持 GATT 客户端模式。哦,正如@MikePetrichenko 指出的那样,WPF 并不直接执行 BLE。我错过了什么吗?

标签: c# bluetooth bluetooth-lowenergy gatt


【解决方案1】:

安装Windows 10 SDK

然后添加三个引用:

Windows
Windows.Foundation.FoundationContract
WindowsBase

然后在属性中将'Copy Local'设置为'true'。

可能的位置提示:

D:\Windows Kits\10\UnionMetadata\10.0.17134.0\Windows.winmd
D:\Windows Kits\10\References\10.0.17134.0\Windows.Foundation.FoundationContract\3.0.0.0\en\Windows.Foundation.FoundationContract.xml
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\WindowsBase.dll

确保在目标机器上进行全面更新。在撰写本文时,有一些项目在 Win10 更新完成之前无法正常工作。

另一种可能的方法是通过 NuGet UWP-Desktop,尽管我从来没有机会尝试。

【讨论】:

    猜你喜欢
    • 2010-09-07
    • 2011-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 2011-10-23
    • 1970-01-01
    • 2011-12-29
    相关资源
    最近更新 更多