External Interfaces Previous page   Next Page

Controlling the Flow of Data: Handshaking

Data flow control or handshaking is a method used for communicating between a DCE and a DTE to prevent data loss during transmission. For example, suppose your computer can receive only a limited amount of data before it must be processed. As this limit is reached, a handshaking signal is transmitted to the DCE to stop sending data. When the computer can accept more data, another handshaking signal is transmitted to the DCE to resume sending data.

If supported by your device, you can control data flow using one of these methods:

You can specify the data flow control method with the FlowControl property. If FlowControl is hardware, then hardware handshaking is used to control data flow. If FlowControl is software, then software handshaking is used to control data flow. If FlowControl is none, then no handshaking is used.

Hardware Handshaking

Hardware handshaking uses specific serial port pins to control data flow. In most cases, these are the RTS and CTS pins. Hardware handshaking using these pins is described in The RTS and CTS Pins.

If FlowControl is hardware, then the RTS and CTS pins are automatically managed by the DTE and DCE. You can return the CTS pin value with the PinStatus property. You can configure or return the RTS pin value with the RequestToSend property.

If your device does not use hardware handshaking in the standard way, then you might need to manually configure the RequestToSend property. In this case, you should configure FlowControl to none. If FlowControl is hardware, then the RequestToSend value that you specify might not be honored. Refer to the device documentation to determine its specific pin behavior.

Software Handshaking

Software handshaking uses specific ASCII characters to control data flow. These characters, known as Xon and Xoff (or XON and XOFF), are described below.

Table 10-12: Software Handshaking Characters 
Character
Integer Value
Description
Xon
17
Resume data transmission
Xoff
19
Pause data transmission

When using software handshaking, the control characters are sent over the transmission line the same way as regular data. Therefore you need only the TD, RD, and GND pins.

The main disadvantage of software handshaking is that you cannot write the Xon or Xoff characters while numerical data is being written to the device. This is because numerical data might contain a 17 or 19, which makes it impossible to distinguish between the control characters and the data. However, you can write Xon or Xoff while data is being asynchronously read from the device because you are using both the TD and RD pins.

Example: Using Software Handshaking

Suppose you want to use software flow control with the example described in Example: Reading Binary Data. To do this, you must configure the oscilloscope and serial port object for software flow control.

To pause data transfer, you write the numerical value 19 to the device.

To resume data transfer, you write the numerical value 17 to the device.


Previous page  Signaling the Presence of Connected Devices Debugging: Recording Information to Disk Next page

© 1994-2005 The MathWorks, Inc.