Arduino Core for STM32  1.0
Stream Class Referenceabstract

This class is for receiving and transmitting data. More...

#include <Stream.h>

Inheritance diagram for Stream:
Collaboration diagram for Stream:

Public Member Functions

virtual int available ()=0
 Checks how many bytes are available in receiving buffer. More...
 
virtual int read ()=0
 Reads one byte from receiving buffer and removes it from buffer. More...
 
virtual int peek ()=0
 Reads one byte from receiving buffer and without removing it from buffer. More...
 
 Stream ()
 Constructor. More...
 
Streamoperator>> (char &c)
 This operator (>>) applied to an input stream is known as extraction operator, it can be used same as cin>> operator. More...
 
Streamoperator>> (char *buffer)
 This operator (>>) applied to an input stream is known as extraction operator, it can be used same as cin>> operator. More...
 
Streamoperator>> (uint8_t *buffer)
 This operator (>>) applied to an input stream is known as extraction operator, it can be used same as cin>> operator. More...
 
 __INTEGER_ONLY__ (T, Stream &) operator>>(T &val)
 This operator (>>) applied to an input stream is known as extraction operator, it can be used same as cin>> operator. More...
 
 __FLOATING_ONLY__ (T, Stream &) operator>>(T &val)
 This operator (>>) applied to an input stream is known as extraction operator, it can be used same as cin>> operator. More...
 
void setTimeout (unsigned long timeout)
 Sets the maximum milliseconds to wait for data transmitting or receiving. More...
 
virtual void width (size_t width_)
 Sets receiving width, that is applied when using operators >> (same as cin.width() method). More...
 
bool find (const char *target)
 Reads and removes data from the stream until the target string is found. More...
 
bool find (uint8_t *target)
 Reads and removes data from the stream until the target string is found. More...
 
bool find (const char *target, size_t length)
 Reads and removes data from the stream until the target string is found. More...
 
bool find (const uint8_t *target, size_t length)
 Reads and removes data from the stream until the target string is found. More...
 
bool find (char target)
 Reads and removes data from the stream until the target character is found. More...
 
bool findUntil (const char *target, const char *terminator)
 Reads data from the stream until a target string or terminator string is found. More...
 
bool findUntil (const uint8_t *target, const char *terminator)
 Reads data from the stream until a target string or terminator string is found. More...
 
bool findUntil (const char *target, size_t targetLen, const char *terminate, size_t termLen)
 Reads data from the stream until a target string or terminator string is found. More...
 
bool findUntil (const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
 Reads data from the stream until a target string or terminator string is found. More...
 
long parseInt ()
 Parses the first valid (long) integer number from the stream. More...
 
 __INTEGER_ONLY__ (T, T) inline parseNum()
 Parses the first valid integer number from the stream. More...
 
float parseFloat ()
 Parses the first valid floating point number from the stream. More...
 
 __FLOATING_ONLY__ (T, T) inline parseNum()
 Parses the first valid floating point number from the stream. More...
 
virtual size_t readBytes (char *buffer, size_t length)
 Reads characters from the stream into a buffer. More...
 
virtual size_t readBytes (uint8_t *buffer, size_t length)
 Reads characters from the stream into a buffer. More...
 
size_t readBytesUntil (char terminator, char *buffer, size_t length)
 Reads characters from the stream into a buffer. More...
 
size_t readBytesUntil (char terminator, uint8_t *buffer, size_t length)
 Reads characters from the stream into a buffer. More...
 
- Public Member Functions inherited from Print
 Print ()
 Constructor. More...
 
int getWriteError ()
 Gets write error. More...
 
void clearWriteError ()
 Clears write error. More...
 
virtual size_t write (uint8_t byte)=0
 Writes one unsigned byte (character). More...
 
size_t write (const char *str)
 Writes character array (string). More...
 
virtual size_t write (const uint8_t *buffer, size_t size)
 Writes byte array (string). More...
 
size_t write (const char *buffer, size_t size)
 Writes character array (string). More...
 
 __INTEGER_ONLY__ (T, size_t) inline write(T val)
 Converts integer type variable to unsigned byte and writes it. More...
 
virtual int availableForWrite ()
 Gets how many bytes can be written, meaning "a single write may block". More...
 
size_t printf (const char *format,...) __attribute__((format(printf
 Prints formatted data. More...
 
size_t size_t print (const String &s)
 Prints string. More...
 
size_t print (const char str[])
 Prints character array (string). More...
 
size_t print (char c)
 Prints one character. More...
 
 __SIGNED_INTEGER_ONLY__ (T, size_t) print(T n
 Converts integer number to character array and prints it. More...
 
size_t println (const String &s)
 Prints string followed by carriage return and new line. More...
 
size_t println (const char[])
 Prints character array (string) followed by carriage return and new line. More...
 
size_t println (char)
 Prints one character followed by carriage return and new line. More...
 
 __INTEGER_ONLY__ (T, size_t) inline println(T n
 Converts integer number to character array followed by carriage return and new line and prints it. More...
 
size_t println (void)
 Prints carriage return and new line. More...
 
template<class T >
Printoperator<< (T value)
 This operator (<<) applied to an output stream is known as insertion operator, it can be used same as cout<< operator. More...
 

Protected Member Functions

int timedRead ()
 Private method to read stream with timeout. More...
 
int timedPeek ()
 Private method to peek stream with timeout. More...
 
int peekNextDigit ()
 Gets the next numeric digit in the stream or -1 if timeout. More...
 
long parseInt (char skipChar)
 Parses the first valid (long) integer number from the stream. More...
 
 __INTEGER_ONLY__ (T, T) parseNum(char skipChar)
 Parses the first valid integer number from the stream. More...
 
float parseFloat (char skipChar)
 Parses the first valid floating point number from the stream. More...
 
 __FLOATING_ONLY__ (T, T) parseNum(char skipChar)
 Parses the first valid floating point number from the stream. More...
 
virtual size_t widthCheck (size_t width_)
 Checks if the correct width in width() method was set. More...
 
- Protected Member Functions inherited from Print
void setWriteError (int err=1)
 Sets write error. More...
 

Protected Attributes

unsigned long _timeout = 1000
 Number of milliseconds to wait for the next char before aborting timed read. More...
 
unsigned long _startMillis
 Used for timeout measurement. More...
 
size_t _width = INT32_MAX
 Maximum operator >> read width. More...
 

Additional Inherited Members

- Public Attributes inherited from Print
int base
 

Detailed Description

This class is for receiving and transmitting data.

See also
Stream.h
Print

Constructor & Destructor Documentation

◆ Stream()

Stream::Stream ( )
inline

Constructor.

Member Function Documentation

◆ timedRead()

int Stream::timedRead ( )
protected

Private method to read stream with timeout.

Returns
Returns one character or -1 if nothing was read.
Here is the call graph for this function:

◆ timedPeek()

int Stream::timedPeek ( )
protected

Private method to peek stream with timeout.

Returns
Returns one character or -1 if nothing was read.
Here is the call graph for this function:

◆ peekNextDigit()

int Stream::peekNextDigit ( )
protected

Gets the next numeric digit in the stream or -1 if timeout.

Returns
Returns the next numeric digit in the stream or -1 if timeout.
Here is the call graph for this function:

◆ available()

virtual int Stream::available ( )
pure virtual

Checks how many bytes are available in receiving buffer.

Returns
Returns number of available bytes in receiving buffer or 0 if nothing is available.
Note
You should to override this method in derived class.

Implemented in HardwareSerial, and HardwareI2C.

◆ read()

virtual int Stream::read ( )
pure virtual

Reads one byte from receiving buffer and removes it from buffer.

Returns
Returns one character or -1 if nothing was read.
Note
You should to override this method in derived class.

Implemented in HardwareSerial, and HardwareI2C.

◆ peek()

virtual int Stream::peek ( )
pure virtual

Reads one byte from receiving buffer and without removing it from buffer.

Returns
Returns one character or -1 if nothing was read.
Note
You should to override this method in derived class.

Implemented in HardwareSerial, and HardwareI2C.

◆ operator>>() [1/3]

Stream & Stream::operator>> ( char &  c)

This operator (>>) applied to an input stream is known as extraction operator, it can be used same as cin>> operator.

Parameters
cReads one character to this variable.
Returns
Returns stream class.
Here is the call graph for this function:

◆ operator>>() [2/3]

Stream & Stream::operator>> ( char *  buffer)

This operator (>>) applied to an input stream is known as extraction operator, it can be used same as cin>> operator.

Note
Reading to buffer is terminated when white character was read or when received data count is higher or equals as width (see width()).
Parameters
bufferReads characters from stream to this buffer.
Returns
Returns stream class.
Here is the call graph for this function:

◆ operator>>() [3/3]

Stream & Stream::operator>> ( uint8_t *  buffer)

This operator (>>) applied to an input stream is known as extraction operator, it can be used same as cin>> operator.

Note
Reading to buffer is terminated when white character was read or when received data count is higher or equals as width (see width()).
Parameters
bufferReads characters from stream to this buffer.
Returns
Returns stream class.
Here is the call graph for this function:

◆ __INTEGER_ONLY__() [1/3]

Stream::__INTEGER_ONLY__ ( ,
Stream  
) &
inline

This operator (>>) applied to an input stream is known as extraction operator, it can be used same as cin>> operator.

Note
This operator works same as parseInt() or parseNum() (only for integers types) methods.
Parameters
valRead value is written to this variable.
Returns
Returns stream class.

◆ __FLOATING_ONLY__() [1/3]

Stream::__FLOATING_ONLY__ ( ,
Stream  
) &
inline

This operator (>>) applied to an input stream is known as extraction operator, it can be used same as cin>> operator.

Note
This operator works same as parseFloat() or parseNum() (only for floating point types) methods.
Parameters
valRead value is written to this variable.
Returns
Returns stream class.

◆ setTimeout()

void Stream::setTimeout ( unsigned long  timeout)

Sets the maximum milliseconds to wait for data transmitting or receiving.

It defaults to 1000 milliseconds.

Parameters
timeoutTimeout in milliseconds.

◆ width()

void Stream::width ( size_t  width_)
virtual

Sets receiving width, that is applied when using operators >> (same as cin.width() method).

Parameters
width_Data width, that can be received at one time with >> operator to char array.
Note
You should to override this method in derived class.

◆ find() [1/5]

bool Stream::find ( const char *  target)

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

Parameters
targetTarget string.
Returns
Returns true if target string is found, false if timed out (see setTimeout).
Here is the call graph for this function:

◆ find() [2/5]

bool Stream::find ( uint8_t *  target)
inline

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

Parameters
targetTarget string.
Returns
Returns true if target string is found, false if timed out (see setTimeout).
Here is the call graph for this function:

◆ find() [3/5]

bool Stream::find ( const char *  target,
size_t  length 
)

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

Parameters
targetTarget string.
lengthLength of the target string.
Returns
Returns true if target string is found, false if timed out (see setTimeout).
Here is the call graph for this function:

◆ find() [4/5]

bool Stream::find ( const uint8_t *  target,
size_t  length 
)
inline

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

Parameters
targetTarget string.
lengthLength of the target string.
Returns
Returns true if target string is found, false if timed out (see setTimeout).
Here is the call graph for this function:

◆ find() [5/5]

bool Stream::find ( char  target)
inline

Reads and removes data from the stream until the target character is found.

Parameters
targetTarget character.
Returns
Returns true if target character is found, false if timed out (see setTimeout).
Here is the call graph for this function:

◆ findUntil() [1/4]

bool Stream::findUntil ( const char *  target,
const char *  terminator 
)

Reads data from the stream until a target string or terminator string is found.

Parameters
targetThe string to search for.
terminatorThe terminal string in the search.
Returns
Returns true if target string is found, false if timed out (see setTimeout).

◆ findUntil() [2/4]

bool Stream::findUntil ( const uint8_t *  target,
const char *  terminator 
)
inline

Reads data from the stream until a target string or terminator string is found.

Parameters
targetThe string to search for.
terminatorThe terminal string in the search.
Returns
Returns true if target string is found, false if timed out (see setTimeout).
Here is the call graph for this function:

◆ findUntil() [3/4]

bool Stream::findUntil ( const char *  target,
size_t  targetLen,
const char *  terminate,
size_t  termLen 
)

Reads data from the stream until a target string or terminator string is found.

Parameters
targetThe string to search for.
targetLenLength of the target string.
terminatorThe terminal string in the search.
targetLenLength of the terminator string.
Returns
Returns true if target string is found, false if timed out (see setTimeout).
Here is the call graph for this function:

◆ findUntil() [4/4]

bool Stream::findUntil ( const uint8_t *  target,
size_t  targetLen,
const char *  terminate,
size_t  termLen 
)
inline

Reads data from the stream until a target string or terminator string is found.

Parameters
targetThe string to search for.
targetLenLength of the target string.
terminatorThe terminal string in the search.
targetLenLength of the terminator string.
Returns
Returns true if target string is found, false if timed out (see setTimeout).
Here is the call graph for this function:

◆ parseInt() [1/2]

long Stream::parseInt ( )
inline

Parses the first valid (long) integer number from the stream.

Characters that are not integers (or the minus sign) are skipped. Parsing stops when no characters have been read for a configurable time-out value, or a non-digit is read. If no valid digits were read when the time-out occurs (see setTimeout()), 0 is returned.

Returns
Returns the first valid (long) integer number from the stream.

◆ __INTEGER_ONLY__() [2/3]

Stream::__INTEGER_ONLY__ ( ,
 
)
inline

Parses the first valid integer number from the stream.

Characters that are not integers (or the minus sign) are skipped. Parsing stops when no characters have been read for a configurable time-out value, or a non-digit is read. If no valid digits were read when the time-out occurs (see setTimeout()), 0 is returned.

Returns
Returns the first valid integer number from the stream.
Note
Use this method like this: Stream.parseNum<type>(); example for int32_t: int32_t value = Serial.parseNum<int32_t>();

◆ parseFloat() [1/2]

float Stream::parseFloat ( )
inline

Parses the first valid floating point number from the stream.

Characters that are not digits (or the minus sign or the decimal point) are skipped. Parsing stops when no characters have been read for a configurable time-out value, or a non-digit is read. If no valid digits were read when the time-out occurs (see setTimeout()), 0 is returned.

Returns
Returns the first valid floating point number from the stream.

◆ __FLOATING_ONLY__() [2/3]

Stream::__FLOATING_ONLY__ ( ,
 
)
inline

Parses the first valid floating point number from the stream.

Characters that are not digits (or the minus sign or the decimal point) are skipped. Parsing stops when no characters have been read for a configurable time-out value, or a non-digit is read. If no valid digits were read when the time-out occurs (see setTimeout()), 0 is returned.

Returns
Returns the first valid floating point number from the stream.
Note
Use this method like this: Stream.parseNum<type>(); example for float: float value = Serial.parseNum<float>();

◆ readBytes() [1/2]

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

Reads characters from the stream into a buffer.

The function terminates if the determined length has been read, or it times out (see setTimeout()).

Parameters
bufferBuffer, where to read data.
lengthLength of the data, you want to read.
Returns
Returns number of successfully read bytes.
Note
You should to override this method in derived class.

Reimplemented in HardwareSerial.

Here is the call graph for this function:

◆ readBytes() [2/2]

virtual size_t Stream::readBytes ( uint8_t *  buffer,
size_t  length 
)
inlinevirtual

Reads characters from the stream into a buffer.

The function terminates if the determined length has been read, or it times out (see setTimeout()).

Parameters
bufferBuffer, where to read data.
lengthLength of the data, you want to read.
Returns
Returns number of successfully read bytes.
Note
You should to override this method in derived class.

Reimplemented in HardwareSerial.

Here is the call graph for this function:

◆ readBytesUntil() [1/2]

size_t Stream::readBytesUntil ( char  terminator,
char *  buffer,
size_t  length 
)

Reads characters from the stream into a buffer.

The function terminates (checks being done in this order) if the determined length has been read, if it times out (see setTimeout()), or if the terminator character is detected (in which case the function returns the characters up to the last character before the supplied terminator).

Note
The terminator itself is not returned in the buffer.
Parameters
terminatorTerminator character.
bufferBuffer, where to read data.
lengthLength of the data, you want to read.
Returns
Returns number of successfully read bytes.
Here is the call graph for this function:

◆ readBytesUntil() [2/2]

size_t Stream::readBytesUntil ( char  terminator,
uint8_t *  buffer,
size_t  length 
)
inline

Reads characters from the stream into a buffer.

The function terminates (checks being done in this order) if the determined length has been read, if it times out (see setTimeout()), or if the terminator character is detected (in which case the function returns the characters up to the last character before the supplied terminator).

Note
The terminator itself is not returned in the buffer.
Parameters
terminatorTerminator character.
bufferBuffer, where to read data.
lengthLength of the data, you want to read.
Returns
Returns number of successfully read bytes.
Here is the call graph for this function:

◆ parseInt() [2/2]

long Stream::parseInt ( char  skipChar)
inlineprotected

Parses the first valid (long) integer number from the stream.

Characters that are not integers (or the minus sign) are skipped. Parsing stops when no characters have been read for a configurable time-out value, or a non-digit is read. If no valid digits were read when the time-out occurs (see setTimeout()), 0 is returned.

Parameters
skipCharCharacter, that will be ignored.
Returns
Returns the first valid (long) integer number from the stream.

◆ __INTEGER_ONLY__() [3/3]

Stream::__INTEGER_ONLY__ ( ,
 
)
inlineprotected

Parses the first valid integer number from the stream.

Characters that are not integers (or the minus sign) are skipped. Parsing stops when no characters have been read for a configurable time-out value, or a non-digit is read. If no valid digits were read when the time-out occurs (see setTimeout()), 0 is returned.

Parameters
skipCharCharacter, that will be ignored.
Returns
Returns the first valid integer number from the stream.
Note
Use this method like this: Stream.parseNum<type>(); example for int32_t: int32_t value = Serial.parseNum<int32_t>();
Here is the call graph for this function:

◆ parseFloat() [2/2]

float Stream::parseFloat ( char  skipChar)
inlineprotected

Parses the first valid floating point number from the stream.

Characters that are not digits (or the minus sign or the decimal point) are skipped. Parsing stops when no characters have been read for a configurable time-out value, or a non-digit is read. If no valid digits were read when the time-out occurs (see setTimeout()), 0 is returned.

Parameters
skipCharCharacter, that will be ignored.
Returns
Returns the first valid floating point number from the stream.
Here is the call graph for this function:

◆ __FLOATING_ONLY__() [3/3]

Stream::__FLOATING_ONLY__ ( ,
 
)
inlineprotected

Parses the first valid floating point number from the stream.

Characters that are not digits (or the minus sign or the decimal point) are skipped. Parsing stops when no characters have been read for a configurable time-out value, or a non-digit is read. If no valid digits were read when the time-out occurs (see setTimeout()), 0 is returned.

Returns
Returns the first valid floating point number from the stream.
Parameters
skipCharCharacter, that will be ignored.
Note
Use this method like this: Stream.parseNum<type>(); example for float: float value = Serial.parseNum<float>();
Here is the call graph for this function:

◆ widthCheck()

size_t Stream::widthCheck ( size_t  width_)
protectedvirtual

Checks if the correct width in width() method was set.

Parameters
width_Width value to check.
Returns
Returns corrected width value.

Reimplemented in HardwareSerial.

Member Data Documentation

◆ _timeout

unsigned long Stream::_timeout = 1000
protected

Number of milliseconds to wait for the next char before aborting timed read.

◆ _startMillis

unsigned long Stream::_startMillis
protected

Used for timeout measurement.

◆ _width

size_t Stream::_width = INT32_MAX
protected

Maximum operator >> read width.


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