This project has moved. For the latest updates, please go here.

How to Determine Bluetooth Serial Port

Topics: Bluetooth - BlueSoliel, Bluetooth - Microsoft, Bluetooth - Other, Bluetooth - Stonestreet, Bluetooth - Widcomm/Broadcom
Feb 11, 2013 at 2:47 PM

I have been testing out both and In the Hand as ways of manipulating Bluetooth. I'm not an expert on Bluetooth but appreciate that there are differences with the Microsoft and Widcomm stacks, and also different Bluetooth Manager applications.

What I really need is a common way to determine which serial port has been assigned to a device. The underlying Windows CE/Mobile operating system seems to know this as I can open a serial port within an application and this will make a connection to whichever Bluetooth device is assigned this serial port. However, within a Visual Studio application, I don't necessarily know which serial ports have been assigned to which devices. Is there a way to enumerate all the trusted Bluetooth devices and determine which serial ports are assigned to them?

Many thanks
Feb 11, 2013 at 4:57 PM

I have continued to look into this, and thought I'd found a solution...

If I call BluetoothClient.DiscoverDevices, I can enumerate all the known Bluetooth devices. Then, for each one (that's authenticated and remembered) I can call BluetoothEndPoint and pass in the device's address and BluetoothService.SerialPort. This returns data about the end point, including a Port field which I thought would contain the serial port name/number. This code runs and returns information, but the Port is always 0

Am I doing something wrong with this code. Or is there a better/easier way to determine which serial port is assigned to the Bluetooth device?

Feb 11, 2013 at 10:44 PM
Edited Feb 11, 2013 at 10:47 PM
How about Getting Virtual COM Port Names

Note I really recommend against using COM ports unless one really really has to. The problem here is just one of the reasons I dislike them.

I thus recommend using Sockets e.g.
    Guid serviceClass;
    serviceClass = BluetoothService.SerialPort;
    // - or - etc
    // serviceClass = MyConsts.MyServiceUuid
    var ep = new BluetoothEndPoint(addr, serviceClass);
    var cli = new BluetoothClient();
    Stream peerStream = cli.GetStream();
    peerStream.Write/Read ...
Feb 12, 2013 at 11:15 AM
Thanks very much for this reply alanjmcf, it's much appreciated

Firstly, I have a Bluetooth device which is linked via it's own SDK event handler. My code needs to make a call to the device's SDK, passing in the COM port, and the event handler is then fired whenever the device gets any data to pass over Bluetooth. I'm not controlling the Bluetooth device directly and I need to use a COM port to be able to use the device's SDK

Secondly, I had a look through the first article you suggested, and in turn that links to an article on Getting Virtual COM Port Names for Remote Bluetooth Devices, which in turn links to an article that I think you might have written on Getting Virtual COM Port Names. This article talks about WMI, but says that WMI is not available on Windows Mobile so resorts to reading the registry. However, I believe the registry keys will be different on different devices, depending on which Bluetooth Manager or stack is in use. It's for this reason that I want to know if I can make a call to a 32Feet.Net function to find out. (I'm using a couple of different devices for testing, and neither has any subkeys under HKLM\Software\Microsoft\Bluetooth\Serial\Ports)

Is it possible to have 32Feet.Net return the COM ports associated with devices?

Thanks again
Feb 15, 2013 at 10:51 AM
Hi All,

There haven't been any responses, so I'm guessing this means that 32Feet.Net cannot determine which COM port is assigned to a Bluetooth device. Could anybody confirm whether this is the case? I am continuing to investigate how to determine which COM port has been assigned to which Bluetooth device, so any advice that anybody can give me at all would be very welcome

Feb 18, 2013 at 6:08 PM
What we know is on that documents page Getting Virtual COM Port Names However it shouldn't be too hard for you to check where in the Registry each stack stores its information and write some Opcode to read all the locations. There's probably a central location where all the ports are referenced too.

We'd be happy to accept such code to include in the library. :-)