From the Introduction
When I wrote the first edition of this book, the RS-232 serial port was the workhorse of PC interfaces. Modems and scores of other peripherals connected to PCs via the serial ports that were present on every machine.
When the Universal Serial Bus (USB) took hold in the late 1990s, many predicted that serial ports would soon be obsolete. Plenty of peripherals that formerly used the serial port have switched to USB. But some devices cant use USB or have requirements that USB alone cant provide. Many embedded systems use serial ports because theyre inexpensive and less complex to program compared to USB. Serial ports can use longer cables than USB allows. And the RS-485 serial interface supports networks suitable for many monitoring and control applications.
While most PCs no longer have built-in serial (COM) ports, the ports are easy to add via USB converters. With converters, the number of expansion slots no longer limits the number of serial ports a system can have. The SerialPort class included in Microsofts .NET Framework shows that PC applications continue to find COM-port communications useful.
This book explores wide and varied territory, including hardware and software; ports in PCs and in embedded systems; and RS-232, RS-485, and wireless interfaces. You dont need to read the book straight through. If youre interested in a particular topic, you can skip right to it.
The first chapters focus on hardware and interfacing. Chapters 1 and 2 are an introduction to asynchronous serial communications. Chapter 3 discusses serial ports in PCs, and chapters 48 are a guide to interfacing using RS-232, RS-485, and wireless technologies.
The next chapters are a guide to programming. Chapters 9 and 10 show how to program serial ports on PCs using Visual Basic .NET and Visual C# .NET. Chapter 11 shows how to program serial ports for embedded systems with examples for microEngineering Labs' PICBASIC PRO compiler and Microchip Technology's MPLAB C18 C compiler.
Chapters 12 and 13 focus on hardware and programming for RS-485 serial networks.
Chapters 1416 explain how to implement USB virtual COM ports using special-purpose and generic USB controllers.
Whats New in the Second Edition
Much has happened in the world of computing since the first edition of this book was released. For this second edition, Ive revised and updated the contents from start to finish.
One addition is example code in C/C# as well as Basic. This book includes code examples for PCs and for embedded systems (microcontrollers).
Also new in the Second Edition are these topics:
Designing and programming USB virtual COM ports.
Using wireless technologies to transmit serial data.
Accessing serial ports over Ethernet or Wi-Fi networks.
Transferring any kind of text data using Unicode encoding.
Who Should Read this Book?
Whether your interest is hardware or software and whether you work with PCs, embedded systems, or both, youll find useful guidance in this book.
Programmers will learn how to communicate via serial ports, including USB virtual COM ports, in PCs and embedded systems. The example code for PCs and microcontrollers in Basic and C/C# provides a quick start for a variety of applications.
Circuit designers will find designs for a variety of applications including converters that translate between RS-232, RS-485, and 3V/5V logic. Designs with fail-safe features, high noise immunity, and low power consumption are included.
Hobbyists and experimenters will find inspiration for projects.
Teachers and students can learn about serial ports and use the examples in this book to demonstrate concepts.
This book assumes you have a basic knowledge of electronics and either Basic/Visual Basic or C/C# programming. I assume no previous knowledge or experience with serial-port hardware or programming.