Package virtualbreadboard.arduino
Class Stream
java.lang.Object
virtualbreadboard.arduino.PrintFormatter
virtualbreadboard.arduino.Stream
- Direct Known Subclasses:
Serial
Port of the Arduino Stream API
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
available() gets the number of bytes available in the stream.boolean
find() reads data from the stream until the target string of given length is foundboolean
void
flush()
Waits for uptimeout
milliseconds for the output buffer to be cleared before clearing any unsent data from from the buffer.Searches the stream for the first matching token in an array of tokens.double
float
parseFloat() returns the first valid floating point number from the Stream buffer.int
parseInt()
long
int
peek()
Returns the next byte of of incoming stream without removing it from the internal buffer.int
read()
read() reads characters from an incoming stream to the buffer.int
readBytes
(byte[] buffer, int len) int
readBytes
(byte[] buffer, int offset, int len) Reads up tolen
bytes of data from the stream into an array of bytes.int
readBytesUntil
(byte eol, byte[] buffer, int len) Reads up tolen
bytes of data from the stream into an array of bytes.readln()
void
setTimeout
(long timeout) toString()
void
write
(byte[] writeMe, int pos, int len) void
write
(int writeMe) void
-
Constructor Details
-
Stream
public Stream()
-
-
Method Details
-
write
- Specified by:
write
in classPrintFormatter
-
write
public void write(byte[] writeMe, int pos, int len) -
write
public void write(int writeMe) - Specified by:
write
in classPrintFormatter
-
available
public int available()available() gets the number of bytes available in the stream. This is only for bytes that have already arrived.- Returns:
- the number of bytes available to read
-
read
public int read()read() reads characters from an incoming stream to the buffer.- Returns:
- the first byte of incoming data available (or -1 if no data is available)
-
readExisting
-
readBytes
public int readBytes(byte[] buffer, int offset, int len) Reads up tolen
bytes of data from the stream into an array of bytes. An attempt is made to read as many aslen
bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.This method blocks until input data is available or times out after
timeout
milliseconds.- Parameters:
buffer
- the buffer into which the data is read.offset
- the start offset in array b at which the data is written.len
- the maximum number of bytes to read.- Returns:
- the total number of bytes read into the buffer
- See Also:
-
setTimeout()
-
readBytes
public int readBytes(byte[] buffer, int len) -
readBytesUntil
public int readBytesUntil(byte eol, byte[] buffer, int len) Reads up tolen
bytes of data from the stream into an array of bytes. An attempt is made to read as many aslen
bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.This method blocks until input data is available,
eol
character is detected, or times out aftertimeout
milliseconds. If- Parameters:
eol
-buffer
-len
-- Returns:
-
peek
public int peek()Returns the next byte of of incoming stream without removing it from the internal buffer. That is, successive calls to peek() will return the same byte, as will the next call to read().- Returns:
- the next byte of stream, returns -1 if the buffer is empty.
-
flush
public void flush()Waits for uptimeout
milliseconds for the output buffer to be cleared before clearing any unsent data from from the buffer. -
find
find() reads data from the stream until the target string of given length is found- Returns:
- true if target string is found, false if timed out.
-
findUntil
-
nextToken
Searches the stream for the first matching token in an array of tokens.- Parameters:
tokens
- is an array of tokens to search the stream for- Returns:
- the matching token else null if timed out
-
setTimeout
public void setTimeout(long timeout) -
parseFloat
public float parseFloat()parseFloat() returns the first valid floating point number from the Stream buffer. 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.- Returns:
-
parseDouble
public double parseDouble() -
parseInt
public int parseInt() -
parseLong
public long parseLong() -
toString
-
readln
-