C H A P T E R  11

Serial Port Drivers

A serial port provides a basic communications interface for the purpose of getting low bandwidth data into and out of a computer. Although modern interfaces such as USB and FireWire have replaced many applications in which the traditional serial port was once used, the serial port driver is still well supported in modern day operating systems, including Mac OS X, despite the fact that Apple has not released hardware with a built-in serial port for over a decade.

There are several reasons for the longevity of the serial port. First, a serial port is simple and inexpensive to implement in hardware, making it a popular choice for hobbyists who are adding computer communications to their electronic projects. Second, it is a very flexible interface. The serial driver is concerned only with transferring data bytes between the serial port and the user space application. The driver plays no role in interpreting the data stream; it simply deals with the transmission of the data.

This leaves the user space application to implement the protocol of the connected device, which means that much of the work that would usually be done by a driver is instead left to the user space application. This means that a hardware vendor doesn't have to provide a driver for their device; they can simply publish the protocol describing the format of the data that they transmit over their serial port, and leave the implementation of the protocol for others. Devices that use serial ports include GPS receivers and barcode scanners. They are also commonly used to provide debugging output on hardware.

Serial ports are no longer found on Macintosh computers; they have been replaced by USB and FireWire ports. Serial devices, such as GPS receivers and barcode scanners, attach to a computer by USB, but they appear to the system as a USB-based serial port that a user space application can connect to. If you are interacting with a device that communicates over a serial port, in nearly all cases your application will be able to use an existing serial port driver. There are very few cases where you will need to implement your own serial port driver; even projects that use a USB-based serial port will use standard drivers to provide the serial port interface.

This chapter describes how a serial port driver is implemented within the I/O Kit, and how to read and write from a serial port in a user space application. The implementation of a serial port driver can be seen as a practical example of driver techniques, including implementing blocking calls, circular buffers, and synchronization and notification. Therefore, even if a serial port driver is not directly relevant to you, the concepts that we will cover can be applied to other drivers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.198.183