public interface SerialDefs
SerialDefs
) that would (at least) have
made the rank growth of implementations interchangeable.Modifier and Type | Interface and Description |
---|---|
static class |
SerialDefs.Helper
Implementation of (helper) methods for serial ports.
|
Modifier and Type | Field and Description |
---|---|
static int |
BI
Event type: Break / Interrupt.
|
static int |
CD
Event type: Carrier detect.
|
static int |
CTS
Event type: Clear to send.
|
static int |
DATA_AVAILABLE
Event type: Data available.
|
static int |
DATABITS_5
Setting: 5 data bits.
|
static int |
DATABITS_6
Setting: 6 data bits.
|
static int |
DATABITS_7
Setting: 7 data bits.
|
static int |
DATABITS_8
Setting: 8 data bits.
|
static int |
DSR
Event type: Data set ready.
|
static int |
FE
Event type: Framing error.
|
static int |
FLOWCONTROL_NONE
Setting: data flow control: none.
|
static int |
FLOWCONTROL_RTSCTS
Setting: data flow control: hardware both directions.
|
static int |
FLOWCONTROL_RTSCTS_IN
Setting: data flow control: hardware on input.
|
static int |
FLOWCONTROL_RTSCTS_OUT
Setting: data flow control: hardware on output.
|
static int |
FLOWCONTROL_XONXOFF
Setting: data flow control: software both directions.
|
static int |
FLOWCONTROL_XONXOFF_IN
Setting: data flow control: software on input.
|
static int |
FLOWCONTROL_XONXOFF_OUT
Setting: data flow control: software on output.
|
static int |
OE
Event type: Overrun error.
|
static int |
OUTPUT_BUFFER_EMPTY
Event type: Output buffer empty.
|
static int |
PARITY_EVEN
Setting: even parity.
|
static int |
PARITY_MARK
Setting: parity mark.
|
static int |
PARITY_NONE
Setting: no parity.
|
static int |
PARITY_ODD
Setting: odd parity.
|
static int |
PARITY_SPACE
Setting: parity space.
|
static int |
PE
Event type: Parity error.
|
static int |
RI
Event type: Ring Indicator.
|
static int |
STOPBITS_1
Setting: 1 stop bit.
|
static int |
STOPBITS_1_5
Setting: 1.5 stop bits.
|
static int |
STOPBITS_2
Setting: 2 stop bits.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the serial port.
|
default String |
flowControlAsString()
Data flow control as String.
|
int |
getBaud()
The serial port's baud rate.
|
int |
getDataBits()
The serial port's data bits, size of one information piece.
|
String |
getExMsg()
The last exception's message.
|
int |
getFlowControlMode()
Data flow control.
|
int |
getParity()
The serial port's parity.
|
String |
getPortName()
The used interface's name.
|
int |
getRcvTimeout()
The serial ports's receive timeout in ms.
|
int |
getStopBits()
The serial port's stop bits.
|
boolean |
isCD()
state des modem's control input's CD (carrier detect) state.
|
boolean |
isCTS()
The modem control input's CTS (clear to send) state.
|
boolean |
isDSR()
The modem control input's DSR (data set ready) state.
|
boolean |
isDTR()
The modem control output's DTR (data terminal ready) state.
|
boolean |
isReady()
Check the serial port's usability.
|
boolean |
isRI()
The modem control input's RI (ring indicator) state.
|
boolean |
isRTS()
The modem control output's RTS (request to send) state.
|
void |
openSerial(CharSequence comPort)
Open the serial port.
|
default String |
parityAsString()
The serial port's parity as String.
|
int |
read()
Read a character from the serial port.
|
int |
read(byte[] b,
int o,
int l)
Read some bytes from the serial port.
|
void |
setDTR(boolean dtr)
Set the state of modem's control output DTR (data terminal ready).
|
void |
setDtrRts(boolean dtr,
boolean rts)
Set the modem control outputs DTR and RTS.
|
void |
setFlowControlMode(int flowControlMode)
Set the data flow control mode.
|
void |
setRcvTimeout(int rcvTimeout)
Set the serial port's receive timeout.
|
void |
setRTS(boolean rts)
Set the state of modem's control output RTS (request to send).
|
boolean |
setSerialPortParams(int baudrate,
int dataBits,
int stopBits,
int parity)
Set all relevant parameters of the serial port.
|
String |
toString()
Text representation.
|
int |
write(byte[] b)
Write some bytes to the serial port.
|
int |
write(byte[] b,
int off,
int len)
Write some bytes to the serial port.
|
boolean |
write(int b)
Write one byte to the serial port.
|
static final int DATABITS_5
5
static final int DATABITS_6
6
DATABITS_5
,
Constant Field Valuesstatic final int DATABITS_7
7
DATABITS_5
,
Constant Field Valuesstatic final int DATABITS_8
8
DATABITS_5
,
Constant Field Valuesstatic final int STOPBITS_1
1
static final int STOPBITS_2
2
static final int STOPBITS_1_5
DATABITS_5
).3
static final int PARITY_NONE
0
static final int PARITY_EVEN
2
static final int PARITY_ODD
1
static final int PARITY_MARK
3
static final int PARITY_SPACE
4
static final int FLOWCONTROL_NONE
0
static final int FLOWCONTROL_RTSCTS_IN
1
static final int FLOWCONTROL_RTSCTS_OUT
2
static final int FLOWCONTROL_RTSCTS
3
(FLOWCONTROL_RTSCTS_OUT
|
FLOWCONTROL_RTSCTS_IN
)static final int FLOWCONTROL_XONXOFF_IN
4
static final int FLOWCONTROL_XONXOFF_OUT
8
static final int FLOWCONTROL_XONXOFF
12
(FLOWCONTROL_XONXOFF_OUT
|
FLOWCONTROL_XONXOFF_IN
)static final int OE
7
static final int PE
8
static final int FE
9
static final int BI
10
static final int CD
6
static final int RI
5
static final int DSR
4
static final int CTS
3
static final int DATA_AVAILABLE
1
static final int OUTPUT_BUFFER_EMPTY
2
String getPortName()
int getRcvTimeout()
rcvTimeout
) values
> 0 reading methods return after that time in ms (milliseconds)
independent of having received any bytes.setRcvTimeout(int)
void setRcvTimeout(int rcvTimeout)
rcvTimeout
- the receive timeout in ms to be setgetRcvTimeout()
int getBaud()
SerialDefs.Helper.baudRate(int)
,
setSerialPortParams(int, int, int, int)
int getDataBits()
setSerialPortParams(int, int, int, int)
int getStopBits()
setSerialPortParams(int, int, int, int)
,
STOPBITS_1
,
STOPBITS_1_5
,
STOPBITS_2
int getParity()
setSerialPortParams(int, int, int, int)
,
parityAsString()
,
PARITY_NONE
,
PARITY_EVEN
default String parityAsString()
SerialDefs.Helper
.parityAsString()
.setSerialPortParams(int, int, int, int)
,
getParity()
boolean setSerialPortParams(int baudrate, int dataBits, int stopBits, int parity)
PARITY_NONE
(default), make
sense.STOPBITS_1
(default), make sense.baudrate
- the baudrate to be setdataBits
- the data item width to be setstopBits
- the number of stop bits to besetparity
- the parity to be setgetParity()
,
getBaud()
,
getDataBits()
,
getStopBits()
,
STOPBITS_1
,
STOPBITS_1_5
,
STOPBITS_2
,
PARITY_NONE
,
PARITY_EVEN
,
PARITY_ODD
,
PARITY_MARK
,
PARITY_SPACE
int getFlowControlMode()
setFlowControlMode(int)
default String flowControlAsString()
flowControlMode
's value is returned as
character sequence.SerialDefs.Helper
.flowControlAsText(null, getFlowControlMode())
.void setFlowControlMode(int flowControlMode)
flowControlMode
- the flow control mode to be setgetFlowControlMode()
boolean isRTS()
setRTS(boolean)
respectively setDtrRts(boolean, boolean)
instead of the interface's re-read value. If doing so false will be
returned prior to any first setting.void setRTS(boolean rts)
rts
- the state of the RTS signalboolean isDTR()
setDTR(boolean)
respectively setDtrRts(boolean, boolean)
instead of the interface's re-read value. If doing so false will be
returned prior to any first setting.void setDTR(boolean dtr)
dtr
- the state of the DTR signalvoid setDtrRts(boolean dtr, boolean rts)
setDTR()
and
setRTS()
.dtr
- the state of the DTR signalrts
- the state of the RTS signalboolean isDSR()
boolean isCTS()
boolean isCD()
boolean isRI()
boolean isReady()
close()
void close()
isReady()
void openSerial(CharSequence comPort) throws IllegalArgumentException, IOException
SerialDefs
object
already represents an open (ready
) serial port of the
same name
the call just does nothing.SerialDefs
object already represents an open
(ready
) serial port of another
name
it will be tried to close
that as first step.comPort
- PortnameIllegalArgumentException
- wrong parameter valuesIOException
- file or stream problemint read()
rcvTimeout
it will wait / block for
unlimited time.int read(byte[] b, int o, int l)
b
- the buffer to read intoo
- the index where to put the first byte readl
- the maximum number of bytes to be read / put into bint write(byte[] b, int off, int len)
b
is null nothing happens at all.len
on total successint write(byte[] b)
b
is null nothing happens at all.write(b, 0, b.length)
.boolean write(int b)
String getExMsg()
String toString()
getExMsg()
criteria, its explanation will be part of the status text returned.