Getting Serial Port Information in C#
- by Jim Fell
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.