Package com.pi4j.io.serial
Class SerialDataEvent
- java.lang.Object
-
- java.util.EventObject
-
- com.pi4j.io.serial.SerialDataEvent
-
- All Implemented Interfaces:
Serializable
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:
- pi4j
- wiringPi
This library depends on the wiringPi native system library. (developed by Gordon Henderson @ http://wiringpi.com/)
- Author:
- Robert Savage (http://www.savagehomeautomation.com)
- See Also:
Serial
,SerialDataEventListener
,SerialDataReader
,SerialFactory
, https://pi4j.com/, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static char[]
hexArray
-
Fields inherited from class java.util.EventObject
source
-
-
Constructor Summary
Constructors Constructor Description SerialDataEvent(Serial serial)
Default event constructor.SerialDataEvent(Serial serial, byte[] data)
Default event constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
discardData()
discard/drain all available bytes from the serial data receive bufferString
getAsciiString()
Get an ASCII string representation of the bytes available in the serial data receive bufferByteBuffer
getByteBuffer()
Get all the bytes (byte-buffer) available in the serial data receive bufferbyte[]
getBytes()
Get all the bytes (byte-array) available in the serial data receive bufferCharBuffer
getCharBuffer(Charset charset)
Get a character buffer of the bytes available in the serial data receive bufferString
getHexByteString()
Get a HEX string representation of the bytes available in the serial data receive bufferString
getHexByteString(CharSequence prefix, CharSequence separator, CharSequence suffix)
Get a HEX string representation of the bytes available in the serial data receive bufferSerialDataReader
getReader()
Get an instance of the serial data readerSerial
getSerial()
Get the serial interface instanceString
getString(Charset charset)
Get a string representation of the bytes available in the serial data receive bufferint
length()
Get the number of bytes available in the serial data-
Methods inherited from class java.util.EventObject
getSource, toString
-
-
-
-
Method Detail
-
getSerial
public Serial getSerial()
Get the serial interface instance- Returns:
- serial interface
-
getReader
public SerialDataReader getReader()
Get an instance of the serial data reader- Returns:
- serial data reader interface
-
length
public int length() throws IOException
Get the number of bytes available in the serial data- Returns:
- number of bytes available
- Throws:
IOException
-
getBytes
public byte[] getBytes() throws IOException
Get all the bytes (byte-array) available in the serial data receive buffer- Returns:
- byte array containing all bytes available in serial data receive buffer
- Throws:
IOException
-
getByteBuffer
public ByteBuffer getByteBuffer() throws IOException
Get all the bytes (byte-buffer) available in the serial data receive buffer- Returns:
- ByteBuffer containing all bytes available in serial data receive buffer
- Throws:
IOException
-
getString
public String getString(Charset charset) throws IOException
Get a string representation of the bytes available in the serial data receive buffer- Parameters:
charset
- the character-set used to construct the string from the underlying byte array- Returns:
- string of data from serial data receive buffer
- Throws:
IOException
-
getAsciiString
public String getAsciiString() throws IOException
Get an ASCII string representation of the bytes available in the serial data receive buffer- Returns:
- ASCII string of data from serial data receive buffer
- Throws:
IOException
-
getHexByteString
public String getHexByteString() throws IOException
Get a HEX string representation of the bytes available in the serial data receive buffer- Returns:
- HEX string of comma separated data bytes from serial data receive buffer
- Throws:
IOException
-
getHexByteString
public String getHexByteString(CharSequence prefix, CharSequence separator, CharSequence suffix) throws IOException
Get a HEX string representation of the bytes available in the serial data receive buffer- Parameters:
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 byte- Returns:
- HEX string of data bytes from serial data receive buffer
- Throws:
IOException
-
getCharBuffer
public CharBuffer getCharBuffer(Charset charset) throws IOException
Get a character buffer of the bytes available in the serial data receive buffer- Parameters:
charset
- the character-set used to construct the character buffer from the underlying byte array- Returns:
- CharBuffer of data from serial data receive buffer
- Throws:
IOException
-
discardData
public void discardData() throws IllegalStateException, IOException
discard/drain all available bytes from the serial data receive buffer
- Throws:
IllegalStateException
IOException
-
-