我正在Visual Studio 2017社区开发Windows 10 UWP应用程序。
我试图从android和IOS设备中读取一些信息。我使用BluetoothLEAdvertisementWatcher观察器查找范围内的有效BLE广告包。我通过特定服务Uuid连接到Gatt服务。最后,我阅读了服务附带的特征。
除了两台S7三星手机外,这对我目前测试的所有设备都有效。
这个过程确实有效,但速度很慢,最终会停止工作甚至阻止蓝牙堆栈。过了一会儿,我将不得不手动关闭蓝牙再打开。
在使用三星S7手机进行每次BLE通信后,我始终遇到这些错误:
onecoreuap \ drivers \ wdm \ bluetooth \ user \ winrt \ common \ devquerydevpropprovider.cpp(297)\ Windows.Devices.Bluetooth.dll!1462192B :(来电者:14621514)ReturnHr(15)tid(36d4)80070490元素没有找到。
onecoreuap \ drivers \ wdm \ bluetooth \ user \ winrt \ common \ devquerydevpropprovider.cpp(131)\ Windows.Devices.Bluetooth.dll!14621555 :(来电者:14578E83)ReturnHr(16)tid(36d4)80070490元素不找到。
onecoreuap \ drivers \ wdm \ bluetooth \ user \ winrt \ device \ bluetoothledevice.cpp(1418)\ Windows.Devices.Bluetooth.dll!14578E9A :(来电者:14576350)LogHr(8)tid(36d4)80070490元素没有找到。
以下是我用来连接Gatt服务的代码:
private async void OnAdvertisementReceived(
BluetoothLEAdvertisementWatcher sender,
BluetoothLEAdvertisementReceivedEventArgs args)
{
BluetoothLEDevice bleModule = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress);
var gattServicesResult = await bleModule.GetGattServicesForUuidAsync(new Guid("YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY"));
if (gattServicesResult.Status == GattCommunicationStatus.Success)
{
foreach (var gattService in gattServicesResult.Services.ToList())
{
if (gattServicesResult.Status == GattCommunicationStatus.Success)
{
GattCharacteristicsResult characteristicsImageID = await gattService.GetCharacteristicsForUuidAsync(new Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"));
if (characteristicsImageID.Status == GattCommunicationStatus.Success)
{
string imageID = null;
foreach (GattCharacteristic gattImageID in characteristicsImageID.Characteristics.ToList())
{
GattReadResult valueImageID = await gattImageID.ReadValueAsync();
IBuffer bufferImageID = valueImageID.Value;
DataReader dataReaderImageID = DataReader.FromBuffer(bufferImageID);
imageID = dataReaderImageID.ReadString(bufferImageID.Length);
}
}
}
}
}
}
导致错误的行(实际上并不致命)是:
bleModule = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress);
我的问题是,是否有其他人发现这是一个问题,是否有解决方案? (可能需要Microsoft在其BLE实现中修复问题)。