JFa*_*Far 6 c# bluetooth-lowenergy windows-10
我升级到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)
看起来 15063 中蓝牙 API 周围的安全功能存在错误,导致了这种情况(我也看到了同样的情况)。查看此线程:
tl;dr 对于 C++ 应用程序,它们提供了一个 CoInitializeSecurity 函数来调用。对于其他人来说,他们似乎建议在注册表中创建一个 AppId,因为 P/Invoke 并不是很有趣。
奇怪的是,目前我通过 Nobel-uwp 一切正常,它使用 C++ 绑定到 UWP 函数来通过 node.js 进行访问。只有通过 C# 我才会遇到问题,并且根据我是在 UWP 还是 WPF/控制台/桌面应用程序中,事情会在不同的点失败。
按照论坛帖子中的概述将 AppId 添加到注册表后,一切又对我有用了。
| 归档时间: |
|
| 查看次数: |
2666 次 |
| 最近记录: |