Click here to Skip to main content
12,503,291 members (64,302 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


45 bookmarked

Serial Port Programming Part 1 – A (very) brief introduction

, 6 Jan 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
A (very) brief introduction to serial port programming.

My first entry in this blog is going to be about serial ports. Why? Mostly because I read a lot of posts in various programming forums in regards to interacting with the serial ports. Most programmers frequently forget that serial ports have been around a very long time so they act a little different then most current communication technologies.

When deploying an application that will be interacting with serial ports the first question should always be what device will be attached and how? The “how” is the most important question. If the device only uses the transmit, receive and signals ground pins then the deployment is a lot easier, if it use all 8 pins it could increase the complexity of the project.

First some resources, a complete understanding is not really necessary but if you get some of the more challenging devices you might need a detailed understanding of how serial communication works in order to troubleshoot properly. Here’s a short list below:

On to the programming, before proceeding, you might want to have a quick look at the MSDN pages for Serial Port class here.

Below is a very brief implementation of the serial port. There’s more to come however this will get you started. There’s a very important note on this implementation, there must always be a terminator or a set byte length of the data. By set byte length I meant that each block of data that you’ll need to process is x long. So instead of a terminator you use track how many bytes are read to know when you’re received all the data.

Next time – Serial Port Programming Part 2 – Developing a GUI to set the Port Settings and validating the data. 

You can download the code below at

 1: using System;
 2: using System.IO.Ports;
 3: using System.Text;
 5: namespace SerialPortExample
 6: {
 7:     /// <span class="code-SummaryComment"><summary>


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Pantelis Chatzinikolis
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

Questionragarding Comport Pin
Member 78274723-Mar-13 22:57
memberMember 78274723-Mar-13 22:57 
GeneralMy vote of 4 Pin
Member 43208442-Jan-12 9:28
memberMember 43208442-Jan-12 9:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160919.1 | Last Updated 6 Jan 2012
Article Copyright 2011 by Pantelis Chatzinikolis
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid