有时无法从方法GetGattServicesAsync
中获取带有参数BluetoothCacheMode.Cached
或BluetoothCacheMode.Uncached
的响应。只有Windows重新启动才能帮助重新连接文件设备并从文件设备获取服务。
我们将Windows.Devices.Bluetooth.dll
与.Net Framework 4.6.1一起使用来构建类库。 Windows PC将连接蓝牙文件设备。
再现问题的步骤:
FromBluetoothAddressAsync
将LE设备与桌面配对:
DeviceInformationPairing loPairingInf = poDevice.DeviceInformation.Pairing;
if (!loPairingInf.IsPaired)
{
DevicePairingKinds loConfirm = DevicePairingKinds.ConfirmOnly;
DevicePairingProtectionLevel loProtectionLevel = DevicePairingProtectionLevel.Default;
DeviceInformationCustomPairing loCustomPairing = loPairingInf.Custom;
}
检查连接状态。如果状态已连接,请调用方法GetGattServicesAsync(BluetoothCacheMode.Cached)
。有时无法从GetGattServicesAsync
获得响应。 30秒后,我们取消任务,处置BluetoothLEDevice
,解除配对并尝试重新连接设备。重新连接失败,只有重新启动Windows才能建立与le设备的连接。
PC:
Dell Precision 5530
蓝牙适配器Qualcomm QCA6174A
Windows 10企业版(1803)
版本10.0.17134构建17134.590
LE设备:
问题:
是否可以避免GetGattServicesAsync的问题?
可能存在一些以编程方式破解以重新连接文件设备的方法 在没有重新启动窗口的情况下取消GetGattServicesAsync之后?
答案 0 :(得分:0)
我发现某些系统服务与此问题有关。
您可以尝试在TaskManager中重新启动Bluetooth Support Service
。
如果要从TaskManager识别进程,则此服务的命令行为
C:\ WINDOWS \ system32 \ svchost.exe -k LocalService -p -s bthserv
此解决方法并不完美,但比重新启动计算机要好一些。
但是,如果要关闭与BluetoothLE设备的连接,请记住拨打BluetoothLEDevice.Dispose
。否则,您可能会在一个过程中遇到其他问题。