uwp - 如何在 UWP 中断开与 BLE 设备的连接
问题描述
我正在使用 PC 上的 Windows 10 连接到 BLE 设备。我正在使用 Gatt Client 连接到设备以读取和写入数据。与设备断开连接不起作用。
public static async Task Disconnect(BluetoothLEDevice device)
{
GattDeviceServicesResult result = await device.GetGattServicesAsync();
var services = result.Services;
foreach (var service in services)
{
GattCharacteristicsResult results = await service.GetCharacteristicsAsync(BluetoothCacheMode.Uncached);
foreach (var charac in results.Characteristics)
{
charac.Service?.Session.Dispose();
}
service?.Dispose();
}
device.Dispose();
await Task.Delay(80000);
var status = device.ConnectionStatus; // **This still shows connected**
device = null;
GC.Collect();
解决方案
推荐阅读
- css - 是否可以将 calc() 函数用于绝对定位元素?
- twitter - 苍鹭服务启动前无法控制现有拓扑
- c# - 如何在从 Angular 调用 Api 到 .NET-core 之前检查 JWT 令牌过期
- python - 将.pb模型转换为.tflite时如何通过通道设置不同的平均值和标准值
- android - WindowInsets 与 InputMethodManager !在android中显示和隐藏软键的正确方法
- php - 在 PHP 中压缩时 PDF 数字签名在 Ghostscript 中不起作用
- typescript - 如何在 TypeScript 中实现声明类的构造函数?
- amazon-web-services - 在 linux 容器上使用 powershell 作为 buildspec 的一部分
- amazon-web-services - 任务数、任务内存和任务 CPU 有什么作用(AWS ECS)
- .net-core - Visual Studio 中的 SSH 远程调试采用什么格式的私钥?