public class WinDoesIt extends Object
SerNimpl
is
preferred by the application programmer. This wrapper is also robust
in the sense that the (native) C functions (just forwarded by this class)
by its nature lack Java's type safety. The direct caller of this class'
methods has to check the
ability to be called and the parameter values in every single case.Modifier and Type | Field and Description |
---|---|
static int |
CLRBREAK
Constant for escape method.
|
static int |
CLRDTR
Constant for escape method.
|
static int |
CLRRTS
Constant for escape method.
|
static long |
INVALID_HANDLE_VALUE
Invalid value for the system's I/O handle.
|
static int |
MS_CTS_ON
Constant for modem state.
|
static int |
MS_DSR_ON
Constant for modem state.
|
static int |
MS_RING_ON
Constant for modem state.
|
static int |
MS_RLSD_ON
Constant for modem state.
|
static int |
ONE5STOPBITS
Constant for StoppBits.
|
static int |
ONESTOPBIT
Constant for stop bits.
|
static int |
PURGE_OR
Constant for purge method.
|
static int |
PURGE_RXABORT
Constant for purge method.
|
static int |
PURGE_RXCLEAR
Constant for purge method.
|
static int |
PURGE_RXOR
Constant for purge method.
|
static int |
PURGE_TXABORT
Constant for purge method.
|
static int |
PURGE_TXCLEAR
Constant for purge method.
|
static int |
SETBREAK
Constant for escape method.
|
static int |
SETDTR
Constant for escape method.
|
static int |
SETRTS
Constant for escape method.
|
static int |
SETXOFF
Constant for escape method.
|
static int |
SETXON
Constant for escape method.
|
static int |
TWOSTOPBITS
Constant for StoppBits.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
closePort(long port)
Close the port respectively handle.
|
static String |
errorMessage(int errNo)
Get the report String from the error number.
|
static boolean |
escapeComm(long handle,
int op)
USART control.
|
static boolean |
flushSerial(long port)
Empty the (system's) output buffer.
|
static int |
getLastError()
Determine the last respectively actual error number.
|
static int |
getSerial(long port)
Read just one byte.
|
static int |
getSerialModemStatus(long port)
Read the modem state.
|
static int[] |
getSerialParams(long port)
Get the serial port's actual settings.
|
static int[] |
getSerialTimeouts(long port)
Get the actual timeouts for the serial port.
|
static long |
openSerialPort(String comPort)
Open a serial port.
|
static boolean |
purgeSerialPort(long port,
int ops)
Clear / abort all outstanding operations.
|
static int |
putSerial(long port,
byte data)
Write just one byte.
|
static int |
readSerial(long port,
byte[] data,
int off,
int len)
Read some bytes from the handle (port).
|
static boolean |
setDtrRts(long handle,
boolean dtr,
boolean rts)
Set the modem control outputs DTR and RTS.
|
static boolean |
setSerialParams(long port,
int baud,
int dataBits,
int stopBits,
int parity,
int flowControl)
Do the serial port's basic settings.
|
static boolean |
setSerialTimeouts(long port,
int readIntervalTimeout,
int readTotalTimeoutMultiplier,
int readTotalTimeoutConstant,
int writeTotalTimeoutMultiplier,
int writeTotalTimeoutConstant)
Set the serial port's timeouts.
|
static int |
writeSerial(long port,
byte[] data,
int off,
int len)
Write some bytes.
|
public static final long INVALID_HANDLE_VALUE
-1L
public static final int ONESTOPBIT
SerialDefs
.0
public static final int TWOSTOPBITS
2
ONE5STOPBITS
,
ONESTOPBIT
,
Constant Field Valuespublic static final int ONE5STOPBITS
SerialDefs
.1
ONESTOPBIT
,
Constant Field Valuespublic static final int PURGE_RXABORT
2
public static final int PURGE_RXCLEAR
8
public static final int PURGE_TXABORT
1
public static final int PURGE_RXOR
10
public static final int PURGE_TXCLEAR
4
public static final int PURGE_OR
15
public static final int MS_CTS_ON
16
getSerialModemStatus(long)
,
MS_DSR_ON
,
Constant Field Valuespublic static final int MS_DSR_ON
32
public static final int MS_RING_ON
64
public static final int MS_RLSD_ON
128
getSerialModemStatus(long)
,
MS_CTS_ON
,
Constant Field Valuespublic static final int CLRBREAK
9
escapeComm(long, int)
,
CLRDTR
,
Constant Field Valuespublic static final int CLRDTR
6
escapeComm(long, int)
,
CLRBREAK
,
Constant Field Valuespublic static final int CLRRTS
4
escapeComm(long, int)
,
CLRBREAK
,
Constant Field Valuespublic static final int SETBREAK
8
escapeComm(long, int)
,
CLRBREAK
,
Constant Field Valuespublic static final int SETDTR
5
escapeComm(long, int)
,
CLRBREAK
,
Constant Field Valuespublic static final int SETRTS
3
escapeComm(long, int)
,
CLRBREAK
,
Constant Field Valuespublic static final int SETXOFF
1
escapeComm(long, int)
,
CLRBREAK
,
Constant Field Valuespublic static final int SETXON
2
escapeComm(long, int)
,
CLRBREAK
,
Constant Field Valuespublic static long openSerialPort(String comPort)
INVALID_HANDLE_VALUE
.getLastError()
(and by
errorMessage(int)
):comPort
- the port's nameINVALID_HANDLE_VALUE
on failurepublic static boolean closePort(long port)
port
will be closed for all further operations.port
- a handlegetLastError()
public static int getLastError()
INVALID_HANDLE_VALUE
, false, null or similar) this method fetches
the operating systems error number.errorMessage(int)
to human readable text usually as an
Exception.errorMessage(int)
public static String errorMessage(int errNo)
AppLangMap
etc.) set for the Java
application
. Hence, the number to text translation may be
cached and done self for the language expected.errNo
- error number; see getLastError()
public static boolean setSerialParams(long port, int baud, int dataBits, int stopBits, int parity, int flowControl)
port
- handlebaud
- baud ratedataBits
- 5..8stopBits
- fitting constant valueparity
- see SerialDefs
flowControl
- (see SerialDefs
)ONESTOPBIT
,
ONE5STOPBITS
,
TWOSTOPBITS
,
getSerialParams(long)
,
setSerialTimeouts(long, int, int, int, int, int)
,
getSerialTimeouts(long)
public static int[] getSerialParams(long port)
port
- handlesetSerialParams(long, int, int, int, int, int)
);
null on failuresetSerialParams(long, int, int, int, int, int)
public static boolean setSerialTimeouts(long port, 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 static int[] getSerialTimeouts(long port)
port
- handlesetSerialTimeouts(long, int, int, int, int, int)
) parameters;public static boolean purgeSerialPort(long port, int ops)
port
- handleops
- Ein oder mehrere (Oder) PURGE-KonstantenPURGE_RXABORT
,
PURGE_RXCLEAR
,
PURGE_TXABORT
,
PURGE_TXCLEAR
,
PURGE_OR
public static int getSerialModemStatus(long port)
port
- the Windows handle for the portMS_CTS_ON
,
MS_DSR_ON
,
MS_RING_ON
,
MS_RLSD_ON
public static int writeSerial(long port, byte[] data, int off, int len)
setSerialTimeouts()
two relevant parameters.port
- handledata
- bufferoff
- index of first byte to be output (0 or larger)len
- number of bytes (has to be <= data's length!)public static int putSerial(long port, byte data)
writeSerial(long, byte[], int, int)
if and only if just one byte
is to be output.port
- handledata
- the bytepublic static boolean flushSerial(long port)
port
will be flushed.public static int readSerial(long port, byte[] data, int off, int len)
setSerialTimeouts()
three relevant parameters.port
- handledata
- the input buffer providedoff
- index of where the first byte read is to be put (0 or larger)len
- number of bytes (has to be <= data's length!)writeSerial(long, byte[], int, int)
public static int getSerial(long port)
readSerial(long, byte[], int, int)
if and only if just one byte
is to be read.port
- handlepublic static boolean setDtrRts(long handle, boolean dtr, boolean rts)
escapeComm(long, int)
.escapeComm(long, int)
,
SETDTR
,
CLRRTS