public class SerialDataEvent extends EventObject
This class provides the serial data event object.
Before using the Pi4J library, you need to ensure that the Java VM in configured with access to the following system libraries:
This library depends on the wiringPi native system library. (developed by Gordon Henderson @ http://wiringpi.com/)
Serial
,
SerialDataEventListener
,
SerialDataReader
,
SerialFactory
,
http://www.pi4j.com/,
Serialized FormModifier and Type | Field and Description |
---|---|
protected static char[] |
hexArray |
source
Constructor and Description |
---|
SerialDataEvent(Serial serial)
Default event constructor.
|
SerialDataEvent(Serial serial,
byte[] data)
Default event constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
discardData()
discard/drain all available bytes from the serial data receive buffer
|
String |
getAsciiString()
Get an ASCII string representation of the bytes available in the serial data receive buffer
|
ByteBuffer |
getByteBuffer()
Get all the bytes (byte-buffer) available in the serial data receive buffer
|
byte[] |
getBytes()
Get all the bytes (byte-array) available in the serial data receive buffer
|
CharBuffer |
getCharBuffer(Charset charset)
Get a character buffer of the bytes available in the serial data receive buffer
|
String |
getHexByteString()
Get a HEX string representation of the bytes available in the serial data receive buffer
|
String |
getHexByteString(CharSequence prefix,
CharSequence separator,
CharSequence suffix)
Get a HEX string representation of the bytes available in the serial data receive buffer
|
SerialDataReader |
getReader()
Get an instance of the serial data reader
|
Serial |
getSerial()
Get the serial interface instance
|
String |
getString(Charset charset)
Get a string representation of the bytes available in the serial data receive buffer
|
int |
length()
Get the number of bytes available in the serial data
|
getSource, toString
protected static final char[] hexArray
public SerialDataEvent(Serial serial)
public SerialDataEvent(Serial serial, byte[] data)
public SerialDataReader getReader()
public int length() throws IOException
IOException
public byte[] getBytes() throws IOException
IOException
public ByteBuffer getByteBuffer() throws IOException
IOException
public String getString(Charset charset) throws IOException
charset
- the character-set used to construct the string from the underlying byte arrayIOException
public String getAsciiString() throws IOException
IOException
public String getHexByteString() throws IOException
IOException
public String getHexByteString(CharSequence prefix, CharSequence separator, CharSequence suffix) throws IOException
prefix
- optional prefix string to append before each data byteseparator
- optional separator string to append in between each data byte sequencesuffix
- optional suffix string to append after each data byteIOException
public CharBuffer getCharBuffer(Charset charset) throws IOException
charset
- the character-set used to construct the character buffer from the underlying byte arrayIOException
public void discardData() throws IllegalStateException, IOException
discard/drain all available bytes from the serial data receive buffer
IllegalStateException
IOException
Copyright © 2012–2019 Pi4J. All rights reserved.