Share via


Getting more information about a serial port in C#

Question

Sunday, April 19, 2009 2:09 PM

In Device Manager there are descriptions of the PC's serial ports with the port number in parenthesis. I would like access to these descriptions in C#. For Example my application uses a USB to Serial Adapter. Device manager reports it as "USB Serial Port (COM1)".  Using the System.IO.SerialPort.GetPortNames() only returns the information in parenthesis. Is there any way to get the information before that i.e. "USB Serial Port"?

Thanks
Wayne

All replies (3)

Wednesday, April 22, 2009 6:28 AM âś…Answered

Hi Ravenb,

We can't get the information through the SerialPort type. I don't know why you need this info in your application. However, there's a solved thread with the same question as you. You can check out the code there, and see if it can help you.

If you have any further problem, please feel free to let me know.

Best regards,
Bruce ZhouPlease mark the replies as answers if they help and unmark if they don't.


Monday, September 17, 2012 8:21 AM

the thread you have suggested use WMI but the only problem with wmi is , WMI is really very slow it take about 40 second to execute the query.  


Tuesday, December 5, 2017 3:06 PM

That is possible with ManagementClass:

       public string GetFullComputerDevices()
        {
            Console.WriteLine("Start");
            ManagementClass processClass = new ManagementClass("Win32_PnPEntity");

            ManagementObjectCollection Ports = processClass.GetInstances();
            string device = "No recognized";
            foreach (ManagementObject property in Ports)
            {
                if (property.GetPropertyValue("Name") != null)
                    if (property.GetPropertyValue("Name").ToString().Contains("USB") &&
                        property.GetPropertyValue("Name").ToString().Contains("COM"))
                    {
                        Console.WriteLine(property.GetPropertyValue("Name").ToString());
                        device = property.GetPropertyValue("Name").ToString();
                    }

                    }
            Console.WriteLine("End");
            return device;
        }