Technical information
Serial Solutions Cterm
characters sent to and received from the serial port. If the open
fails (comname may have been set to a non-valid device with
the C command in CTERM) then fopen returns a value NULL.
Open_com tests this and generates an error message if the value
is NULL.
At this stage the device driver has not been accessed. The
fopen statement has allowed C and DOS to prepare for I/O to
the port, setting up their variables and buffers.
MS-DOS as well as C can alter characters as they are sent
and received. We can alter the mode that DOS assigns to the file
from the default (called ’cooked’, where translations are
performed) to a more direct one (called ’raw’). The raw mode
has the 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 function uncook(), shown in Figure 7-2.
Figure 7-2. Function uncook().___________________________
/* Alter mode of file from cooked (DOS default) to raw. */
/* Prevents translation of CR/LF, trapping of CTRL-Z and */
/* Allows read/write operations to be performed more efficiently. */
void uncook(FILE *file)
{
union REGS inregs, outregs;
/* Change IOCTL from Cooked to RAW data function 0x44. */
inregs.h.ah = 0x44;
inregs.h.al = 0x00; /* get device data */
inregs.x.bx = fileno(file);
intdos( &inregs, &outregs );
inregs.x.dx=outregs.x.dx;
inregs.h.dl=inregs.h.dl | 0x20; /* set raw data mode */
inregs.h.dh=0;
inregs.h.al = 0x01; /* set device data */
intdos( &inregs, &outregs );
}
Uncook() uses DOS service 0x44 to read alter, and set the
device data that DOS maintains. It uses the C function fileno()
to find the handle (a short integer) that DOS associates with the
file.
Page 120 Chapter 7