Technical information

Serial Solutions Cterm
Figure 7-4. Function outstr()._________________________
/* Send a string of characters to com port. */
/* This routine must deal with write errors on COM port. */
void outstr(char *data, int count)
{
int i,c;
time_t t1, t2;
for(i = 0; i < count ; i++)
{
time( &t1 );
fputc(*(data + i), com_out);
fseek(com_out, 0l, SEEK_SET); /* Reset file pointer..means
flush */
while( ferror(com_out)
&& (difftime(time(&t2),t1) < timeout) )
{
clearerr(com_out);
fputc(*(data + i), com_out);
fseek(com_out, 0l, SEEK_SET); /* Reset file
pointer..means flush */
};
if( ferror(com_out) )
{
screen("Failed to output to port.\n",fromctrl);
/* Write failure */
clearerr(com_out);
};
};
}
The output function in C used is fputc(). The ferror
function is used to detect any problems with writing the
character. The problem may be a full output buffer at the driver
level. Outstr handles this by trying to send each byte until the
error condition ends. If after a time interval set by the variable
timeout the error persists outstr gives up and prints an error
message. The other terminal programs do not perform these
retrys- they are present here to support the put command, which
relies on outstr sending all the bytes given to it to the file.
Page 122 Chapter 7