• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5521
  • Last Modified:

C# - Getting the FriendlyName from USB Serial Port?

Hi Everyone.
How to get the InstanceName from a USB Serial Port?
if we use the code below will display all Serial Port!
CommPort com=CommPort.Instance;
            int foundRSP=0;

            string[] portList=com.GetAvailablePorts();
            #region This code takes all the serial ports
            for(int i=0;i<portList.Length;++i)
                {
                string name=portList[i];
                comboBox1.Items.Add(name);
                if(name==Settings.Port.PortName)
                    foundRSP=i;
                }

            if(portList.Length>0)
                comboBox1.SelectedIndex=foundRSP;
            #endregion

Open in new window


However I need to show only the USB Serial Port.
I tried this way and not succeeded.
            ManagementObjectSearcher searcher=new ManagementObjectSearcher("root\\WMI","SELECT * FROM MSSerial_PortName");
            string[] USBPorts=System.IO.Ports.SerialPort.GetPortNames();
            #region In this code I need only the USB Serial Port

            //FriendlyName, PID & VID.

            foreach(ManagementObject queryObj in searcher.Get)
                {
                lbl_InstanceName.Text="InstanceName: {0}"+queryObj["InstanceName"];
                lbl_PortName.Text="PortName: {0}"+queryObj["PortName"];

                //If the serial port's instance name contains USB Serial Port
                //it must be a USB to serial device
                if(queryObj["InstanceName"].ToString().Contains("USB Serial Port"))
                    {
                    comboBoxUSB.Items.Add(queryObj["PortName"]);
                    }
                }
            #endregion

Open in new window


Thanks in advance,
ocaccy
0
ocaccy
Asked:
ocaccy
  • 2
2 Solutions
 
Bob LearnedCommented:
Did you try Win32_SerialPort.Description?
0
 
ocaccyAuthor Commented:
Not yet!
This function will need to work on XP, VISTA and 7.
I Would like to work in direction of your tip.
Have you any suggestion to link?
0
 
ocaccyAuthor Commented:
Thank you, still not as I need, but this much better than before his comments.
ocaccy
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now