我需要从一台蓝牙设备中获取数据,使用C#在Windows 10上进行操作。我对蓝牙API不太熟悉,无法弄清楚以下内容为什么不能工作:
使用BluetoothLEAdvertisementWatcher
搜索广告,这部分可以正常工作。我收到了来自设备的广告(本地名称匹配),以及它的ServiceUuids
。接下来,我尝试使用与广告一起收到的BluetoothAddress
连接到设备:
private async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher,
BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
ulong blAdress = eventArgs.BluetoothAddress;
BluetoothLEDevice blDevice = await
Windows.Devices.Bluetooth.BluetoothLEDevice.FromBluetoothAddressAsync(blAdress);
}
然而,这样做会导致异常:
这是从设备读取数据的正确方法吗?还有其他选项可以从服务中读取数据吗?在 windows 中手动配对设备并不是一个真正的选择,也似乎失败了。未找到元素。(HRESULT 异常:0x80070490)。
/编辑 1:我检查设备的本地名称,以确保只尝试连接到正确的设备。所以我想这个特定设备的连接存在问题,但我仍然不知道如何解决它。iOS 上已成功读取服务数据,因此应该是可行的。