1
votes

I am writing an application in C#, to connect to a Bluetooth breakout chip.

From my understanding, Windows assign a COM port to the device; so I can connect to it. Although, I do not understand how to retrieve the name of the device associated to a specific port.

At the moment I retrieve all the COM, and then since I know which port is working for the BT device, I open the connection manually with a button.

The objective here is to turn on the device, and if the device is paired; it will connect automatically. Unless I got it wrong; when you pair a Bluetooth device, it get assigned to a COM port; so it should be possible to retrieve the device name/BT name, interrogating the COM port? In this way I can scan all the ports; check which port is assigned to that device name and open automatically the connection.

Is this correct or there is a different way to achieve what I want to achieve?

1

1 Answers

0
votes

So far, I found no quick way to do so, nor an API from Windows or .NET that allow you to do such an easy thing, like get info about a COM port. Either nobobody works with Bluetooth on serial, or it must be so horrible that not even Microsoft wanted to put efforts in allowing this info to be obtained.

Beside the very convoluted ways to get the info, raging from registry inquire to introspection on different levels; I found this add on called 32feet for .NET; which allow to actually do what I was trying to achieve.

The code is pretty simple; and the object created has the info about the friendly name used in the Bluetooth peripherals screen, and is able to return also the port that is bound to that device, once it connects.

Quite a surprise that I have to use an external solution, while I was expecting that it would be exposed somehow through the standard API in Windows. Although it works, problem solved!

IF I find a different way to do the same, and that does not require more overhead than what you really need, I will post it here.