相关疑难解决方法(0)

FromBluetoothAddressAsync IAsyncOperation不包含"GetAwaiter"错误的定义

我正在研究一个简单的流行语.我一直在提到这段代码

我在视觉工作室2017工作.

我的核心代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Threading;


using Windows.Devices.Bluetooth.Advertisement;
using Windows.Devices.Bluetooth;
using Windows.Devices;
using Windows.Foundation;
using Windows;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {

        private BluetoothLEAdvertisementWatcher watcher;

        public Form1()
        {

            InitializeComponent();
            watcher = new BluetoothLEAdvertisementWatcher();

            watcher.Received += OnAdvertisementReceived;
        }

        private async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
        {
            var dev = await BluetoothLEDevice.FromBluetoothAddressAsync(eventArgs.BluetoothAddress);

            }


    }
Run Code Online (Sandbox Code Playgroud)

在该行中var dev = await BluetoothLEDevice.FromBluetoothAddressAsync(eventArgs.BluetoothAddress) …

c# bluetooth async-await

9
推荐指数
2
解决办法
4069
查看次数

FromBluetoothAddressAsync永远不会在WPF应用程序中的Windows 10 Creators Update上返回

我升级到Windows 10,版本1703 build 15063(Creators Update)正式发布.当我在WPF桌面应用程序中运行以下代码时,BluetoothLEDevice.FromBluetoothAddressAsync永远不会返回.

在我的Windows 10更新之前(即之前的1607版本14393),此代码工作正常.如果在新的Win 10 1703中作为UWP运行,此代码也可以正常工作.

BluetoothLEAdvertisementWatcher BleWatcher = null;

private void Button_Click(object sender, RoutedEventArgs e)
{
     BleWatcher = new BluetoothLEAdvertisementWatcher
     {
          ScanningMode = BluetoothLEScanningMode.Active
     };
     BleWatcher.Received += Watcher_Received;
     BleWatcher.Start();
}

private async void Watcher_Received(BluetoothLEAdvertisementWatcher sender, 
                                    BluetoothLEAdvertisementReceivedEventArgs args)
{
         var device = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress);
         // never continues beyond this point above with my BTLE devices that previously worked 
}
Run Code Online (Sandbox Code Playgroud)

我按照/sf/answers/2613467601/中的说明设置我的WPF桌面应用程序以使用UWP API.

问题更严重,因为我的现有WPF应用程序将在客户开始升级到Win 10 1703时被破坏,因为我现有的exe不再有效.

是否有其他人在(非UWP)桌面exe中使用Windows 10 1703更新遇到此问题?

经过进一步的实验,我确实发现如果我将可选的BluetoothAddressType.Public第二个参数添加到FromBluetoothAddressAsync调用中,则返回该函数,但返回的设备为null.

var device = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress, BluetoothAddressType.Public);
Run Code Online (Sandbox Code Playgroud)

c# bluetooth-lowenergy windows-10

6
推荐指数
1
解决办法
2666
查看次数

尝试为 Windows C++ 创建 Gatt 客户端应用程序,该应用程序在建立连接时不会失败

我正在使用用于 C++的 Windows api Gatt Client BLE,我的目标是连接两个设备(但在这种情况下我将只尝试一个)并在不关闭设备的情况下不断读取和写入数据。我所有的设备都有一个特定的服务,其中包含一个读取特性和一个写入特性。

如何测试:

使用 Visual Studio 2017 (v141) 和 Windows SDK 版本:10.0.18362.0,创建一个新的控制台 (.exe) 解决方案,将 Project -> Properties 中的 Platform 更改为 Win32 并转到 Project -> Properties -> C/C++ ->命令行并添加以下选项:

/std:c++17 /await 
Run Code Online (Sandbox Code Playgroud)

然后将以下代码复制到一个文件中(您可以将所有代码复制到同一个 .cpp 文件中):

#pragma once
#include <SDKDDKVer.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <iostream>
#include <queue>
#include <map>
#include <mutex>
#include <condition_variable>
#include <string>

#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Web.Syndication.h>

#include "winrt/Windows.Devices.Bluetooth.h"
#include "winrt/Windows.Devices.Bluetooth.GenericAttributeProfile.h"
#include "winrt/Windows.Devices.Enumeration.h"

#include "winrt/Windows.Storage.Streams.h"

#pragma comment(lib, "windowsapp")


using namespace std;

using namespace winrt; …
Run Code Online (Sandbox Code Playgroud)

c++ bluetooth hresult bluetooth-lowenergy bluetooth-gatt

6
推荐指数
0
解决办法
287
查看次数

使用 gatt 协议的 Windows 10 蓝牙通信

我有多个 BLE 设备需要与之通信。如何连接到特定设备并与之通信?

在 Windows 10 中,似乎没有连接方法。

谢谢

bluetooth bluetooth-lowenergy win-universal-app windows-10-universal

5
推荐指数
1
解决办法
1856
查看次数

如何使用C#手动绑定到WinForm中的蓝牙低能耗设备?

这个问题通常由以下问题回答:Windows UWP发现后连接到BLE设备

我目前正在使用Windows 10上的C#.NET WinForm编写自定义服务并进行测试,以连接到低功耗蓝牙(BLE)设备。我正在使用Framework 4.6.1。我们正在使用带有TI CC2650 BLE子卡的TI SmartRF06评估板。另一位开发人员正在处理主板的固件。

当前我使用的方法类似于上面的参考答案,因此我能够连接到已经绑定的BLE设备。该设备是手动绑定的,Windows确实要求我输入PIN。由于设备没有PIN,只需输入“ 0”就可以连接设备。一旦建立连接,我就可以使用所有GATT服务并做我需要做的事情。因此,我对找到并持有Advertising BLE设备没有任何问题。

问题是如何连接尚未配对的BLE设备?我遍历网络,发现了许多BLE代码示例,但没有具体说明如何完成代码配对。不确定我什至不需要配对,但Windows似乎仅在配对设备上显示我的GATT服务。

当我使用未配对的设备执行此操作时:

private void BleWatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
{       
    var dev = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress);
    // dev.DeviceInformation.Pairing.CanPair is true
    // dpr.Status is Failed
    DevicePairingResult dpr = await dev.DeviceInformation.Pairing.PairAsync(DevicePairingProtectionLevel.None);
    var service = await GattDeviceService.FromIdAsync(dev.DeviceInformation.Id);
}
Run Code Online (Sandbox Code Playgroud)

当未手动配对设备时,dpr的结果总是失败。导致结果GattDeviceServices为空。但是我能够获得BLE设备的广告和属性。

还有这种类型的连接方法,但我不知道如何使用它:

var prslt = await device.DeviceInformation.Pairing.Custom.PairAsync(DevicePairingKinds.ProvidePin, DevicePairingProtectionLevel.None,IDevicePairingSettings);
Run Code Online (Sandbox Code Playgroud)

IdeviceParingSettings是一个接口。不确定要使用哪个类。我在想这是可以设置我可能需要的“ O”密码的地方?

在Windows中使用BLE设备没有安全性的情况下,是否有人能够与Windows中的BLE设备配对。基本上,它应该是开放的。我觉得我缺少一些简单的东西,或者根本不可能做到这一点(我已经看到一些帖子声称是这种情况。其中大多数已经有很多年了)。

我确实尝试了上述文章中描述的方法,但结果没有任何差异。

任何帮助表示赞赏。如果您需要更多代码,请查看我在顶部提供的链接,因为这是我开始的地方。如果有可能我做错了一个序列,我将很乐意提供我所有的实际代码。

c# winforms bluetooth-lowenergy windows-10-desktop

3
推荐指数
1
解决办法
7484
查看次数