Search code examples
c#.netbluetooth-lowenergy32feet

C# connecting to an already paired device using 32feet.NET


I am trying to connect to a Blood Pressure Machine via bluetooth. The device is already paired with my laptop. When I use nuget pacage inTheNet. I am able to get a list of devices near by, but am unable to get the device that is already paired

  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);
        }

Solution

  • If anyone need more fast solution use:

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

    Where: maxDevices - The number of in-range devices to find before the inquiry may be stopped early. The result can contain more than this number of devices. authenticated - True to return previously authenticated/paired devices. remembered - True to return remembered devices. unknown-True to return previously unknown devices.

    Example:

    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));
    
                }