我正试图通过蓝牙连接到血压机。该设备已与我的笔记本电脑配对。当我在网上使用nuget pacage时。我能够获得附近的设备列表,但无法获得已配对的设备
string macAddress = FindMACAddress();
_blueToothEndPoint = new BluetoothEndPoint(BluetoothAddress.Parse(macAddress), BluetoothService.BluetoothBase);
_blueToothClient = new BluetoothClient(_blueToothEndPoint);
BluetoothDeviceInfo[] devices = _blueToothClient.DiscoverDevices();
foreach (BluetoothDeviceInfo device in devices)
{
Console.WriteLine(device.DeviceAddress);
}
答案 0 :(得分:1)
如果有人需要更快速的解决方案使用:
public BluetoothDeviceInfo[] DiscoverDevices(int maxDevices, bool authenticated, bool remembered, bool unknown);
其中: maxDevices - 可以提前停止查询之前要查找的范围内设备的数量。结果可能包含超过此数量的设备。 authenticated - 如果为True,则返回先前经过身份验证/配对的设备。 记住 - 确认返回记住的设备。 unknown -True返回以前未知的设备。
示例:
var devices = bluetoothClient.DiscoverDevices(10, true, true, false);
foreach (var device in devices)
{
var blueToothInfo =
string.Format(
"- DeviceName: {0}{1} Connected: {2}{1} Address: {3}{1} Last seen: {4}{1} Last used: {5}{1}",
device.DeviceName, Environment.NewLine, device.Connected, device.DeviceAddress, device.LastSeen,
device.LastUsed);
blueToothInfo += string.Format(" Class of device{0} Device: {1}{0} Major Device: {2}{0} Service: {3}",
Environment.NewLine, device.ClassOfDevice.Device, device.ClassOfDevice.MajorDevice,
device.ClassOfDevice.Service);
Console.WriteLine(blueToothInfo);
Console.WriteLine();
devicesList.Items.Add(new BluetoothDeviceInfoContainer(device));
}
答案 1 :(得分:0)
这似乎适用于device.Remembered属性。
BluetoothDeviceInfo[] devices;
foreach (var device in devices)
{
if (device.Remembered == true) return "Already Paired";
else return "Not Paired";
}
希望这有帮助!
克里斯