Hello Mario.
In .NET, you can use the DeviceInformation
class to get the connection status of a paired Bluetooth device without opening the corresponding COM port. Here is a sample code snippet:
DeviceInformationCollection PairedBluetoothDevices = await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelectorFromPairingState(true));
This code will return a collection of DeviceInformation
objects representing all paired Bluetooth devices. You can then filter this collection by the device name to connect to the device you want.
Please note that this method does not require opening the COM port associated with the Bluetooth device. It simply queries the system for the pairing state of the device.
Remember to add the necessary using directives at the top of your file:
using Windows.Devices.Bluetooth;
using Windows.Devices.Enumeration;
Also, ensure that your project has the necessary capabilities enabled in the Package.appxmanifest file (like bluetooth, etc.). Please note that this code is for UWP apps and may not work in a traditional .NET Framework or .NET Core console application. If you’re not developing a UWP app, you might need to use a library like 32feet.NET which provides a managed interface to the Win32 Bluetooth APIs. I hope this helps! Let me know if you have any other questions.