Getting Serial Port Information in C#

Posted by Jim Fell on Stack Overflow See other posts from Stack Overflow or by Jim Fell
Published on 2010-05-14T22:16:11Z Indexed on 2010/05/19 21:40 UTC
Read the original article Hit count: 451

Filed under:
|
|
|

I have some code that loads the serial ports into a combo-box:

     List<String> tList = new List<String>(); 

     comboBoxComPort.Items.Clear();

     foreach (string s in SerialPort.GetPortNames())
     {
        tList.Add(s);
     }

     tList.Sort();
     comboBoxComPort.Items.Add("Select COM port...");
     comboBoxComPort.Items.AddRange(tList.ToArray());
     comboBoxComPort.SelectedIndex = 0;

I would like to add the port descriptions (similar to what are shown for the COM ports in the Device Manager) to the list and sort the items in the list that are after index 0 (solved: see above snippet). Does anyone have any suggestions for adding the port descriptions? I am using Microsoft Visual C# 2008 Express Edition (.NET 2.0). Any thoughts you may have would be appreciated. Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about comports