public interface Serial
This interface provides a set of functions for 'Serial' communication.
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/)
#SerialFactory,
#SerialDataEvent,
#SerialDataListener,
http://www.pi4j.com/| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_COM_PORT
The default hardware COM port provided via the Raspberry Pi GPIO header.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(SerialDataListener... listener)
Java consumer code can call this method to register itself as a listener for serial data
events.
|
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)
Java consumer code can call this method to unregister itself as a listener for serial data
events.
|
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.
|
static final String DEFAULT_COM_PORT
#serialOpen(String,int),
Constant Field Valuesint open(String device, int baudRate)
device - 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.DEFAULT_COM_PORTvoid close()
boolean isOpen()
open(String, int)void flush()
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.
void write(char data)
data - A single character to be transmitted.void write(char[] data)
data - A character array of data to be transmitted.void write(byte data)
data - A single byte to be transmitted.void write(byte[] data)
data - A byte array of data to be transmitted.void write(String data)
data - A string of data to be transmitted.void writeln(String data)
data - A string of data to be transmitted.void write(String data, String... args)
data - A string of formatted data to be transmitted.args - A series of arguments that can be included for the format string variable
replacements.void writeln(String data, String... args)
data - A string of formatted data to be transmitted.args - A series of arguments that can be included for the format string variable
replacements.int availableBytes()
void addListener(SerialDataListener... listener)
Java consumer code can call this method to register itself as a listener for serial data events.
listener - A class instance that implements the SerialListener interface.#SerialListener,
#SerialDataEventvoid removeListener(SerialDataListener... listener)
Java consumer code can call this method to unregister itself as a listener for serial data events.
listener - A class instance that implements the SerialListener interface.#SerialListener,
#SerialDataEventCopyright © 2012 Pi4J. All Rights Reserved.