public class SerialPort extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
SerialPort.FlowControl
Represents what type of flow control to use for serial communication
|
static class |
SerialPort.Parity
Represents the parity to use for serial communications
|
static class |
SerialPort.Port |
static class |
SerialPort.StopBits
Represents the number of stop bits to use for Serial Communication
|
static class |
SerialPort.WriteBufferMode
Represents which type of buffer mode to use when writing to a serial port
|
| Constructor and Description |
|---|
SerialPort(int baudRate,
SerialPort.Port port)
Create an instance of a Serial Port class.
|
SerialPort(int baudRate,
SerialPort.Port port,
int dataBits)
Create an instance of a Serial Port class.
|
SerialPort(int baudRate,
SerialPort.Port port,
int dataBits,
SerialPort.Parity parity)
Create an instance of a Serial Port class.
|
SerialPort(int baudRate,
SerialPort.Port port,
int dataBits,
SerialPort.Parity parity,
SerialPort.StopBits stopBits)
Create an instance of a Serial Port class.
|
| Modifier and Type | Method and Description |
|---|---|
void |
disableTermination()
Disable termination behavior.
|
void |
enableTermination()
Enable termination with the default terminator '\n'
Termination is currently only implemented for receive.
|
void |
enableTermination(char terminator)
Enable termination and specify the termination character.
|
void |
flush()
Force the output buffer to be written to the port.
|
void |
free()
Destructor.
|
int |
getBytesReceived()
Get the number of bytes currently available to read from the serial port.
|
byte[] |
read(int count)
Read raw bytes out of the buffer.
|
String |
readString()
Read a string out of the buffer.
|
String |
readString(int count)
Read a string out of the buffer.
|
void |
reset()
Reset the serial port driver to a known state.
|
void |
setFlowControl(SerialPort.FlowControl flowControl)
Set the type of flow control to enable on this port.
|
void |
setReadBufferSize(int size)
Specify the size of the input buffer.
|
void |
setTimeout(double timeout)
Configure the timeout of the serial port.
|
void |
setWriteBufferMode(SerialPort.WriteBufferMode mode)
Specify the flushing behavior of the output buffer.
|
void |
setWriteBufferSize(int size)
Specify the size of the output buffer.
|
int |
write(byte[] buffer,
int count)
Write raw bytes to the serial port.
|
int |
writeString(String data)
Write a string to the serial port
|
public SerialPort(int baudRate,
SerialPort.Port port,
int dataBits,
SerialPort.Parity parity,
SerialPort.StopBits stopBits)
baudRate - The baud rate to configure the serial port.port - The Serial port to usedataBits - The number of data bits per transfer. Valid values are between 5 and 8 bits.parity - Select the type of parity checking to use.stopBits - The number of stop bits to use as defined by the enum StopBits.public SerialPort(int baudRate,
SerialPort.Port port,
int dataBits,
SerialPort.Parity parity)
baudRate - The baud rate to configure the serial port.dataBits - The number of data bits per transfer. Valid values are between 5 and 8 bits.parity - Select the type of parity checking to use.public SerialPort(int baudRate,
SerialPort.Port port,
int dataBits)
baudRate - The baud rate to configure the serial port.dataBits - The number of data bits per transfer. Valid values are between 5 and 8 bits.public SerialPort(int baudRate,
SerialPort.Port port)
baudRate - The baud rate to configure the serial port.public void free()
public void setFlowControl(SerialPort.FlowControl flowControl)
flowControl - the FlowControl value to usepublic void enableTermination(char terminator)
terminator - The character to use for termination.public void enableTermination()
public void disableTermination()
public int getBytesReceived()
public String readString()
public String readString(int count)
count - the number of characters to read into the stringpublic byte[] read(int count)
count - The maximum number of bytes to read.public int write(byte[] buffer,
int count)
buffer - The buffer of bytes to write.count - The maximum number of bytes to write.public int writeString(String data)
data - The string to write to the serial port.public void setTimeout(double timeout)
timeout - The number of seconds to to wait for I/O.public void setReadBufferSize(int size)
size - The read buffer size.public void setWriteBufferSize(int size)
size - The write buffer size.public void setWriteBufferMode(SerialPort.WriteBufferMode mode)
mode - The write buffer mode.public void flush()
public void reset()
Copyright © 2015. All rights reserved.