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 voiddiscardData()discard/drain all available bytes from the serial data receive bufferStringgetAsciiString()Get an ASCII string representation of the bytes available in the serial data receive bufferByteBuffergetByteBuffer()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 bufferCharBuffergetCharBuffer(Charset charset)Get a character buffer of the bytes available in the serial data receive bufferStringgetHexByteString()Get a HEX string representation of the bytes available in the serial data receive bufferStringgetHexByteString(CharSequence prefix, CharSequence separator, CharSequence suffix)Get a HEX string representation of the bytes available in the serial data receive bufferSerialDataReadergetReader()Get an instance of the serial data readerSerialgetSerial()Get the serial interface instanceStringgetString(Charset charset)Get a string representation of the bytes available in the serial data receive bufferintlength()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 IOExceptionGet the number of bytes available in the serial data- Returns:
- number of bytes available
- Throws:
IOException
-
getBytes
public byte[] getBytes() throws IOExceptionGet 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, IOExceptiondiscard/drain all available bytes from the serial data receive buffer
- Throws:
IllegalStateExceptionIOException
-
-