Koduino
Public Member Functions | List of all members
Stream Class Referenceabstract

Stream library inherited by Wire, Serial, etc. More...

#include <Stream.h>

Detailed Description

Stream library inherited by Wire, Serial, etc.

Authors
Arduino team, Avik De avikd.nosp@m.e@gm.nosp@m.ail.c.nosp@m.om

This file is part of koduino https://github.com/avikde/koduino

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, see http://www.gnu.org/licenses/.

Stream, Print, String

Stream is a collection of functions for ASCII or binary streams used by Serial, Wire, etc. These methods are identical to the Arduino equivalents.

The Arduino String library is included as well.

Streaming

The excellent Streaming library is also available.

Example

#include <Arduino.h>
void setup() {
Serial1.begin(115200);
}
void loop() {
Serial1 << "The time is " << millis() << " and PI = " << PI << "\n";
delay(1000);
}

Public Member Functions

virtual int available ()=0
 Return the number of bytes in the receive buffer. More...
 
virtual int read ()=0
 Reads a single byte from the receive buffer. More...
 
virtual int peek ()=0
 Reads a single byte from the receive buffer. More...
 
virtual void flush ()=0
 Waits till the previous write operation is finished.
 
void setTimeout (uint32_t timeout)
 Sets maximum milliseconds to wait for stream data. More...
 
bool find (char *target)
 Reads data from the stream until the target string is found. More...
 
bool find (char *target, size_t length)
 Reads data from the stream until the target string of given length is found. More...
 
bool findUntil (char *target, char *terminator)
 Same as find() but search ends if the terminator string is found. More...
 
int parseInt ()
 Returns the first valid (long) integer value from the current position. More...
 
float parseFloat ()
 Float version of parseInt() More...
 
size_t readBytes (char *buffer, size_t length)
 Read chars from stream into buffer. More...
 
size_t readBytesUntil (char terminator, char *buffer, size_t length)
 Same as readBytes() with terminator character. More...
 

Inherits Print.

Inherited by TwoWire, and USARTClass.

Member Function Documentation

virtual int Stream::available ( )
pure virtual

Return the number of bytes in the receive buffer.

Returns

Implemented in TwoWire, and USARTClass.

bool Stream::find ( char *  target)

Reads data from the stream until the target string is found.

Parameters
target
Returns
true if target string is found, false if timed out (see setTimeout)
bool Stream::find ( char *  target,
size_t  length 
)

Reads data from the stream until the target string of given length is found.

Parameters
target
length
Returns
true if target string is found, false if timed out
bool Stream::findUntil ( char *  target,
char *  terminator 
)

Same as find() but search ends if the terminator string is found.

Parameters
target
terminator
Returns
float Stream::parseFloat ( )

Float version of parseInt()

Returns
int Stream::parseInt ( )

Returns the first valid (long) integer value from the current position.

Initial characters that are not digits (or the minus sign) are skipped. Integer is terminated by the first character that is not a digit.

Returns
virtual int Stream::peek ( )
pure virtual

Reads a single byte from the receive buffer.

Does not increment the buffer pointer

Returns

Implemented in TwoWire, and USARTClass.

virtual int Stream::read ( )
pure virtual

Reads a single byte from the receive buffer.

Increments the buffer pointer

Returns

Implemented in TwoWire, and USARTClass.

size_t Stream::readBytes ( char *  buffer,
size_t  length 
)

Read chars from stream into buffer.

Terminates if length characters have been read or timeout (see setTimeout())

Parameters
buffer
length
Returns
The number of characters placed in the buffer (0 means no valid data found)
size_t Stream::readBytesUntil ( char  terminator,
char *  buffer,
size_t  length 
)

Same as readBytes() with terminator character.

Terminates if length characters have been read, timeout, or if the terminator character detected

Parameters
terminator
buffer
length
Returns
the number of characters placed in the buffer (0 means no valid data found)
void Stream::setTimeout ( uint32_t  timeout)

Sets maximum milliseconds to wait for stream data.

Parameters
timeoutDefault is 1 second

The documentation for this class was generated from the following files: