入门基础

Arduino中Stream的应用

字号+ 作者:duino123.com 来源:未知 2016-05-09 22:36 我要评论( )

Stream即数据流,包括字符和二进制数据流,Stream不是直接调用的,但是在所有依赖于数据流的函数都与Stream相关。

PLCLIVE.COM注:

Stream即数据流,包括字符和二进制数据流,Stream不是直接调用的,但是在所有依赖于数据流的函数都与Stream相关。



Stream

Stream defines the reading functions in Arduino. When using any core functionality that uses a read() or similar method, you can safely assume it calls on the Stream class. For functions like print(), Stream inherits from the Print class.

Some of the libraries that rely on Stream include :

Serial
Wire
Ethernet Client
Ethernet Server
SD


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). 

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)
 


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). 

Syntax

stream.available()

Parameters

stream : an instance of a class that inherits from Stream.

Returns

int : the number of bytes available to read
 


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).

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).

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). 

Syntax

stream.findUntil(targetterminal)

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). 

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 .

readBytes() returns the number of bytes 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). 

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

The number of bytes placed in the buffer
 


readBytesUntil()

Description

readBytesUntil() reads 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.

readBytesUntil() returns the number of bytes 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). 

Syntax

stream.readBytesUntil(characterbufferlength)

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

The number of bytes placed in the buffer
 


readString()

Description

readString() reads characters from a stream into a string. The function terminates if it times out .

This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). 

Syntax

stream.readString()

Parameters

none

Returns

A string read from a stream
 


readStringUntil()

Description

readStringUntil() reads characters from a stream into a string. The function terminates if the terminator character is detected or it times out.

This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). 

Syntax

stream.readString(terminator)

Parameters

terminator : the character to search for (char)

Returns

The entire string read from a stream, until the terminator character is detected
 


parseInt()

Description

parseInt() returns the first valid (long) integer number from the serial buffer. Characters that are not integers (or the minus sign) are skipped.

In particular:

  • Initial characters that are not digits or a 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, 0 is returned;

This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). 

Syntax

stream.parseInt(list)

stream.parseInt(''list', char skipchar')

Parameters

stream : an instance of a class that inherits from Stream.
list : the stream to check for ints (char) skipChar: used to skip the indicated char in the search. Used for example to skip thousands divider.

Returns

long
 


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).

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). 

Syntax

stream.setTimeout(time)

Parameters

stream : an instance of a class that inherits from Stream.
time : timeout duration in milliseconds (long).

Parameters

None

 

如需更详细资料,如有好资源分享,请加入QQ交流群:214461008

欢迎阅读,欢迎转载,不用注明出处!本站只提供入门和进阶资料,做您学习的小伙伴!

老司机也欢迎光临指导!有好内容请加群:214461008 不要看声明了,看内容吧!

相关文章
  • Arduino中int和char之间的转换

    Arduino中int和char之间的转换

    2016-05-17 23:29

  • 如何使用Eclipse开发Arduino程序

    如何使用Eclipse开发Arduino程序

    2016-05-13 15:48

  • 通过串口命令Arduino控制8路继电器的实现

    通过串口命令Arduino控制8路继电器的实现

    2016-05-13 14:18

  • Arduino如何产生随机数

    Arduino如何产生随机数

    2016-05-09 21:31

网友点评