Chapter 53. Controlling Modems

Bill Birthisel

Serial ports are one of the oldest black boxes in computing: data goes in, data comes out, and few people understand how, even though serial ports have been around much longer than PCs and haven’t changed much over the years. They’re still a very common way to connect computers to their peripherals, or even computers to one another. This article describes how to use the Win32::SerialPort module to talk to devices like modems from your Win32 Perl programs. (If you’re not using Windows, the Device::SerialPort module, also on CPAN, provides the same interface for Linux, AIX, Solaris, and other POSIX operating systems.)

Before communicating, serial ports have to agree about a few things. Sometimes the agreement is pre-arranged; for instance, operating systems typically know how to talk to many types of mice. But you probably have seen something like 9600,8N1 in a manual to describe a serial device configuration. Those are the serial characteristics: baud rate, data bits, parity, and stop bits.

Let’s look at what that 9600,8N1 means. At all times, a serial line either has a voltage difference across it (an “on” bit) or no voltage difference (an “off” bit). The 9600 defines the time between bits: 1/9,600 second. The 8 tells you how many bits there are per character. ASCII requires only seven bits, but most connections these days find a use for that eighth bit. An additional bit, the parity bit, is sometimes used as a simplistic checksum for the ...

Get Computer Science & Perl Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.