我尝试连接到BLE外围设备。首先,我看广告:
watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active };
watcher.Received += WatcherOnReceived;
watcher.Start();
Run Code Online (Sandbox Code Playgroud)
在WatcherOnReceived回调中,我尝试创建BluetoothLEDevice
public async void WatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs btAdv)
{
BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress);
}
Run Code Online (Sandbox Code Playgroud)
但是,我总是在WatcherOnReceived回调中得到bleDevice == null。为什么以及如何解决?在UWP应用程序中创建BLE设备的正确方法是什么?然后,我需要连接到该设备,发现其GATT服务和特性,在其中一些上启用通知,并读/写其中一些。
这个问题的答案很简单-不要在Windows 10上使用BLE。该API无法正常工作或行为随机,并且完全没有文档说明。我喜欢每个人都在谈论物联网是下一次工业革命,并且微软在存在6年的BLE后仍无法使用BLE API。