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 TypeMethodDescriptionintavailable() gets the number of bytes available in the stream.booleanfind() reads data from the stream until the target string of given length is foundbooleanvoidflush()Waits for uptimeoutmilliseconds 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.doublefloatparseFloat() returns the first valid floating point number from the Stream buffer.intparseInt()longintpeek()Returns the next byte of of incoming stream without removing it from the internal buffer.intread()read() reads characters from an incoming stream to the buffer.intreadBytes(byte[] buffer, int len) intreadBytes(byte[] buffer, int offset, int len) Reads up tolenbytes of data from the stream into an array of bytes.intreadBytesUntil(byte eol, byte[] buffer, int len) Reads up tolenbytes of data from the stream into an array of bytes.readln()voidsetTimeout(long timeout) toString()voidwrite(byte[] writeMe, int pos, int len) voidwrite(int writeMe) void
-
Constructor Details
-
Stream
public Stream()
-
-
Method Details
-
write
- Specified by:
writein classPrintFormatter
-
write
public void write(byte[] writeMe, int pos, int len) -
write
public void write(int writeMe) - Specified by:
writein 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 tolenbytes of data from the stream into an array of bytes. An attempt is made to read as many aslenbytes, 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
timeoutmilliseconds.- 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 tolenbytes of data from the stream into an array of bytes. An attempt is made to read as many aslenbytes, 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,
eolcharacter is detected, or times out aftertimeoutmilliseconds. 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 uptimeoutmilliseconds 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
-