C#使用32feet.NET连接到已配对的设备

本文关键字:使用 32feet NET 连接 | 更新日期: 2023-09-27 18:24:17

我正试图通过蓝牙连接到血压机。该设备已与我的笔记本电脑配对。当我在网上使用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);
        }

C#使用32feet.NET连接到已配对的设备

如果有人需要更快速的解决方案,请使用:

public BluetoothDeviceInfo[] DiscoverDevices(int maxDevices, bool authenticated, bool remembered, bool unknown);

其中:maxDevices-在提前停止查询之前要查找的范围内设备的数量。结果可能包含超过此数量的设备。authenticated-为True可返回以前经过身份验证/配对的设备。记住-为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));
            }

这似乎适用于设备。记住的属性。

BluetoothDeviceInfo[] devices;
foreach (var device in devices)
{
if (device.Remembered == true) return "Already Paired";
else return "Not Paired";
}

希望这能有所帮助!

Chris