Serial Communications

Serial communication requires a one-to-one connection between transmitter and receiver, typically by way of a serial cable. IR transceiver modems are also used for serial communications.

From the standpoint of software, each serial device is identified by its COM port name, for example, "COM1:" and "COM2:." The COM-port assignments are stored in the registry under \HKEY_LOCAL_MACHINE\Drivers. Because they may be installable, check \HKEY_LOCAL_MACHINE\Active to see which drivers are loaded.

Serial communication over a COM port is similar to reading from, or writing to, a file, and it uses some of the same functions. Regardless of the hardware, the basic procedure works as described in the next section, "Implementing Serial Communications."

Using IR transceivers is more complex. Windows CE supports two ways to use an IR transceiver for serial communications. One approach supported by some Windows CE-based devices treats the IR transceiver like a serial cable. The data is not processed by the system in any way. The sending and receiving applications are responsible for dealing with collision-detection and other potential problems. This approach is referred to as raw infrared, or raw IR.

The COM port assigned to raw IR is determined by the original equipment manufacturer (OEM) and is listed in the registry. Because it may share a port assignment with a wired serial connector, you should check the registry to be certain. If the port is shared, you must use EscapeCommFunction to set the port to IR mode.

A second approach to serial IR communications uses the Infrared Data Association (IrDA) protocols. These protocols are part of the network stack, and are discussed in "Infrared Sockets" later in this chapter. To simplify their use for serial communications, Windows CE provides an emulator (IrComm), that enables an application to communicate using the IrDA protocols in much the same way it does with raw IR.

From a programming standpoint, the main difference between raw IR and IrComm is that they have different COM-port assignments. With IrComm, there is also no need to explicitly configure the port for IR by calling EscapeCommFunction.