Technical information

Serial Solutions Pasterm
This shows the two variables, type File Of Char, Com_Inp
and Com_Out, that refer to the com port. They are the same file,
but input and output refer to them via different files structures.
A single file would have to be continually opened and closed
with Reset and ReWrite as the file was read and written. Text
files could be used, and have the advantage that strings and
numbers can be read/written with ease. They do however impose
certain restrictions on the file:- for example an end of file
condition results in reads returning an eof character (ASCII
character 26), so confusing ’no characters to read’ with
’character 26 read’. The user may find that text files will suffice
for their application. The Assign procedure initialises the file
variable with certain internal parameters and the name of the file
or device. The files are opened with the procedures Reset, for
input, and ReWrite, for output. Before performing the open
input/output error checking is switched off with the compiler
directive {$I-}. If the Reset or ReWrite fails (ComName may
have been set to a non-valid device with the C command in
Pasterm) then the function IOResult returns a non-zero value.
Open_Com tests this, and generates an error message and closes
the files if the value after either Reset or ReWrite is non_zero.
If error checking had not been disabled with {$I-} then a failure
would halt the program with an error message. When the open is
complete error checking is enabled with {$I+}.
At this stage the device driver has not been accessed. The
Reset and ReWrite functions have simply allowed Turbo Pascal
and DOS to prepare for I/O to the port, setting up their variables
and buffers.
MS-DOS can process characters as they are sent and
received. We can alter the mode that DOS assigns to the file
from the default (called ’cooked’, where this processing is
performed) to a more direct one (called ’raw’). The raw mode
has the second advantage that data transfers are performed on as
many bytes as possible at a time, rather than one byte at a time,
as cooked mode does. The change from cooked to raw mode is
performed by the procedure UnCook, which is local to
Open_Com. This uses DOS service $44 to read alter, and set the
device data that DOS maintains. It accesses the record structure
Page 144 Chapter 9