LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How does one determine which com port is connected to which bluetooth device?

Hello!

 

 

Problem: Unknown virtual com port number after pairing bluetooth device

 

 

Description I have bluetooth devices that use the serialport service.  I've figured out how to discover, pair, and start the service, but I can't figure out a good automated way to determine which com port is connected to which bluetooth device.

 

Request:  Any dotnet, or other platform commands that I can use to accomplish this I will gladly explore.  Any ideas other ideas how to do this?  

I've already thought of querying each device, but it's very time consuming.

 

 

-Eximo

-Regards

eximo
_______________________________________________
UofL Bioengineering M.S.
Neuronetrix

"I had rather be right than be president" -Henry Clay
0 Kudos
Message 1 of 10
(7,422 Views)

What i do for Com ports is query the devices and Identify them by Model Number, Serial Number or in some cases a responce to a particular command.  Then I assign the discovered instruments to a com port. You can use an array of clusters for this {[Instrument] [ Com Port]}.

 

It can get tricky trying to Identify a particular instrument to a com port especially with primitive porly written device drivers.

Visualize the Solution

CLA

LabVIEW, LabVIEW FPGA
0 Kudos
Message 2 of 10
(7,417 Views)

right, but someplace windows knows the relationship between devices and com ports, especially bluetooth devices.  When you pair with a bluetooth device and check the serial port box.  It will pop up a box that says something to the effect "cell-johnson assigned comport 14".  I just need to know where that information is stored in the dotnet variable structure for the stack or operating system.

 

In order to query a comport that is attached to a bluetooth device you have to connect to the device.  If i have 15 bluetooth devices in a room with me (bluetooth device manufacturer here, so i could have hundreds, and the list would be continously changing), I can't wait for it to check each one each time I want to connect.

-Regards

eximo
_______________________________________________
UofL Bioengineering M.S.
Neuronetrix

"I had rather be right than be president" -Henry Clay
0 Kudos
Message 3 of 10
(7,408 Views)

Hi eximo,

 

As far as I know it depends on the Bluetooth stack you are using. You will need to consult the API to find out more.

 

However, you can use WMI to get the plug and play ID, which contains the BT Address:

 

using System;
using System.IO.Ports;


namespace SerialPortExample
{
    class SerialPortExample
    {
        public static void Main()
        {
            System.Management.ManagementObjectSearcher Searcher = new System.Management.ManagementObjectSearcher("Select * from WIN32_SerialPort");
            foreach (System.Management.ManagementObject Port in Searcher.Get())
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(Port.Properties["PNPDeviceID"].Value.ToString(),"BT"))
                {
                    foreach (System.Management.PropertyData Property in Port.Properties)
                    {
                        Console.WriteLine(Property.Name + " " + (Property.Value == null ? null : Property.Value.ToString()));
                    }
                }
            }

            Console.ReadLine();
        }

    }
}

 

Please see this link for more details:

http://botbench.com/blog/2011/09/23/finding-bluetooth-paired-nxts-with-wmi/

 

Kind Regards,

Message 4 of 10
(7,329 Views)

I think you are right to use system.io.ports.

 

How do you get access to system.io.ports in labview.  If I attempt to open that assembly class with a property I just get the "This assembly contains no public classes or interfaces"

-Regards

eximo
_______________________________________________
UofL Bioengineering M.S.
Neuronetrix

"I had rather be right than be president" -Henry Clay
0 Kudos
Message 5 of 10
(6,896 Views)

Before connecting, use the Find VISA Resource to get a list of available COM ports.  Then after you connect, use it again to figure out which was added.  You now know what COM port was added due to that Bluetooth connection.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 10
(6,884 Views)

That works as long as you have physical access to the machine. But if it's a remote machine which might reboot and enumerate the connected devices in another order then you'll need a lower level solution like above.

Message 7 of 10
(6,880 Views)

That is correct LathoS,

 

The entire reason this function is needed is because there are multiple devices connected to different machines.  Different technicians are expected to use different machines, the user-needs specify that the technicians won't have to open device manager to determine which com port is connected to which device.  (understandably this will increase productivity as it will decrease wasted time opening and looking at device configuration multiple times a day each day)

 

I have determined that there is a method to do this through registry queries but it's a significant pain.  There is a function in the Windows development pack that is called USBview, but it's not compiled into a DLL or .net assembly so is not useful unless somebody can explain how to transform the .net c# code into labVIEWease

-Regards

eximo
_______________________________________________
UofL Bioengineering M.S.
Neuronetrix

"I had rather be right than be president" -Henry Clay
0 Kudos
Message 8 of 10
(6,868 Views)

So you have a central machine controlling all Bluetooth connections in a test lab?  Or is each machine managing itself?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 10
(6,860 Views)

Essentially one machine with multiple permanently enumerated comports.  Some of the connected devices are the same as others.

-Regards

eximo
_______________________________________________
UofL Bioengineering M.S.
Neuronetrix

"I had rather be right than be president" -Henry Clay
0 Kudos
Message 10 of 10
(6,843 Views)