我使用C#在Windows 10中查找蓝牙低Enegergy设备当我运行下面的代码,我遇到了这样的错误:C#扫描蓝牙LE设备
"An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code".
错误的行Debug.WriteLine("Found device: " + devices[0].Id);
我不知道它为什么超出范围。谢谢!
namespace BluetoothLE
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void LookForPairedDevices()
{
// Get BLE devices paired with Windows
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector());
Debug.WriteLine("Found device: " + devices[0].Id);
}
}
}
'DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector()'返回任何设备,因此试图访问索引0(第一个项目)抛出一个异常 –