Managing Ports and Transfers in .NET
# #
Chapter 2 introduced flow control. The SerialPort class’s Handshake property
offers four flow-control options: None, Request to Send, Xon/Xoff, and
Request to Send with Xon/Xoff.
!#
With Request to Send flow control selected, the COM-port driver sets RTS
false when the InBufferCount property equals (ReadBufferSize - 1024) bytes or
greater. The remote computer should then stop sending data until RTS is true.
In the other direction, the driver doesn’t send data when CTS is false.
With Xon/Xoff flow control selected, the driver sends an Xoff code when the
InBufferCount property reaches (ReadBufferSize - 1024) bytes. The remote
computer should then stop sending data until receiving an Xon code. In the
other direction, after receiving an Xoff code, the driver doesn’t send data until
receiving an Xon code.
Request to Send with Xon/Xoff flow control uses both flow-control protocols.
If CTS is false indicating that the remote computer can’t receive data, the driver
won’t send an Xoff.
After the local computer asserts RTS or sends an Xoff code, the remote com-
puter can send 1024 bytes before the buffer is full. A computer sending data to
such a port should check the flow-control input at least once every 1024 bytes.
For example, assume the SerialPort object has 1030 bytes free in its receive
buffer and is too busy to process received data immediately. If the sending com-
puter checks the flow-control input, sees that it’s OK to send data, and sends
1031 bytes without re-checking, the receive buffer could overflow.
Embedded systems are likely to have much smaller buffers. A computer sending
data to embedded systems should check the flow-control input often, ideally
before sending each byte.
##
!#
The SerialPort class also provides properties for monitoring and controlling the
flow-control lines explicitly and an event to announce changes at flow-control
inputs. An application might need to monitor or control flow-control signals
for non-standard uses such as controlling a synchronous serial interface. An
application can also send and detect software flow-control codes without rely-
ing on the SerialPort object to do so.