Asynchronous Serial Communications Programmer's Reference Manual (32022-90052)
72 Chapter3
Common Device Control Functions
Reading From Asynchronous Devices
Using READ or READX
The READ and READX intrinsics provide a simple method for reading
from the standard input device. You do not need to know the file
number when you use these intrinsics. Except for the intrinsic name,
the syntax is the same for READ and READX. The syntax of the READ
intrinsic is shown below:
I16 CA I16V
transfercount
:=READ(message,expectedlength);
The maximum length of the read is passed in expectedlength and the
call returns the actual length of the read in
transfercount
, if
transfercount
is used. The read data is returned in message.
Both READ and READX transfer an ASCII string into a character
array in your program. However, READ transfers data from $STDIN,
while READX transfers data from $STDINX. READ also differs from
READX in the way an end-of-file is interpreted. READ recognizes any
colon (:) found in column 1 as an end-of-file, while READX interprets
only :EOD as an end-of-file.
Because there is no file number associated with READ or READX, it is
not possible to use the FCHECK intrinsic to determine what took place
in the event of an error. Nor can you use the :FILE command to
redirect input, since the input always comes from the standard input
files opened by the session at logon time.
Because of the limitations inherent in the use of READ and READX, it
is recommended that you use these intrinsics only for temporary
programs as a quick way to obtain input from a terminal. A better
programming practice for permanent programs would be to use FOPEN
or HPFOPEN to open $STDIN or $STDINX and then issue FREAD calls
against these files.