COMM-DRV/Lib: GetString() Gets a carriage return, line feed, or null terminated string from receive buffer

Description-

This function attempts to get a string from the serial port. A string is considered to be a set of characters delimited by a carriage return, a linefeed, or a NULL character. This function throws away said characters. The returned string is always null terminated. This function will wait for up to the amount of time set by SetTimeout() before returning if an entire string is not read. A partial string will be read if the time-out occurs before one of the above delimiting characters is read or if an attempt to read a string larger than the specified buffer is read.

Syntax-

count = GetString(port,len,str);

On Entry-

int port;

Port previously opened with OpenComPort().

int len;

Length of the buffer in which to place the string.

char *str;

Pointer to the buffer for the string.

On Exit-

int    count;

Number of bytes returned.

See Also-

GetByte()
GetPacket()

Example-

#include <comm.h>

int     count;
int     port=0;
char   buf[256];

if ((count = GetString(port,sizeof(buf),buf)) == 0)
    {
    printf("No bytes returned\n");

    /* Take remedial action*/

    break;
    }