External Interfaces/API |
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.
s1
is created for the first modem, and the serial port object s2
is created for the second modem.
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.
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.
atd
command to the first modem. This command puts the modem "off the hook," which is equivalent to manually lifting a phone receiver.
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.
Using Control Pins | Controlling the Flow of Data: Handshaking |