public class SerialImpl extends Object implements Serial
This implementation class implements the 'Serial' interface using the WiringPi Serial library.
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 @ https://projects.drogon.net/)
#com.pi4j.io.serial.Serial,
#com.pi4j.io.serial.SerialDataEvent,
#com.pi4j.io.serial.SerialDataListener,
#com.pi4j.io.serial.SerialFactory,
http://www.pi4j.com/DEFAULT_COM_PORT| Constructor and Description |
|---|
SerialImpl() |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(SerialDataListener... listener)
Add Serial Event Listener
|
int |
availableBytes()
This method is called to determine if and how many bytes are available on the serial received
data buffer.
|
void |
close()
This method is called to close a currently open open serial port.
|
void |
flush()
This method is called to immediately flush the serial data transmit buffer and force any
pending data to be sent to the serial port immediately.
|
boolean |
isOpen()
This method is called to determine if the serial port is already open.
|
int |
open(String device,
int baudRate)
This method is call to open a serial port for communication.
|
char |
read()
This method will read the next character available from the serial port receive buffer.
|
void |
removeListener(SerialDataListener... listener)
Remove Serial Event Listener
|
void |
write(byte data)
This method is called to submit a single byte of data to the serial port transmit buffer.
|
void |
write(byte[] data)
This method is called to submit a byte array of data to the serial port transmit buffer.
|
void |
write(char data)
This method is called to submit a single character of data to the serial port transmit
buffer.
|
void |
write(char[] data)
This method is called to submit a character array of data to the serial port transmit buffer.
|
void |
write(String data)
This method is called to submit a string of data to the serial port transmit buffer.
|
void |
write(String data,
String... args)
This method is called to submit a string of formatted data to the serial port transmit
buffer.
|
void |
writeln(String data)
This method is called to submit a string of data with trailing CR + LF characters to the
serial port transmit buffer.
|
void |
writeln(String data,
String... args)
This method is called to submit a string of formatted data with trailing CR + LF characters
to the serial port transmit buffer.
|
public int open(String device, int baudRate)
open in interface Serialdevice - The device address of the serial port to access. You can use constant
'DEFAULT_COM_PORT' if you wish to access the default serial port provided via the
GPIO header.baudRate - The baud rate to use with the serial port.Serial.DEFAULT_COM_PORTpublic boolean isOpen()
isOpen in interface Serialopen(String, int)public void close()
public void flush()
public char read()
This method will read the next character available from the serial port receive buffer.
NOTE: If a serial data listener has been implemented and registered with this class, then this method should not be called directly. A background thread will be running to collect received data from the serial port receive buffer and the received data will be available on via the event.
public void write(char data)
public void write(char[] data)
public void write(byte data)
public void write(byte[] data)
public void write(String data)
public void writeln(String data)
public void write(String data, String... args)
public void writeln(String data, String... args)
public int availableBytes()
availableBytes in interface Serialpublic void addListener(SerialDataListener... listener)
Add Serial Event Listener
Java consumer code can call this method to register itself as a listener for serial data events.
addListener in interface Seriallistener - A class instance that implements the SerialListener interface.#com.pi4j.io.serial.SerialDataListener,
#com.pi4j.io.serial.SerialDataEventpublic void removeListener(SerialDataListener... listener)
Remove Serial Event Listener
Java consumer code can call this method to unregister itself as a listener for serial data events.
removeListener in interface Seriallistener - A class instance that implements the SerialListener interface.#com.pi4j.io.serial.SerialDataListener,
#com.pi4j.io.serial.SerialDataEventCopyright © 2012 Pi4J. All Rights Reserved.