我们有托管GATT服务器的电话应用程序,具有服务和特色。在桌面应用程序中,我们尝试使用DeviceWatcher使用UWP API搜索它。var deviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(false), new List<string>(), DeviceInformationKind.AssociationEndpoint);然后我们尝试从设备获取服务var serviceResult = await device.GetGattServicesForUuidAsync(ServiceId);但是这种方法非常不稳定。查找并连接到设备需要30-60秒。有时它找不到设备或找到设备,但是无法获得服务。另外,我们尝试将设备与PC配对,并仅检查已配对或已连接的设备var deviceWatcher = DeviceInformation.CreateWatcher( BluetoothLEDevice.GetDeviceSelectorFromPairingState(true), new List<string>(), DeviceInformationKind.AssociationEndpoint);但是这个观察者什么也没找到。我们尝试了不同的AQS过滤器,并获得了相同的结果。另外,我们尝试使用32feet lib仅获取配对的已连接设备。var client = new BluetoothClient();var paired = client.DiscoverDevices(5, true, true, false);foreach (var bluetoothDeviceInfo in paired){ var addressBytes = bluetoothDeviceInfo.DeviceAddress.ToByteArray(); var addr = BitConverter.ToUInt64(addressBytes, 0); var device = await BluetoothLEDevice.FromBluetoothAddressAsync(addr)); var serviceResult = await device.GetGattServicesForUuidAsync(ServiceId);}它可以快速运行并找到电话,但是找到的设备不包含我们的GATT服务,并且其蓝牙地址与DeviceWatcher找到的设备不同。看起来一个手机上有两个蓝牙设备:第一个设备具有我们的BLE服务,第二个设备已配对但没有服务。有什么方法可以配对正确的BLE设备并仅搜索配对的吗?
1 回答
- 1 回答
- 0 关注
- 596 浏览
添加回答
举报
0/150
提交
取消