How to get specifik name of comport?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Askelassen
    New Member
    • Nov 2009
    • 6

    How to get specifik name of comport?

    Hello.

    My question is as follows:

    I am making a little gui that uses COMPORTS to connect to a board. I want the program to be able to find the correct COMPORT by itself. This goes fine with try/catch as long as I dont have other devices that uses COMPORTS. My code so far is as follows:

    Code:
      public void InitSerialPort()
            {
    
                int i = 0;
                bool comportSelect = false;
    
                while (comportSelect == false)
                {
                    try
                    {
                        if (i == 21)
                        {
                            Error(0);
                            comportSelect = true;
                        }
                        else
                        {
                            mySerialPort = new SerialPort(("COM" + i.ToString()), 19200, Parity.None, 8, StopBits.Two);
                            mySerialPort.DataReceived += new SerialDataReceivedEventHandler(Received);
                            mySerialPort.Open();
                            mySerialPort.
                            MessageBox.Show(mySerialPort.PortName);
                            comportSelect = true;
                        }
                    }
                    catch
                    {
                        i++;
                    }
                }
            }

    This doesn't work when I have an other device using a lower COMPORT as the one for my gui. If I open device manager I can see different desciptions of the comports. The one I want to use is described as:

    "USB Serial Port (COM3)"

    Do you guys know a way to return this description so I can do a "chec" to see wheater I have selected the right COMPORT?

    Thanks allready!

    /Aske
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    There is a way to get some information about them using WMI (like in http://www.python-forum.org/pythonfo...t=7175&p=88622 )

    Comment

    • Askelassen
      New Member
      • Nov 2009
      • 6

      #3
      I'm writing in c# in visual studio :) so can I use this?

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        How can I know? If there is a way to access WMI from c# (I'm sure there is) then yes, I permit you to use this for whatever purposes.

        Comment

        Working...