<< Previous | Next >>

cof_serXgets

int cof_serXgets( char * s, int max, unsigned long tmout ); /* where X is A-F */

Description

This single-user cofunction reads characters from port X until a null terminator, linefeed, or carriage return character is read, max characters are read, or until tmout milliseconds transpires between characters read. A timeout will never occur if no characters have been received. This function is non-reentrant. It yields to other tasks for as long as the input buffer is locked or whenever the buffer becomes empty as characters are read. s will always be null terminated upon return. The functions cof_serEgets() and cof_serFgets() may be used with the Rabbit 3000 or Rabbit 4000.

NOTE Alternatively you can use another form of this function that has been generalized for all serial ports. Instead of substituting for "X" in the function name, the prototype of the generalized function is: cof_serXgets(int port, ...), where "port" is one of the macros SER_PORT_A through SER_PORT_F.

Parameters

s
Character array into which a null terminated string is read.

max
The maximum number of characters to read into s.

tmout
Millisecond wait period between characters before timing out.

Return value

1 if CR or max bytes read into s.
0 if function times out before reading CR or max bytes.

Library

RS232.LIB

Example

   

main() {                 // echoes null terminated character strings 
int getOk;
char s[16];
serAopen(19200);
loopinit();
while (1) {
loophead();
costate {
wfd getOk = cof_serAgets (s, 15, 20);
if (getOk)
wfd cof_serAputs(s);
else { //
timed out: s null terminated, but incomplete
}
}
}
serAclose();
}

Dynamic C Functions << Previous | Next >> rabbit.com