Stream Class Functions In Arduino Programming Language
Stream Functions In Arduino Programming Language:
available()
Description
available() gets the number of bytes available in the stream. This is only for bytes that have already arrived.
This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the Stream class main page for more information.
Syntax
stream.available()
Parameters
stream : an instance of a class that inherits from Stream.
Returns
int : the number of bytes available to read
read()
Description
read() reads characters from an incoming stream to the buffer.
This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the Stream class main page for more information.
Syntax
stream.read()
Parameters
stream : an instance of a class that inherits from Stream.
Returns
the first byte of incoming data available (or -1 if no data is available)
flush()
Description
flush() clears the buffer once all outgoing characters have been sent.
This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the Stream class main page for more information.
Syntax
stream.flush()
Parameters
stream : an instance of a class that inherits from Stream.
Returns
boolean
find()
Description
find() reads data from the stream until the target string of given length is found
The function returns true if target string is found, false if timed out.
This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the Stream class main page for more information.
Syntax
stream.find(target)
Parameters
stream : an instance of a class that inherits from Stream.
target : the string to search for (char)
Returns
boolean
findUntil()
Description
findUntil() reads data from the stream until the target string of given length or terminator string is found.
The function returns true if target string is found, false if timed out
This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the Stream class main page for more information.
Syntax
stream.findUntil(target, terminal)
Parameters
stream : an instance of a class that inherits from Stream.
target : the string to search for (char)
terminal : the terminal string in the search (char)
Returns
boolean
peek()
Read a byte from the file without advancing to the next one. That
is, successive calls to peek() will return the same value, as will the
next call to read().
This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the Stream class main page for more information.
Syntax
stream.peek()
Parameters
stream : an instance of a class that inherits from Stream.
Returns
The next byte (or character), or -1 if none is available.
readBytes()
Description
readBytes() read characters from a stream into a buffer. The function
terminates if the determined length has been read, or it times out (see
setTimeout()).
readBytes() returns the number of characters placed in the buffer. A 0 means no valid data was found.
This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the Stream class main page for more information.
Syntax
stream.readBytes(buffer, length)
Parameters
stream : an instance of a class that inherits from Stream.
buffer: the buffer to store the bytes in (char[] or byte[])
length : the number of bytes to read (int)
Returns
byte
readBytesUntil()
Description
readBytesUntil() read characters from a stream into a buffer. The
function terminates if the terminator character is detected, the
determined length has been read, or it times out (see setTimeout()).
readBytesUntil() returns the number of characters placed in the buffer. A 0 means no valid data was found.
This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the Stream class main page for more information.
Syntax
stream.readBytesUntil(character, buffer, length)
Parameters
stream : an instance of a class that inherits from Stream.
character : the character to search for (char)
buffer: the buffer to store the bytes in (char[] or byte[])
length : the number of bytes to read (int)
Returns
byte
parseInt()
Description
parseInt() returns the first valid (long) integer number from the
current position. Initial characters that are not integers (or the minus
sign) are skipped.
parseInt() is terminated by the first character that is not a digit.
This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the Stream class main page for more information.
Syntax
stream.parseInt(list)
Parameters
stream : an instance of a class that inherits from Stream.
list : the stream to check for ints (char)
Returns
int
parseFloat()
Description
parseFloat() returns the first valid floating point number from the
current position. Initial characters that are not digits (or the minus
sign) are skipped.
parseFloat() is terminated by the first character that is not a floating
point number.
This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the Stream class main page for more information.
Syntax
stream.parseFloat(list)
Parameters
stream : an instance of a class that inherits from Stream.
list : the stream to check for floats (char)
Returns
float
setTimeout()
Description
setTimeout() sets the maximum milliseconds to wait for stream data,
it defaults to 1000 milliseconds. This function is part of the Stream
class, and is called by any class that inherits from it (Wire, Serial,
etc). See the Stream class main page for more information.
Syntax
stream.setTimeout(time)
Parameters
stream : an instance of a class that inherits from Stream.
time : timeout duration in milliseconds (long).
Parameters
None