這是用於獲取BLE設備的UWP代碼。爲什麼我爲某些設備獲取bleDevice == null?我沒有找到解釋這個問題的任何文件。BluetoothLEDevice.FromIdAsync返回null
var devices = await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector());
foreach (DeviceInformation di in devices)
{
Debug.WriteLine(di.Name);
BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(di.Id);
if (bleDevice == null) {
Debug.WriteLine("--- NULL ----");
continue;
}
Debug.WriteLine(bleDevice.Name);
}
我注意到,我得到bleDevice!= NULL對於有感嘆號與Windows STATUS_DEVICE_POWER_FAILURE在設備管理器中的BLE裝置。
我得到bleDevice == null爲設備管理器中沒有感嘆號的BLE設備。
我要非常感謝你爲了這個簡單的解決方案,我正在拉我的頭髮,試圖弄清楚爲什麼我變得空了。 – Kingpin