我們有托管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 回答
- 0 關注
- 613 瀏覽
添加回答
舉報
0/150
提交
取消