External Interfaces Previous page   Next Page

Signaling the Presence of Connected Devices

DTE's and DCE's often use the CD, DSR, RI, and DTR pins to indicate whether a connection is established between serial port devices. Once the connection is established, you can begin to write or read data.

You can monitor the state of the CD, DSR, and RI pins with the PinStatus property. You can specify or monitor the state of the DTR pin with the DataTerminalReady property.

The following example illustrates how these pins are used when two modems are connected to each other.

Example: Connecting Two Modems

This example connects two modems to each other via the same computer, and illustrates how you can monitor the communication status for the computer-modem connections, and for the modem-modem connection. The first modem is connected to COM1, while the second modem is connected to COM2.

  1. Create the serial port objects - After the modems are powered on, the serial port object s1 is created for the first modem, and the serial port object s2 is created for the second modem.
  2. Connect to the devices - s1 and s2 are connected to the modems. Because the default value for the ReadAsyncMode property is continuous, data is asynchronously returned to the input buffers as soon as it is available from the modems.
  1. Because the default DataTerminalReady property value is on, the computer (data terminal) is now ready to exchange data with the modems. You can verify that the modems (data sets) can communicate with the computer by examining the value of the Data Set Ready pin with the PinStatus property.

    The value of the DataSetReady field is on because both modems were powered on before they were connected to the objects.

  1. Configure properties - Both modems are configured for a baud rate of 2400 bits per second and a carriage return (CR) terminator.
  2. Write and read data - Write the atd command to the first modem. This command puts the modem "off the hook," which is equivalent to manually lifting a phone receiver.
  1. Write the ata command to the second modem. This command puts the modem in "answer mode," which forces it to connect to the first modem.

    After the two modems negotiate their connection, you can verify the connection status by examining the value of the Carrier Detect pin using the PinStatus property.

    You can also verify the modem-modem connection by reading the descriptive message returned by the second modem.

    Now break the connection between the two modems by configuring the DataTerminalReady property to off. You can verify that the modems are disconnected by examining the Carrier Detect pin value.

  1. Disconnect and clean up - Disconnect the objects from the modems, and remove the objects from memory and from the MATLAB workspace.

Previous page  Using Control Pins Controlling the Flow of Data: Handshaking Next page

© 1994-2005 The MathWorks, Inc.