The buffer (actually a PAB) is set-up with
FBUF: SERIAL S" RS232.BA=9600 DV80O" SERIAL FILE SERIAL #OPEN
The above attempts to open the serial port for output as a Display Variable 80 type file.
A file buffer called SERIAL is declared (using
FBUF:), and this is fed to
FILE (along with the string that describes the file).
FILE builds the PAB in the buffer named SERIAL.
#OPEN leaves a
FALSE on the stack if the file was opened successfully. If the file could not be opened, it leaves a TRUE on the stack. This allows easy trapping with ABORT" as shown below:
SERIAL #OPEN ABORT" Can't open file"
In the event of a file error,
IOERR can be read to get the DSR error code. If
IOERR returns -1 (>FFFF) then this means that no free file IO slots were found. A maximum of 3 open files are supported (2 if block files are also to be used). Note that block files are immediately closed after they are accessed for either reading or writing, so 3 generic file I/O streams are available when no blocks files are being used.