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, skippublic static volatile int errNoRetLast
public final String getPortName()
SerialDefsgetPortName in interface SerialDefspublic 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 SerialDefscomPort - Portname (null or empty returns null without Exception)IOException - file or stream problemSerialDefs.Helper.newInstance(CharSequence, CharSequence)public int getRcvTimeout()
SerialDefsrcvTimeout) values
> 0 reading methods return after that time in ms (milliseconds)
independent of having received any bytes.getRcvTimeout in interface SerialDefsSerialDefs.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)
SerialDefssetRcvTimeout in interface SerialDefsrcvTimeout - the receive timeout in ms to be setSerialDefs.getRcvTimeout()public int getBaud()
SerialDefsgetBaud in interface SerialDefsSerialDefs.Helper.baudRate(int),
SerialDefs.setSerialPortParams(int, int, int, int)public int getDataBits()
SerialDefsgetDataBits in interface SerialDefsSerialDefs.setSerialPortParams(int, int, int, int)public int getStopBits()
SerialDefsgetStopBits in interface SerialDefsSerialDefs.setSerialPortParams(int, int, int, int),
SerialDefs.STOPBITS_1,
SerialDefs.STOPBITS_1_5,
SerialDefs.STOPBITS_2public int getParity()
SerialDefsgetParity in interface SerialDefsSerialDefs.setSerialPortParams(int, int, int, int),
SerialDefs.parityAsString(),
SerialDefs.PARITY_NONE,
SerialDefs.PARITY_EVENpublic String parityAsString()
SerialDefsSerialDefs.Helper.parityAsString().parityAsString in interface SerialDefsSerialDefs.setSerialPortParams(int, int, int, int),
SerialDefs.getParity()public boolean setSerialPortParams(int baudrate,
int dataBits,
int stopBits,
int parity)
SerialDefsSerialDefs.PARITY_NONE (default), make
sense.SerialDefs.STOPBITS_1 (default), make sense.setSerialPortParams in interface SerialDefsbaudrate - 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_SPACEpublic int getFlowControlMode()
SerialDefsgetFlowControlMode in interface SerialDefsSerialDefs.setFlowControlMode(int)public String flowControlAsString()
SerialDefsflowControlMode's value is returned as
character sequence.SerialDefs.Helper.flowControlAsText(null, getFlowControlMode()).flowControlAsString in interface SerialDefspublic void setFlowControlMode(int flowControlMode)
SerialDefssetFlowControlMode in interface SerialDefsflowControlMode - the flow control mode to be setSerialDefs.getFlowControlMode()public boolean isRTS()
SerialDefsSerialDefs.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 SerialDefspublic void setRTS(boolean rts)
SerialDefssetRTS in interface SerialDefsrts - the state of the RTS signalpublic boolean isDTR()
SerialDefsSerialDefs.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 SerialDefspublic void setDTR(boolean dtr)
SerialDefssetDTR in interface SerialDefsdtr - the state of the DTR signalpublic void setDtrRts(boolean dtr,
boolean rts)
SerialDefssetDTR() and
setRTS().setDtrRts in interface SerialDefsdtr - the state of the DTR signalrts - the state of the RTS signalpublic boolean isDSR()
SerialDefsisDSR in interface SerialDefspublic boolean isCTS()
SerialDefsisCTS in interface SerialDefspublic boolean isCD()
SerialDefsisCD in interface SerialDefspublic boolean isRI()
SerialDefsisRI in interface SerialDefspublic boolean isReady()
SerialDefsisReady in interface SerialDefsSerialDefs.close()public void close()
SerialDefsclose in interface SerialDefsclose in interface Closeableclose in interface AutoCloseableclose in class InputStreamSerialDefs.isReady()public int read()
SerialDefsrcvTimeout it will wait / block for
unlimited time.read in interface SerialDefsread in class InputStreampublic int read(byte[] b,
int off,
int len)
SerialDefsread in interface SerialDefsread in class InputStreamb - 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)
SerialDefsb is null nothing happens at all.write in interface SerialDefslen on total successpublic int write(byte[] b)
SerialDefsb is null nothing happens at all.write(b, 0, b.length).write in interface SerialDefspublic boolean write(int b)
SerialDefswrite in interface SerialDefspublic 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()
SerialDefsgetExMsg in interface SerialDefspublic String toString()
getExMsg()
criteria, its explanation will be part of the status text returned.toString in interface SerialDefstoString in class Objectpublic 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.