public class SerNimpl extends InputStream implements SerialDefs
SerialDefs
. Otherwise this class sticks to usual
operating system habits as procured by the used class
WinDoesIt
.SerNimpl
object is (itself) a InputStream
,
allowing (in the ready state) the reading of bytes or byte arrays from the
serial interface.getOut()
(in the ready state). But, the three
write()
methods as well as close()
should be
called as directly provided by this SerNimpl
object, except where
an OutputStream
object is explicitly needed.SerialDefs.Helper
Modifier and Type | Field and Description |
---|---|
static int |
errNoRetLast
Last consumed error.
|
BI, CD, CTS, DATA_AVAILABLE, DATABITS_5, DATABITS_6, DATABITS_7, DATABITS_8, DSR, FE, FLOWCONTROL_NONE, FLOWCONTROL_RTSCTS, FLOWCONTROL_RTSCTS_IN, FLOWCONTROL_RTSCTS_OUT, FLOWCONTROL_XONXOFF, FLOWCONTROL_XONXOFF_IN, FLOWCONTROL_XONXOFF_OUT, OE, OUTPUT_BUFFER_EMPTY, PARITY_EVEN, PARITY_MARK, PARITY_NONE, PARITY_ODD, PARITY_SPACE, PE, RI, STOPBITS_1, STOPBITS_1_5, STOPBITS_2
Constructor and Description |
---|
SerNimpl() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the serial port.
|
String |
flowControlAsString()
Data flow control as String.
|
boolean |
flush()
Empty the (system's) output buffer.
|
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.
|
OutputStream |
getOut()
Fetching the
OutputStream . |
int |
getParity()
The serial port's parity.
|
long |
getPort()
The serial port's number (handle).
|
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)
Connect to a serial port of given name.
|
String |
parityAsString()
The serial port's parity as String.
|
boolean |
purgeSerial(int ops)
Get rid of pending operations.
|
int |
read()
Read a character from the serial port.
|
int |
read(byte[] b,
int off,
int len)
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.
|
boolean |
setSerialTimeouts(int readIntervalTimeout,
int readTotalTimeoutMultiplier,
int readTotalTimeoutConstant,
int writeTotalTimeoutMultiplier,
int writeTotalTimeoutConstant)
Set the serial port's timeouts.
|
String |
toString()
Text representation.
|
StringBuilder |
toString(StringBuilder bastel)
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.
|
available, mark, markSupported, read, reset, skip
public static volatile int errNoRetLast
public final String getPortName()
SerialDefs
getPortName
in interface SerialDefs
public long getPort()
WinDoesIt
) internally for all further
operations on the respective port.SerialDefs
's contract.public void openSerial(CharSequence comPort) throws IOException
SerNimpl
respectively SerialDefs
object will be
connected to the serial port named comPort
.IOException
.openSerial
in interface SerialDefs
comPort
- Portname (null or empty returns null without Exception)IOException
- file or stream problemSerialDefs.Helper.newInstance(CharSequence, CharSequence)
public int getRcvTimeout()
SerialDefs
rcvTimeout
) values
> 0 reading methods return after that time in ms (milliseconds)
independent of having received any bytes.getRcvTimeout
in interface SerialDefs
SerialDefs.setRcvTimeout(int)
public boolean setSerialTimeouts(int readIntervalTimeout, int readTotalTimeoutMultiplier, int readTotalTimeoutConstant, int writeTotalTimeoutMultiplier, int writeTotalTimeoutConstant)
readIntervalTimeout
- between the bytes (see above)readTotalTimeoutMultiplier
- * number of bytes (see above)readTotalTimeoutConstant
- + (see above)writeTotalTimeoutMultiplier
- * number of bytes (see above)writeTotalTimeoutConstant
- + (see above)public void setRcvTimeout(int rcvTimeout)
SerialDefs
setRcvTimeout
in interface SerialDefs
rcvTimeout
- the receive timeout in ms to be setSerialDefs.getRcvTimeout()
public int getBaud()
SerialDefs
getBaud
in interface SerialDefs
SerialDefs.Helper.baudRate(int)
,
SerialDefs.setSerialPortParams(int, int, int, int)
public int getDataBits()
SerialDefs
getDataBits
in interface SerialDefs
SerialDefs.setSerialPortParams(int, int, int, int)
public int getStopBits()
SerialDefs
getStopBits
in interface SerialDefs
SerialDefs.setSerialPortParams(int, int, int, int)
,
SerialDefs.STOPBITS_1
,
SerialDefs.STOPBITS_1_5
,
SerialDefs.STOPBITS_2
public int getParity()
SerialDefs
getParity
in interface SerialDefs
SerialDefs.setSerialPortParams(int, int, int, int)
,
SerialDefs.parityAsString()
,
SerialDefs.PARITY_NONE
,
SerialDefs.PARITY_EVEN
public String parityAsString()
SerialDefs
SerialDefs.Helper
.parityAsString()
.parityAsString
in interface SerialDefs
SerialDefs.setSerialPortParams(int, int, int, int)
,
SerialDefs.getParity()
public boolean setSerialPortParams(int baudrate, int dataBits, int stopBits, int parity)
SerialDefs
SerialDefs.PARITY_NONE
(default), make
sense.SerialDefs.STOPBITS_1
(default), make sense.setSerialPortParams
in interface SerialDefs
baudrate
- the baudrate to be setdataBits
- the data item width to be setstopBits
- the number of stop bits to besetparity
- the parity to be setSerialDefs.getParity()
,
SerialDefs.getBaud()
,
SerialDefs.getDataBits()
,
SerialDefs.getStopBits()
,
SerialDefs.STOPBITS_1
,
SerialDefs.STOPBITS_1_5
,
SerialDefs.STOPBITS_2
,
SerialDefs.PARITY_NONE
,
SerialDefs.PARITY_EVEN
,
SerialDefs.PARITY_ODD
,
SerialDefs.PARITY_MARK
,
SerialDefs.PARITY_SPACE
public int getFlowControlMode()
SerialDefs
getFlowControlMode
in interface SerialDefs
SerialDefs.setFlowControlMode(int)
public String flowControlAsString()
SerialDefs
flowControlMode
's value is returned as
character sequence.SerialDefs.Helper
.flowControlAsText(null, getFlowControlMode())
.flowControlAsString
in interface SerialDefs
public void setFlowControlMode(int flowControlMode)
SerialDefs
setFlowControlMode
in interface SerialDefs
flowControlMode
- the flow control mode to be setSerialDefs.getFlowControlMode()
public boolean isRTS()
SerialDefs
SerialDefs.setRTS(boolean)
respectively SerialDefs.setDtrRts(boolean, boolean)
instead of the interface's re-read value. If doing so false will be
returned prior to any first setting.isRTS
in interface SerialDefs
public void setRTS(boolean rts)
SerialDefs
setRTS
in interface SerialDefs
rts
- the state of the RTS signalpublic boolean isDTR()
SerialDefs
SerialDefs.setDTR(boolean)
respectively SerialDefs.setDtrRts(boolean, boolean)
instead of the interface's re-read value. If doing so false will be
returned prior to any first setting.isDTR
in interface SerialDefs
public void setDTR(boolean dtr)
SerialDefs
setDTR
in interface SerialDefs
dtr
- the state of the DTR signalpublic void setDtrRts(boolean dtr, boolean rts)
SerialDefs
setDTR()
and
setRTS()
.setDtrRts
in interface SerialDefs
dtr
- the state of the DTR signalrts
- the state of the RTS signalpublic boolean isDSR()
SerialDefs
isDSR
in interface SerialDefs
public boolean isCTS()
SerialDefs
isCTS
in interface SerialDefs
public boolean isCD()
SerialDefs
isCD
in interface SerialDefs
public boolean isRI()
SerialDefs
isRI
in interface SerialDefs
public boolean isReady()
SerialDefs
isReady
in interface SerialDefs
SerialDefs.close()
public void close()
SerialDefs
close
in interface SerialDefs
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
SerialDefs.isReady()
public int read()
SerialDefs
rcvTimeout
it will wait / block for
unlimited time.read
in interface SerialDefs
read
in class InputStream
public int read(byte[] b, int off, int len)
SerialDefs
read
in interface SerialDefs
read
in class InputStream
b
- the buffer to read intooff
- the index where to put the first byte readlen
- the maximum number of bytes to be read / put into bpublic int write(byte[] b, int off, int len)
SerialDefs
b
is null nothing happens at all.write
in interface SerialDefs
len
on total successpublic int write(byte[] b)
SerialDefs
b
is null nothing happens at all.write(b, 0, b.length)
.write
in interface SerialDefs
public boolean write(int b)
SerialDefs
write
in interface SerialDefs
public boolean flush()
WinDoesIt.flushSerial(long)
public boolean purgeSerial(int ops)
ops
- One or more (OR) PURGE constantsWinDoesIt.PURGE_RXABORT
,
WinDoesIt.PURGE_RXCLEAR
,
WinDoesIt.PURGE_TXABORT
,
WinDoesIt.PURGE_TXCLEAR
,
WinDoesIt.PURGE_OR
,
WinDoesIt.purgeSerialPort(long, int)
public OutputStream getOut()
OutputStream
. ready
port this method provides the
"out direction" as stream. close()
of the port or
of that OutputStream
invalidate both.OutputStream
object mainly delegates to the
"direct" SerNimpl
respectively SerialDefs
write
methods. They should be used directly as far as possible. In other
words, this method should not be called, except in cases where an
OutputStream
object is needed explicitly and unavoidably.InputStream
is needed, this SerNimpl
object
(itself) is it.OutputStream
object, as
long as the serial port stays ready
.OutputStream
or nullpublic String getExMsg()
SerialDefs
getExMsg
in interface SerialDefs
public String toString()
getExMsg()
criteria, its explanation will be part of the status text returned.toString
in interface SerialDefs
toString
in class Object
public StringBuilder toString(StringBuilder bastel)
getExMsg()
criteria, its explanation will be part of the status text returned.bastel
- the StringBuilder to append to. If null, it will be
generated with starting capacity 180.