【问题标题】:Connecting to bluetooth device using BluetoothLEDevice.FromIdAsync results in errors [duplicate]使用 BluetoothLEDevice.FromIdAsync 连接到蓝牙设备会导致错误 [重复]
【发布时间】:2017-10-13 20:46:45
【问题描述】:

我正在使用 Unity 为 hololens 构建一个应用程序。我想连接蓝牙设备。我开始在 Visual Studio 中构建一个插件,我可以从我的 Unity 项目中调用它来查找并连接到使用蓝牙的设备。 我使用了微软关于这个项目的文档:https://docs.microsoft.com/en-us/windows/uwp/devices-sensors/gatt-client

附近设备的查询就像一个魅力。调用此函数后,事件会在找到或删除设备时正确启动。但是,当尝试使用 BluetootLEDevice.FromIdAsync() 创建连接到设备的功能时,出现以下错误:

ErrorCS4036'IAsyncOperation' 不包含“GetAwaiter”的定义,并且找不到接受“IAsyncOperation”类型的第一个参数的扩展方法“GetAwaiter”(您是否缺少“System”的 using 指令?)

虽然我使用的是系统参考,所以我在这里做错了什么?这是我正在使用的代码:

private static async void ConnectDevice(string deviceInfoID)
    {
        // Note: BluetoothLEDevice.FromIdAsync must be called from a UI thread because it may prompt for consent.
        BluetoothLEDevice bluetoothLeDevice = await BluetoothLEDevice.FromIdAsync(deviceInfoID);
    }

【问题讨论】:

  • 您是否错过了课程开始时的“使用系统”参考?
  • 不,我写的第一行
  • 添加这两个引用:C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmdC:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll。确切路径取决于您的操作系统和框架版本。
  • @ManfredRadlwimmer 我现在可以连接到设备,但下一个问题来了。当我尝试使用以下方法获取 GattDeviceServicesResult 时: GattDeviceServicesResult result = await connectedDevice.GetGattServicesAsync();它说我缺少另一个 using 指令或程序集参考。我还必须添加什么?
  • 嗯……大概吧。它确切地说是什么意思?您可能需要再次在IAsyncOperation<>Task<> 之间进行转换,否则您会遗漏其他内容……如果没有实际代码,很难说。是 VS 在抱怨还是已经在 Unity 中了?

标签: c# .net windows uwp hololens


【解决方案1】:

我的回答迟了,但我一直在努力解决同样的问题,解决方案是包含这个 .dll "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    • 1970-01-01
    • 2010-10-21
    • 2012-03-31
    相关资源
    最近更新 更多