Main Page

From LibSerial

Contents

Features

  • Simplified serial port programming in C++ under POSIX operating systems.
  • Support for USB-serial converters.
  • Access serial ports from scripting languages such as PHP, Python, Perl, Ruby, and Java (coming soon in version 0.6.0).

LibSerial Description

LibSerial provides a collection of C++ classes that allow one to access serial ports on POSIX systems like standard C++ iostream objects. The SerialStream class represents the primary class that is expected to be used by developers to access serial ports as iostream objects. Additionally a SerialPort class is available to provide access to serial ports without using the standard C++ iostream interface. This is useful for embedded systems where a complete C++ STL may not be available. Member functions are provided for setting various parameters of the serial ports such as the baud rate, character size, flow control and others. The idea is to simplify serial port programming on POSIX systems. For example, using libserial, you can do the following:

 #include <SerialStream.h>
 //
 // Open the serial port. 
 //
 SerialStream serial_port( "/dev/ttyS0" ) ;
 //
 // Set the baud rate of the serial port.
 //
 serial_port.SetBaudRate( SerialStreamBuf::BAUD_9600 ) ;
 //
 // Read a character from the serial port. 
 //
 char next_char ; 
 serial_port >> next_char ; 
 //
 // Write the character back to the serial port. 
 //
 serial_port << next_char ;

In addition to the C++ programming languge, LibSerial releases after version 0.6.0 also provide bindings to several scripting languages such as Python, Perl, PHP, Java, and Ruby. This provides developers a wide range languages to select when writing applications that need access to serial ports on POSIX compatible operating systems.

LibSerial has received most extensive testing under Linux operating system. It is currently being tested on Mac OS X and version 0.6.0 will support Mac OS X operating system. There are no plans to port this library to Microsoft Windows operating system at this point (including the use of Cygwin).

Download

The latest version of LibSerial is 0.5.2. You can download the source code for LibSerial-0.5.2 from here. Older versions of LibSerial can be downloaded from here.

Documentation

Links

An excellent collection of a variety of C++ classes including a set of classes that can be used for programming serial ports. GNU CommonC++ is also cross-platform (it runs on POSIX as well as Win32 systems).
A lot of the code in LibSerial is based on information obtained from Michael R. Sweet's guide to serial programming. Thanks, Mike.