Serial Communications: A C++ Developer's Guide, 2nd Edition
by Mark Nelson
Wiley Books,1999
ISBN 9780764545702
662 pages.
List price in the US is $44.95

"…an excellent general reference for modern serial communication packages" — Jim Kyle, Windows Tech Journal

"Mark's new book on serial port programming is fabulous…" — Jeff Duntemann, PC Techniques


The first edition of this book will be hard to find. It is pretty easy to find the second edition in used condition on If you purchase this or some other book after clicking through the link above, you’ll help me keep this web site up and running with the few pennies I skim from your purchase. Thanks!

For beginning and advanced C programmers, this book is a comprehensive reference guide to writing flexible serial communications applications for the PC. In the past, C programmers developing for RS-232 hardware were tied to a single platform. Any change in one of several variables, such as the CPU, the operating system, the C compiler, or the type of serial interface used, required an extensive rewrite of the program.

Now in Serial Communications: A C++ Developer’s Guide Mark Nelson shows you how to write portable applications using C++ to avoid the limitations of serial programming. A hands-on guide to mastering object-oriented techniques in writing software for modems, BBS’s, and other communications systems, this book covers the latest C++ compilers from Microsoft, Borland, and Symantec. The disk includes extensive C and C++ source code.

Topics include:

  • Writing communications programs that are easily portable between different operating systems and hardware platforms.
  • Accessing modems or other serial devices across networks.
  • Using standard and intelligent multiport boards.
  • Implementation of file transfer formats such as XMODEM, YMODEM, ZMODEM, and Kermit.
  • Interfacing with the latest high-speed modems at data rates of 9600 bps and higher.


The 32 bit code in this book was developed for the most part with Visual C++ 5. Readers have run into a few compiler glitches with Visual C++ 6. If you use VC++ 6, please be sure to apply all of Microsoft’s service packs. At this time, the latest is SP3. You can download these from the Microsoft web site. (I’d provide a link, but Microsoft changes their web page often enough to make this an exercise in frustration.

Chapter 1

Figure 1-5 on Page 10 has an extra 0 bit in the middle of the word. There should be a string of 5, not six. Here’s an improved version of the image:

Chapter 11 - Win32Port.h

If you are developing for a Windows 2000 target, or for NT4 with SP3 or later, you will need to modify a single line in Win32Port.h. Around line 76 of ths file, you will find a line of code that looks like this:

enum { EV_RINGTE = 0x2000 }

Change it to look li this:

enum { EV_RINGTE = 0 }

This flag is used to get the serial driver to report changes on the input RLSD (ringer) control line under Windows 9X. This undocumented feature allows things to work properly in that environment, but breaks things under Windows 2000.

Keep in mind that if you make this change, your program won’t respond to incoming rings under Win32, unless you watch for “RING” messages coming from your modem. (Watching for messages is probably a better way to do it in general, so maybe it’s time to change!)

If you are deploying your code on both Windows 2K and Windows 9X, you might want to create a more general purpose solution by determining whether or not to use the EV_RINGTE mask at runtime, based on detection of the O/S type.

Chapter 11 - Win32Port.cpp

I botched the definition of a loop in this code, and despite the compiler warning, I failed to note the problem until alerted by several readers.

The loop in output_worker() used to start like this:

for ( bool done = false ; ; !done ) {

It has been corrected to start like this:

for ( bool done = false ; !done ; ) {

Chapter 12

For some reason, the publisher decided to leave this chapter’s executable off the CD-ROM. This shouldn’t be a big deal, since you ought to be able to build it with the included project file. But, just in case you can’t, here is the executable. Note that this is built with debug options turned off.

Chapter 13 - Win32Term.cpp

There are a few errors that showed up in this project in Visual C++ 6. They are all related to minor changes in header files or the way the compiler parses them.

In Win32Term::Paint(), a call to SelectObject() needed a cast of the return type before it could be assigned to hOldFont. The line was:

HFONT hOldFont = SelectObject( hDC, m_hFont );
HFONT hOldFont = (HFONT) SelectObject( hDC, m_hFont );

Chapter 13 - Win32Term.h

I use a pragma in this header file to turn off compiler warnings for error C4786, which are unavoidable, and are really pointing to problems in the compiler, not in my code. In VC++ 6, the pragma has to be moved to be ahead of the #include for header file vector. The resulting code now looks like this:

// The vector<vector<>> variables in this class
// end up with incredibly long expanded names. This
// pragma disables the associated warnings
#pragma warning( disable : 4786 )
#include <windows.h>
#include <vector>
using namespace std;

Download changed files

You should be able to build the new executable by copying this files to the correct locations in your project.

Chapter 16

Bill Jacques noticed that the SendSingleFile() function in Zmodem.cpp gets stuck in an infinite loop if the remote end has an allocation problem. He sends an update of the function (as a Word Doc.) Bill wrote a Win32-specific version of the function, so don’t try to include this code if you are running in some other environment.

You will have to replace the existing function in Zmodem.cpp.