How To Access Serial Ports In C#

The pre-installed Visual Studio C# class for manipulating serial ports in C# is found in the following namespace:

To get a string list of the current active COM ports on the computer, and then populate a combobox with this list, use the code:

The SerialPort class contains an handy enumeration of commonly available baud rates. The following code shows how to populate a combo box with these values.

To set up the SerialPort class for use, you have to set the parameters shown in the code below.

Then you can use code like shown below to open and close the serial port for use.

Posted: April 11th, 2013 at 4:15 pm