Asynchronous Serial Communications Programmer's Reference Manual (32022-90052)

56 Chapter3
Common Device Control Functions
Opening Asynchronous Devicefiles
Opening Asynchronous Devicefiles
Devicefiles Before an asynchronous device can be used by your
program, you must obtain access to the device and define the
characteristics you want to be associated with the device for your
application. You do this by using the FOPEN or HPFOPEN intrinsic to
open a file on the device, passing the file specifications required by your
program in the parameters of the call. See Chapter 8, “Intrinsics
Reference,” for a description of the syntax of the FOPEN and
HPFOPEN intrinsics.
When the FOPEN or HPFOPEN call is executed, MPE/iX will open the
file as specified by the parameters of the call, establish communications
between your program and the file, allocate needed resources (including
the device on which the file is to reside), and return a file number to
your program. If the file is not opened successfully, a 0 is returned as
the file number. See Chapter 2, “Controlling Asynchronous Devices
Programmatically,” for more information on condition codes.
The file number assigned by the open call is unique. Because every file
has its own number, even if multiple files are opened on the same
device, it is possible to use the file number to access a specific file in
subsequent intrinsic calls. The file number remains associated with the
file as long as it is opened; that is, until your program either issues an
FCLOSE against that file or terminates.
The parameter values used for the FOPEN or HPFOPEN call
determine what features will be associated with the file. System default
values are assumed for any optional parameters not specifically
designated.
Default values will also be assumed if you attempt to specify a value
that does not make sense for the device on which the file is being
opened. For example, the userlabel parameter of the FOPEN intrinsic
has no meaning for files opened on terminals and, if specified, any value
will be ignored and the default of 0 assumed.
The fact that parameters are ignored if not meaningful for a specific
device provides an extra degree of flexibility when coding a program. If
you foresee an instance when you might want to temporarily redirect a
file normally resident on one type of device to another type of device,
you can code the specifications that will allow you to do so. For example,
you can specify the tape label option (
foption
bit (6:1) of the FOPEN
intrinsic) for a file your program normally opens on a terminal even
though this option has no meaning for files on asynchronous devices.
If you later run the same program, but issue a :FILE command to
redirect that file to tape, there is no need to specify the tape label
option.