This chapter provides sample code that demonstrates how to use the device-file mechanism to find and communicate with a serial device that explicitly claims to be a modem, such as a built-in or USB modem. Because there is no safe, programmatic way to determine if a device attached to a serial port is indeed a modem, the sample code in this chapter does not find modems on the other side of a serial port.
The code snippets in this chapter are from the sample application SerialPortSample, available in its entirety at http://developer.apple.com/samplecode/SerialPortSample.
Note: If you choose to develop a Cocoa application that accesses a serial modem, be aware that Objective-C does not provide interfaces for I/O Kit or POSIX functions. However, because the I/O Kit and POSIX APIs are C APIs, you can call them from a Cocoa application.
Although the sample code in this chapter has been compiled and tested to some degree, Apple does not recommend that you directly incorporate this code into a commercial application. For example, only limited error handling is shown—you should develop your own techniques for detecting and handling errors.
Serial Device Access in an Intel-Based Macintosh
Accessing a Serial Device
Including Header Files and Defining Macros and Constants
Setting Up a Main Function
Finding All Modems
Getting the Path to the Device File for a Modem
Opening the Serial Port
Communicating With the Modem
Closing the Serial Port
Last updated: 2005-12-06