Serial /RS232 Programming Tutorials for Beginners

serial port programming tutorials in C,Csharp,Python on windows,Linux

Serial Port Programming

This is a collection of articles on programming the serial port of a x86 PC using C,CSharp (C#) and Python.

The tutorials covers programming the serial port using native API's like

  1. Win32 API on Windows or
  2. termios/ioctl() API on Linux.

The tutorial also explains how to program the serial port using C# on .NET framework (Windows) .

For Cross platform applications you can use the open source Python module PySerial for writing code on Windows and Linux.Since PySerial is available for Mac OSX ,the code provided here can run on Macs too(I have not tested it ).


The code presented in the tutorials are written using opensource or freely downloadable softwares like

  • GCC (GNU C Compiler)
  • Microsoft Visual Studio Express Edition/Microsoft Visual Studio Community Edition
  • Active Python
  • SharpDevelop 

The codes are tested on a Windows 7  and a Ubuntu/Linux Mint PC.

In the case of Python,seperate code is provided for Python2.7 and Python 3.x to accomadate the differences.

Most PC companies have stopped including hardware based DB9 serial ports in their computers and most laptops never had any to begin with.In this tutorial most of the examples are tested using USB to Serial Converters like USB2SERIAL.You can use any USB to Serial Converters, only requirement is that you should be able to access the RXD ,TXD ,RTS and DTR pins of the module(which are brought out in USB2SERIAL to bergs).


Windows Platform

serial port programming in windows 7 windows 8 windows 10 using win32 api

Serial Port Programming using Win32 API

Controlling DTR and RTS pins of Serial Port using Win32 API

Serial Programming using C Sharp (C#) on Windows (.NET Framework)

GUI based Serial Communication Program using C# (.NET Framework)

Serial Programming using Visual Basic.Net on Windows (.Net Framework) 

Serial Communication using D2XX library and FT232 chip


Linux Platform

serial port programming on linux ,ubuntu,raspberry pi debian for beginners

Serial Port Programming on Linux

Controlling the RTS and DTR pins of Serial Port in Linux

Serial Programming using C# on Linux using Mono Framework


Cross Platform (both Linux and Windows )

Cross Platform serial communication using Python (PySerial)

Serial Programming using C# on Linux using Mono Framework


RS485 Programming Tutorials 

Some times we have to communicate with systems that are several 100's of meters away like a remote data acqisition system or a robot, in such cases serial (RS232) will not cut it. You have to use some thing known as a RS485 protocol that can communicate over several Kilo Meters.

One problem with standard PC's is that they dont come with a RS485 port,you can use USB2SERIAL which already have a MAX485 based RS485 tranciever that you can use to implement such a network.check out the below link if you are interested in building an RS485 communication network.You can buy the hardware here .Sample codes are available in C ,Csharp (C#) and Python for Windows and Linux platforms. 

Cross Platform RS485 communication using USB2SERIAL

Communicating with a Robot over an RS485 link

Controlling DC Motors using RS485 link on Windows and Linux 

Remote DAQ system using MSP430



quite comprehensive serial programming article

java section is missing !