Skip to content

Getting a List of Serial Ports with SerialPortStream

MrEngineer02 edited this page May 2, 2017 · 3 revisions

SerialPortStream uses two mechanisms to obtain details about serial ports: the registry; and the Windows Management Interface (WMI). There is one method compatible with System.IO.SerialPort, the other is new.

List of COM ports

This method is compatible with the Microsoft implementation:

using System.Diagnostic;

foreach (string c in SerialPortStream.GetPortNames()) {
  Trace.WriteLine("GetPortNames: " + c);
}

Port Descriptions

To get a description about the serial port also:

using System.Diagnostic;

foreach (SerialPortStream.PortDescription desc in SerialPortStream.GetPortDescriptions()) {
  Trace.WriteLine("GetPortDescriptions: " + desc.Port + "; Description: " + desc.Description);
}

Clone this wiki locally