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
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.
s1is created for the first modem, and the serial port object
s2is created for the second modem.
s2are connected to the modems. Because the default value for the
continuous, data is asynchronously returned to the input buffers as soon as it is available from the modems.
DataTerminalReadyproperty 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
The value of the
DataSetReady field is
on because both modems were powered on before they were connected to the objects.
atdcommand to the first modem. This command puts the modem "off the hook," which is equivalent to manually lifting a phone receiver.
atacommand 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
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.
|Using Control Pins||Controlling the Flow of Data: Handshaking|
© 1994-2005 The MathWorks, Inc.