public abstract class SerialPort extends CommPort
| Modifier and Type | Field and Description |
|---|---|
static int |
DATABITS_5
5 data bit format.
|
static int |
DATABITS_6
6 data bit format.
|
static int |
DATABITS_7
7 data bit format.
|
static int |
DATABITS_8
8 data bit format.
|
static int |
FLOWCONTROL_NONE
Flow control off.
|
static int |
FLOWCONTROL_RTSCTS_IN
RTS/CTS flow control on input.
|
static int |
FLOWCONTROL_RTSCTS_OUT
RTS/CTS flow control on output.
|
static int |
FLOWCONTROL_XONXOFF_IN
XON/XOFF flow control on input.
|
static int |
FLOWCONTROL_XONXOFF_OUT
XON/XOFF flow control on output.
|
static int |
PARITY_EVEN
Even parity scheme.
|
static int |
PARITY_MARK
Mark parity scheme.
|
static int |
PARITY_NONE
No parity bit.
|
static int |
PARITY_ODD
Odd parity scheme.
|
static int |
PARITY_SPACE
Space parity scheme.
|
static int |
STOPBITS_1
One stop bit.
|
static int |
STOPBITS_1_5
One and 1/2 stop bits.
|
static int |
STOPBITS_2
Two stop bits.
|
| Constructor and Description |
|---|
SerialPort()
Instantiates a new Serial port.
|
| Modifier and Type | Method and Description |
|---|---|
abstract void |
addEventListener(SerialPortEventListener listener)
Registers a
SerialPortEventListener object to listen for
SerialEvents. |
abstract int |
getBaudRate()
Returns the currently configured baud rate.
|
abstract int |
getDataBits()
Returns the currently configured number of data bits.
|
abstract int |
getFlowControlMode()
Returns the currently configured flow control mode.
|
abstract InputStream |
getInputStream()
Returns an input stream.
|
abstract int |
getParity()
Returns the currently configured parity setting.
|
abstract int |
getStopBits()
Returns the currently defined stop bits.
|
abstract boolean |
isCD()
Returns the state of the CD (Carrier Detect) bit in the UART, if
supported by the underlying implementation.
|
abstract boolean |
isCTS()
Returns the state of the CTS (Clear To Send) bit in the UART, if
supported by the underlying implementation.
|
abstract boolean |
isDSR()
Returns the state of the DSR (Data Set Ready) bit in the UART, if
supported by the underlying implementation.
|
abstract boolean |
isDTR()
Returns the state of the DTR (Data Terminal Ready) bit in the UART, if
supported by the underlying implementation.
|
abstract boolean |
isRI()
Returns the state of the RI (Ring Indicator) bit in the UART, if
supported by the underlying implementation.
|
abstract boolean |
isRTS()
Returns the state of the RTS (Request To Send) bit in the UART, if
supported by the underlying implementation.
|
abstract void |
notifyOnBreakInterrupt(boolean enable)
Expresses interest in receiving notification when there is a break
interrupt on the line.
|
abstract void |
notifyOnCarrierDetect(boolean enable)
Expresses interest in receiving notification when the CD (Carrier Detect)
bit changes.
|
abstract void |
notifyOnCTS(boolean enable)
Expresses interest in receiving notification when the CTS (Clear To Send)
bit changes.
|
abstract void |
notifyOnDataAvailable(boolean enable)
Expresses interest in receiving notification when input data is
available.
|
abstract void |
notifyOnDSR(boolean enable)
Expresses interest in receiving notification when the DSR (Data Set
Ready) bit changes.
|
abstract void |
notifyOnFramingError(boolean enable)
Expresses interest in receiving notification when there is a framing
error.
|
abstract void |
notifyOnOutputEmpty(boolean enable)
Expresses interest in receiving notification when the output buffer is
empty.
|
abstract void |
notifyOnOverrunError(boolean enable)
Expresses interest in receiving notification when there is an overrun
error.
|
abstract void |
notifyOnParityError(boolean enable)
Expresses interest in receiving notification when there is a parity
error.
|
abstract void |
notifyOnRingIndicator(boolean enable)
Expresses interest in receiving notification when the RI (Ring Indicator)
bit changes.
|
abstract void |
removeEventListener()
Deregisters event listener registered using
addEventListener
. |
abstract void |
sendBreak(int duration)
Sends a break of
duration milliseconds duration. |
abstract void |
setDTR(boolean state)
Sets or clears the DTR (Data Terminal Ready) signal, if supported by the
underlying implementation.
|
abstract void |
setFlowControlMode(int flowcontrol)
Sets the flow control mode.
|
abstract void |
setRTS(boolean state)
Sets or clears the RTS (Request To Send) bit in the UART, if supported by
the underlying implementation.
|
abstract void |
setSerialPortParams(int baudRate,
int dataBits,
int stopBits,
int parity)
Sets the serial port parameters.
|
close, disableReceiveFraming, disableReceiveThreshold, disableReceiveTimeout, enableReceiveFraming, enableReceiveThreshold, enableReceiveTimeout, getInputBufferSize, getName, getOutputBufferSize, getOutputStream, getReceiveFramingByte, getReceiveThreshold, getReceiveTimeout, isReceiveFramingEnabled, isReceiveThresholdEnabled, isReceiveTimeoutEnabled, setInputBufferSize, setOutputBufferSizepublic static final int DATABITS_5
public static final int DATABITS_6
public static final int DATABITS_7
public static final int DATABITS_8
public static final int PARITY_NONE
public static final int PARITY_ODD
public static final int PARITY_EVEN
public static final int PARITY_MARK
public static final int PARITY_SPACE
public static final int STOPBITS_1
public static final int STOPBITS_2
public static final int STOPBITS_1_5
public static final int FLOWCONTROL_NONE
public static final int FLOWCONTROL_RTSCTS_IN
public static final int FLOWCONTROL_RTSCTS_OUT
public static final int FLOWCONTROL_XONXOFF_IN
public static final int FLOWCONTROL_XONXOFF_OUT
public abstract void addEventListener(SerialPortEventListener listener) throws TooManyListenersException
SerialPortEventListener object to listen for
SerialEvents.listener - the listenerTooManyListenersException - the too many listeners exceptionpublic abstract int getBaudRate()
public abstract int getDataBits()
public abstract int getFlowControlMode()
public abstract int getParity()
public abstract int getStopBits()
public abstract boolean isCD()
public abstract boolean isCTS()
public abstract boolean isDSR()
public abstract boolean isDTR()
public abstract boolean isRI()
public abstract boolean isRTS()
public abstract void notifyOnBreakInterrupt(boolean enable)
enable - the enablepublic abstract void notifyOnCarrierDetect(boolean enable)
enable - the enablepublic abstract void notifyOnCTS(boolean enable)
enable - the enablepublic abstract void notifyOnDataAvailable(boolean enable)
enable - the enablepublic abstract void notifyOnDSR(boolean enable)
This notification is hardware dependent and may not be supported by all implementations.
enable - the enablepublic abstract void notifyOnFramingError(boolean enable)
enable - the enablepublic abstract void notifyOnOutputEmpty(boolean enable)
enable - the enablepublic abstract void notifyOnOverrunError(boolean enable)
enable - the enablepublic abstract void notifyOnParityError(boolean enable)
enable - the enablepublic abstract void notifyOnRingIndicator(boolean enable)
enable - the enablepublic abstract void removeEventListener()
addEventListener
.
This is done automatically when the port is closed.
public abstract void sendBreak(int duration)
duration milliseconds duration.duration - The break duration in milliseconds.public abstract void setDTR(boolean state)
state - the statepublic abstract void setFlowControlMode(int flowcontrol)
throws UnsupportedCommOperationException
flowcontrol - the flowcontrolUnsupportedCommOperationException - the unsupported comm operation exceptionpublic abstract void setRTS(boolean state)
state - the statepublic abstract void setSerialPortParams(int baudRate,
int dataBits,
int stopBits,
int parity)
throws UnsupportedCommOperationException
baudRate - the baud ratedataBits - the data bitsstopBits - the stop bitsparity - the parityUnsupportedCommOperationException - the unsupported comm operation exceptionpublic abstract InputStream getInputStream() throws IOException
| threshold | timeout | read buffer size | read behaviour | ||
|---|---|---|---|---|---|
| state | value | state | value | ||
| disabled | - | disabled | - | n bytes | block until minimum one byte of data is available |
| enabled | m bytes | disabled | - | n bytes | block until min(m,n) bytes are available |
| disabled | - | enabled | x msec | n bytes | block for x msec or until any data is available |
| enabled | m bytes | enabled | x msec | n bytes | block for x msec or until min(m,n) bytes are available |
Framing errors may cause the Timeout and Threshold trigger early and to complete the read prematurely without raising an exception.
Enabling the Timeout OR Threshold with a value a zero is a special case. This causes the underlying driver to poll for incoming data instead being event driven. Otherwise, the behaviour is identical to having both the Timeout and Threshold disabled. Returns: InputStream object that can be used to read from the port Throws: java.io.IOException - if an I/O error occurred.
Timeout is interpreted as inter character timeout, in other words the timeout will not occur as long as the pause before the first character or between characters is shorter that the timeout value.
getInputStream in class CommPortnull if the port is unidirectional and doesn't support receiving data.IOException - the io exceptionCopyright © 2017. All rights reserved.