【发布时间】:2026-02-16 05:45:01
【问题描述】:
我尝试连接到 BLE 外围设备。首先,我看广告:
watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active };
watcher.Received += WatcherOnReceived;
watcher.Start();
在 WatcherOnReceived 回调中我尝试创建 BluetoothLEDevice
public async void WatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs btAdv)
{
BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress);
}
但是,我总是在 WatcherOnReceived 回调中得到 bleDevice == null。为什么以及如何解决它?在 UWP 应用程序中创建 BLE 设备的正确方法是什么?然后我需要连接到该设备,发现它的 GATT 服务和特性,在其中一些上启用通知并读/写其中一些。
【问题讨论】: