首页 > 解决方案 > 如何在 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();

标签: uwpbluetooth-lowenergy

解决方案


推荐阅读