You must Sign In to post a response.
  • Category: .NET

    How do I get device information from specific port names?

    I am now working on a project which related to bluetooth communication.
    I retrieved all COM ports names "COM12" , "COM23" from devices "Dual-SPP" and "SOLONOID" , now my problem is I could get information related to device like "DeviceID", "Friendly name" , but i need to get the above actual names of device like
    "Dual-SPP" and "SOLONOID".

    How do i get this names? please suggest.
    Thanks .


    What I have tried:

    ManagementObjectSearcher searcher =
    new ManagementObjectSearcher("root\\CIMV2",
    "SELECT * FROM Win32_PnPEntity");

    foreach (ManagementObject ManObj in searcher.Get())
    {
    if (ManObj["Caption"].ToString().Contains("(COM"))
    {
    Console.WriteLine(ManObj["DeviceID"].ToString());
    Console.WriteLine(ManObj["PNPDeviceID"].ToString());
    Console.WriteLine(ManObj["Name"].ToString());
    Console.WriteLine(ManObj["Caption"].ToString());
    Console.WriteLine(ManObj["Description"].ToString());
    Console.WriteLine(ManObj["ProviderType"].ToString());
    Console.WriteLine(ManObj["Status"].ToString());
    }
    }
  • #767877
    Hi Priyanka,

    Try this.
    Hope it helps!!

    using System.Management;
    using System.IO;

    string result = "";
    using (var searcher = new ManagementObjectSearcher("SELECT * FROM WIN32_SerialPort"))
    {
    string[] portnames = SerialPort.GetPortNames();
    var ports = searcher.Get().Cast<ManagementBaseObject>().ToList();
    var tList = (from n in portnames join p in ports on n equals p["DeviceID"].ToString() select n + " - " + p["Caption"]).ToList();

    foreach (string s in tList)
    {
    result = result + s;
    }
    }
    MessageBox.Show(result);

  • #767880
    I already tried it but this code not giving me what i want

  • #767883
    Basically There is no univeral way of identifying serial port unless the devices have special commands that you can send to the device and have it respond with identifying information there is not much you can do. I think if you have use some special third party device then ask for their API
    I got some snippet on below link, but I don't know how much it will work
    http://stackoverflow.com/questions/4500027/get-the-device-name-connected-to-the-serial-port

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments