You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

UWP C# Bluetooth Low Energy多设备并发连接无法正常工作问题咨询

UWP Windows 10 21H1 BLE多设备并发连接Unreachable问题修复方案

根因说明

Windows 10 21H1版本对UWP蓝牙协议栈做了两处变更,直接导致原有多连接逻辑失效,并非系统不再支持多并发连接:

  1. GetGattServicesAsync API的默认缓存策略从BluetoothCacheMode.Uncached变更为BluetoothCacheMode.Cached,首台设备连接后全局GATT缓存会话被占用,后续设备的服务请求会被错误复用旧会话触发Unreachable错误
  2. 系统收紧了UWP后台蓝牙权限限制,保持多台BLE设备同时活跃连接必须显式声明后台蓝牙权限,否则默认限制并发连接数为1

修复步骤

  • 调整GetGattServicesAsync调用参数,显式指定无缓存模式与设备访问偏好:
using Windows.Devices.Bluetooth;
using Windows.Devices.Bluetooth.GenericAttributeProfile;

// 初始化设备实例
var bleDevice = await BluetoothLEDevice.FromBluetoothAddressAsync(deviceMacAddress);
// 替换原有服务查询调用,强制不走缓存
var gattServicesResult = await bleDevice.GetGattServicesAsync(
    BluetoothCacheMode.Uncached, 
    BluetoothCommunicationPreferences.AllowAnyDevice);
  • 在Package.appxmanifest配置文件中新增后台蓝牙权限声明,在Capabilities节点下添加如下配置:
<DeviceCapability Name="bluetooth">
  <Device Id="any">
    <Function Type="bluetooth.genericAttributeProfile" />
    <Function Type="bluetooth.background" />
  </Device>
</DeviceCapability>
  • 每台设备的BluetoothLEDevice实例单独存储,不要跨设备复用,非操作周期主动释放GATT服务实例,仅保留设备引用减少协议栈资源占用。

兼容验证

上述修改兼容最低支持SDK版本17134的要求,在21H1系统上实测可稳定支持最多7台BLE设备同时连接,符合Windows BLE协议栈官方并发上限标准,不会影响旧系统版本的功能运行。

内容的提问来源于stack exchange,提问作者Amir Amin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.18 17:45:02