Asynchronous Serial Communications Programmer's Reference Manual (32022-90052)
70 Chapter3
Common Device Control Functions
Reading From Asynchronous Devices
Setting a Read Time Limit
FCONTROL can also be used to set a time limit on a succeeding read,
by specifying 4 as the value of controlcode and specifying a time limit,
in seconds, through param (up to 65535 seconds). If the read
immediately following the call takes more than the time specified, the
read will terminate in error and any data already received will be
flushed. The read limit remains in effect only for the next read. You
must issue a separate FCONTROL(4) call prior to every read on which
you want to impose a time limit.
There are many circumstances in which it is advisable to set a timeout
value. Timeouts should always be used with devices that operate
without a dedicated attendant, to prevent hangs that could occur if the
device were to fail in some way.
Timeouts are effective in all data editing modes. This makes it possible
to terminate even a binary mode read should it exceed the specified
time limit. During block mode reads, however, the timer is halted upon
receipt of the DC2 character and the block mode read timer takes over.
When a read terminates as the result of exceeding the timeout set by
FCONTROL(4), the read fails with a CCL condition and all data is lost.
A call to FCHECK returns an FSERR 22, Software Timeout.
The code segment shown in Figure 3-4 sets a 30-second time limit for
the next read posted against
fileid_in
. The sample includes an error
checking routine which verifies whether or not the read terminated
normally. If not, the program calls FCHECK. If FCHECK returns an
FSERR 22, the program will inform the user that a read timeout
occurred.