Serial Programming
From Wikibooks, the open-content textbooks collection
This book explains different aspects of serial data communication. Serial data communications is the foundation for most forms of data communications used with modern computing devices. The focus of the articles in this book will be around the implementation of RS-232 (aka RS-232C, aka V.24, aka EIA-232D, etc.) based serial data communication and will explore a wide range of implementations and uses for serial data transfer.
Contents |
[edit] Book Contents
- General
- Introduction and OSI Network Model
- RS-232 Wiring and Connections
- Typical RS232-Hardware Configuration
- Low-Level serial Interface Hardware
- Specific Programming Environments
- Serial Data Communications in DOS
- TAPI communications in Windows
- Serial communications in Linux and Unix
- Serial communications using Java
- Programming serial Devices
- Serial Programming Applications
- Forming Data Packets
- Error Correction Methods
- Two Way Communication
- Serial Data Networks
- Practical Application Development
- IP over Serial Connections
- Appendix: communications channels that are very similar to RS-232
[edit] Intended Audience
This series of articles is intended for people who are interested in diving into the "guts" of serial data communications systems. This material is rarely taught in university courses, and it can be tough to learn "on the job".
As with any software development, the individual topics are simple, but tying them all together can be very complex. This text takes a layered approach to the subject, in order to avoid overwhelming the novice. The first chapter deals with the bare copper wires and how they are handled. Subsequent chapters will add layers of protocol.
Typical serial communication can happen at just about any level. Some applications pull "raw" data right off the wires while others use full packet networks on multiple computers. For more, see "Why Serial Programming?" in the introduction.
[edit] Prerequisites
Serial programming cannot be done without knowing how to program and without knowing how to access the system. This book assumes that you are able to write software in at least one computer programming language. Knowing how to use at least one software tool that supports low-level operating system access will also help.
This series is written toward the x86 platform of CPUs, but much of this information can be applied to other environments including custom embedded systems or other CPU systems. Details of I/O control will have to be garnered from the respective CPU architectures if you proceed in that manner with alternate CPU systems. If possible, please add to these articles if you are knowledgeable about this subject, particularly if you are familiar with some of these alternate software systems or CPU architectures.
If I haven't scared you off so far, I am still trying to write to a relative novice in computers. Writing low-level software/driver routines can be intimidating. Even if you are working from an API library, this sort of software development can be a very different experience from a typical "Hello World" application. While you may be able to write "Hello World" with a dozen lines or less in most software languages, transmitting "Hello World" across a serial connection can take quite a bit of code and reading up on all of the software settings and where they should be at. I'll give concrete examples and at the same time try to explain the "Why" as well as the "How".
In addition to compiler tools, having access to a good terminal emulator application would also be very useful. On multi-tasking systems like Windows or Linux, this can be run as a separate task from the application that you are developing. In cases like this it is helpful if your computer has at least two serial data communication ports, and that you have access to a "null-modem" cable, at least to start with. There are some software tricks to avoid this requirement, but it is much more satisfying if you can see actual communication occurring. Having access to a second computer drives the idea home even more, especially when data file transfer is covered. RS-232 Connections describes a few more pieces of hardware (e.g. a Breakout Box or a Protocol Analyzer), both simple and advanced versions, which are useful when doing serial programming.
[edit] A Note on Terminology
The term 'RS-232' is used in a relaxed sense in this book, as it has become common in computing, and not in the strict sense of some RS-232 standard. The actual RS-232 standard is known under many different names, and in many different versions. Depending on the version, the standard does not even define all aspects which are commonly associated with 'RS-232' communication (e.g. start/stop bit framing).
Readers who need the precision of a standard are referred to one or more of the RS-232 standards. Readers who are interested in the practical programming of RS-232-like interfaces and devices should find useful information in this book.
[edit] Resources
See Subject:Computer engineering for other kinds of low-level serial interface hardware that typically have the same high-level programming interface as RS-232 (RS-422, RS-423, RS-449, RS-485, MIL-STD-188, Universal Serial Bus (USB), etc.) and hardware that happens to be serial (Serial ATA, Wifi, Ethernet, etc), although it usually uses a very different high-level protocol.