Kon*_*ski 5 c# bluetooth windows-10
我正在尝试编写一个应用程序来读取Windows 10 IoT上的所有MAC地址.这些代码行返回所有配对设备,即使它们没有打开.
var selector = BluetoothDevice.GetDeviceSelector();
var devices = await DeviceInformation.FindAllAsync(selector);
listBox.Items.Add(devices.Count);
foreach (var device in devices)
{
listBox.Items.Add(device.Id);
}
Run Code Online (Sandbox Code Playgroud)
我也找到了这行代码
await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
Run Code Online (Sandbox Code Playgroud)
这返回null.有没有办法扫描Windows 10通用应用程序中的所有MAC地址?
您已经非常接近找到问题的答案了。您可以尝试BluetoothDevice从 DeviceId 属性获取实例。然后,您将能够获取所有特定的蓝牙信息,包括蓝牙地址
var selector = BluetoothDevice.GetDeviceSelector();
var devices = await DeviceInformation.FindAllAsync(selector);
foreach (var device in devices)
{
var bluetoothDevice = await BluetoothDevice.FromIdAsync(device.Id);
if (bluetoothDevice != null)
{
Debug.WriteLine(bluetoothDevice.BluetoothAddress);
}
Debug.WriteLine(device.Id);
foreach(var property in device.Properties)
{
Debug.WriteLine(" " + property.Key + " " + property.Value);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3672 次 |
| 最近记录: |