Chapter 5. Using Serial and Infrared Ports

With insomnia, nothing is real. Everything is far away. Everything is a copy of a copy of a copy.

?Narrator, Fight Club

Previous chapters have described how you can develop applications on a Pocket PC device to use TCP/IP-based networks in a variety of ways to send and receive data between a client and host. This chapter explores the most basic communication protocol that is supported on these devices?low-level serial input/output. A serial connection is most simply defined as a direct, one-to-one connection between two devices whose data is transferred one bit at a time. Examples of serial connections include those between a Pocket PC device and a modem, printer, or some type of data collection device.

Windows CE supports both serial cable and infrared (IR) communications as a mechanism for establishing a connection between two serial devices. Figure 5.1 shows Pocket PC's built-in capability to receive a file over infrared.

Figure 5.1. Using infrared to receive a file


Establishing a connection and transferring data back and forth with another serial device is fairly straightforward?Pocket PC uses the same functions as it does when working with the file system (such as CreateFile(), ReadFile(), and so on). This is also the same mechanism that is used on the desktop, which makes porting applications from a Windows XP system to a mobile device an easy process.

With regard to where the serial and infrared network APIs sit on the TCP/IP OSI layer, an application that you develop will directly use the serial APIs, which reside in the data-link layer. These functions work with the serial and infrared drivers, which then communicate with the actual serial hardware in the OSI physical layer using the standard RS-232C interface. Figure 5.2 shows how both the serial and infrared communication stack fits into the TCP/IP OSI model:

Figure 5.2. Serial and infrared communications and the TCP/IP OSI model


To use the serial or infrared communication functions with your application, you need to include the header windows.h, and link with the coredll.lib library in your project.


Serial-based infrared communications support only half-duplex operations. This means that only one device can transmit or receive data over a particular direction at a time.