Mar*_*sek 1 bluetooth-lowenergy
这是用于获取BLE设备的UWP代码。为什么某些设备会出现bleDevice == 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);
}
Run Code Online (Sandbox Code Playgroud)
我注意到对于Windows设备管理器中带有STATUS_DEVICE_POWER_FAILURE带有感叹号的BLE设备,我得到bleDevice!= null。
对于设备管理器中没有感叹号的BLE设备,我得到bleDevice == null。
小智 6
我遇到了同样的问题。李志智(Chi Lee)先前的回答实际上是很好的,但没有足够详细的说明(非专家;-)。
这里是详细的过程(假设您在Microsoft Visual Studio下有一个ac#项目):



如果您已经有配对的设备(在程序中或在Windows中手动),则BluetoothLEDevice.FromIdAsync(di.Id)将不再返回null 。
| 归档时间: |
|
| 查看次数: |
1366 次 |
| 最近记录: |