1

I have a communication tool I've written to send data over a COM port on a computer, currently you have to Search for COM ports and then select the correct COM port, the UI looks like this:

Com port

However, I would like to be able to display the full COM port identifier in the list. I'm talking the full names here:

Serial port list

Is there a way to do this in C#? I've done a bit of digging and can't find it. Here is how I'm currently searching for available COM ports:

        private void find_open_ports_Click(object sender, EventArgs e)
    {
        string[] open_com_array = null;
        int index = -1;
        string com_port_name = null;

        open_com_array = SerialPort.GetPortNames();
        do
        {
            index += 1; // search next com port to see if it's open
            open_ports.Items.Add(open_com_array[index]); // adds open com port to dropdown box
        }
        while (!((open_com_array[index] == com_port_name) || (index == open_com_array.GetUpperBound(0))));
        Array.Sort(open_com_array);
        if (index == open_com_array.GetUpperBound(0));
        {
            com_port_name = open_com_array[0];
        }
        open_ports.Text = open_com_array[0];
        com_status.Text = "Open Selected COM Port";
    }

Thanks for the help in advance!

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
biggi_
  • 266
  • 3
  • 12
  • http://stackoverflow.com/questions/2837985/getting-serial-port-information – 001 Feb 25 '16 at 19:00
  • http://stackoverflow.com/questions/9370859/get-friendly-port-name-programatically – 001 Feb 25 '16 at 19:01
  • Got it thanks! I"m looking into those now. they didn't show when I did a search for some odd reason. – biggi_ Feb 25 '16 at 19:01
  • I looked at the first link and tried the second answer, the one using System.Management and get the error when trying the var searcher = new ManagementObjectSearcher of "The type or namespace name "managementObjectSearcher" could not be found (are you missing a using directive or an assembly refrence". Not sure what that means, but that snippit of code doesn't seem to be working.... – biggi_ Feb 25 '16 at 19:17
  • Did you add a reference to "System.Management" assembly? – 001 Feb 25 '16 at 19:27
  • I just tried a couple of those posts and [this one](http://stackoverflow.com/a/28329584/669576) worked on my pc. – 001 Feb 25 '16 at 19:42
  • I added System.Management to my main .cs file as well as the assembly instructions under properties. where all does it need to go? getting the same error. – biggi_ Feb 25 '16 at 20:07
  • [How to: Add and Remove References in Visual Studio (C#)](https://msdn.microsoft.com/en-us/library/7314433t%28v=vs.90%29.aspx?f=255&MSPPError=-2147217396) – 001 Feb 25 '16 at 20:17
  • Ok so I'm close now...just trying to get that into a combo box. They have "portList" without saying what that is. I"m trying to get into a combo box...ideas? – biggi_ Feb 25 '16 at 20:25

0 Answers0