Technical information
Cterm Serial Solutions
Reading From The File._____________________
The function inpstr(), below, reads from the serial port.
Figure 7-3. Function inpstr()._________________________
/* Read a character from com port. */
/* If echo to line true then send it back out. */
/* Return value is number of bytes read. */
int inpstr(char *data)
{
int c;
c = getc( com_inp );
*data = char( c );
if( c == EOF )
{
clearerr( com_inp);
return 0; /* EOF is error condition ==> return none. */
}
else
{
if( echo & echol ) /* If echo set then send back out. */
outstr(data, 1);
return 1;
};
}
The read is performed by getc(). It is at the first access of
the port for a read or write that the driver itself is actually
accessed. It sets up its internal buffers, which are essential for
interrupt driven I/O, and initialises the serial hardware. If the
driver can return no data then getc() returns the value EOF (end
of file), which inpstr() checks. Inpstr() also handles echo to line,
by calling outstr(), the serial output function.
Writing To The File.__________________
Writes to the serial port are performed by outstr() below.
Chapter 7 Page 121