【发布时间】:2015-10-01 16:49:09
【问题描述】:
对于一个项目,我需要使用 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);
}
但是,这样做会导致异常:
未找到元素。 (HRESULT 异常:0x80070490)。
这是从设备读取数据的正确方法吗?是否有其他选项可用于从服务中读取数据?在 Windows 中手动配对设备并不是一个真正的选择,而且似乎也失败了。
/Edit 1:我检查设备的本地名称以确保我只尝试连接到正确的设备。所以我猜想连接到这个特定设备有问题,但我仍然不知道如何解决这个问题。服务数据在iOS上读取成功,应该是可以的。
【问题讨论】:
标签: c# windows bluetooth bluetooth-lowenergy windows-10