1

I know there are questions out there referring to gathering the friendly name of a device on the Device Manager but I cannot do this as the device is simply referred to as "Stardard Serial over Bluetooth link (COM)" and I have many virtual ports with the same reference. I want the name of the device as shown on the Devices and Printers window on:

How to get the device name from here

I'm doing this in C# and currently just getting a list of available COM ports on the system and selecting the one I know from memory.

Ryanas
  • 1,757
  • 3
  • 19
  • 36

3 Answers3

2

I managed to get it to work using 32Feet.Net.

You can search for a device by doing

    BluetoothClient client = new BluetoothClient();
        devices = client.DiscoverDevicesInRange();
        foreach (BluetoothDeviceInfo d in devices)
        {
            items.Add(d.DeviceName);
        }

This will give a list of the friendly names you see on the Devices and Printers window rather than "Standard serial over Bluetooth Link".

If you want the COM port like me or any other piece of information then you can simply do a WMI query such as

    System.Management.ManagementObjectSearcher Searcher = new System.Management.ManagementObjectSearcher("Select * from WIN32_SerialPort");
        foreach (System.Management.ManagementObject Port in Searcher.Get())
        {
             //your comparison or code here
        }
Ryanas
  • 1,757
  • 3
  • 19
  • 36
  • There are two Com ports in case of bluetooth, one incoming and other outgoing. How can we determine which one is incoming and which one is outgoing ? @Ryanas – Waleed Naveed Nov 21 '19 at 06:07
1

I managed to get the bluetooth name, address and the COM port number without using the 32feet.net library by fiddling with the registry key.

Then, you could connect the bluetooth device by using the SerialPort class by passing the COM port number.

The pseudo code to obtain the bluetooth information is below:

  • enumerate all the COM port available in the PNP
  • obtain the device classGuid
  • search the bluetooth address from the classGuid
  • when the bluetooth address is known, the bluetooth name can be obtained from - this registry SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devices

I have posted my code in the link below:

https://stackoverflow.com/a/36298213/2297825

Community
  • 1
  • 1
Tim
  • 3,755
  • 3
  • 36
  • 57
0

I'm using my custom code using 32feet.Net Library which helps me to get the Device Friendly Name also COM port information attached with that device in C# Console Application.

I'm using below code to detect Topaz-Signature Device, and its friendly Name is "T-S460-BT2". You can replace this

string FriendlyDeviceName = "T-S460-BT2";

in the code with your device name you want to search.

using InTheHand.Net;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Bluetooth.Widcomm;
using InTheHand.Net.Sockets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Text.RegularExpressions;

namespace SearchDevice
{
    class Program
    {
        static void Main(string[] args)
        {

            string FriendlyDeviceName =  "T-S460-BT2";

            if (BluetoothRadio.IsSupported)
            {
                BluetoothClient client = new BluetoothClient();
                BluetoothDeviceInfo[] devices;
                devices = client.DiscoverDevicesInRange();
                foreach (BluetoothDeviceInfo d in devices)
                {
                    if (Regex.IsMatch(d.DeviceName, FriendlyDeviceName, RegexOptions.IgnoreCase))
                    {
                        try
                        {
                            string query = string.Format("SELECT Name, DeviceID, PNPDeviceID from WIN32_SerialPort");
                            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
                            ManagementObjectCollection osDetailsCollection = searcher.Get();
                            foreach (ManagementObject mo in osDetailsCollection)
                            {
                                string PNPDeviceID = (string)mo.GetPropertyValue("PNPDeviceID");
                                if (PNPDeviceID != null && Regex.IsMatch(PNPDeviceID, d.DeviceAddress + "", RegexOptions.IgnoreCase))
                                {
                                    Console.WriteLine("{0}", ((string)mo.GetPropertyValue("DeviceId")).Replace("COM", ""));
                                }
                            }
                        }
                        catch (Exception exx)
                        {

                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Not Supported");
            }

            Console.ReadLine();

        }
    }
}
Waqas Ghouri
  • 1,079
  • 2
  • 16
  • 36