public class SerialPort
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
BAUDRATE_110 |
static int |
BAUDRATE_115200 |
static int |
BAUDRATE_1200 |
static int |
BAUDRATE_128000 |
static int |
BAUDRATE_14400 |
static int |
BAUDRATE_19200 |
static int |
BAUDRATE_256000 |
static int |
BAUDRATE_300 |
static int |
BAUDRATE_38400 |
static int |
BAUDRATE_4800 |
static int |
BAUDRATE_57600 |
static int |
BAUDRATE_600 |
static int |
BAUDRATE_9600 |
static int |
DATABITS_5 |
static int |
DATABITS_6 |
static int |
DATABITS_7 |
static int |
DATABITS_8 |
static int |
ERROR_FRAME |
static int |
ERROR_OVERRUN |
static int |
ERROR_PARITY |
static int |
FLOWCONTROL_NONE |
static int |
FLOWCONTROL_RTSCTS_IN |
static int |
FLOWCONTROL_RTSCTS_OUT |
static int |
FLOWCONTROL_XONXOFF_IN |
static int |
FLOWCONTROL_XONXOFF_OUT |
static int |
MASK_BREAK |
static int |
MASK_CTS |
static int |
MASK_DSR |
static int |
MASK_ERR |
static int |
MASK_RING |
static int |
MASK_RLSD |
static int |
MASK_RXCHAR |
static int |
MASK_RXFLAG |
static int |
MASK_TXEMPTY |
static int |
PARITY_EVEN |
static int |
PARITY_MARK |
static int |
PARITY_NONE |
static int |
PARITY_ODD |
static int |
PARITY_SPACE |
static int |
PURGE_RXABORT |
static int |
PURGE_RXCLEAR |
static int |
PURGE_TXABORT |
static int |
PURGE_TXCLEAR |
static int |
STOPBITS_1 |
static int |
STOPBITS_1_5 |
static int |
STOPBITS_2 |
| Constructor and Description |
|---|
SerialPort(java.lang.String portName) |
| Modifier and Type | Method and Description |
|---|---|
void |
addEventListener(SerialPortEventListener listener)
Add event listener.
|
void |
addEventListener(SerialPortEventListener listener,
int mask)
Add event listener.
|
boolean |
closePort()
Close port.
|
int |
getEventsMask()
Getting events mask for the port
|
int |
getFlowControlMode()
Get flow control mode
|
int |
getInputBufferBytesCount()
Get count of bytes in input buffer
|
int[] |
getLinesStatus()
Getting lines status.
|
int |
getOutputBufferBytesCount()
Get count of bytes in output buffer
|
java.lang.String |
getPortName()
Getting port name under operation
|
boolean |
isCTS()
Get state of CTS line
|
boolean |
isDSR()
Get state of DSR line
|
boolean |
isOpened()
Getting port state
|
boolean |
isRING()
Get state of RING line
|
boolean |
isRLSD()
Get state of RLSD line
|
boolean |
openPort()
Port opening
Note: If port busy TYPE_PORT_BUSY exception will be thrown. |
boolean |
purgePort(int flags)
Purge of input and output buffer.
|
byte[] |
readBytes()
Read all available bytes from port like a byte array
|
byte[] |
readBytes(int byteCount)
Read byte array from port
|
byte[] |
readBytes(int byteCount,
int timeout)
Read byte array from port
|
java.lang.String |
readHexString()
Read all available bytes from port like a Hex String
|
java.lang.String |
readHexString(int byteCount)
Read Hex string from port (example: FF 0A FF).
|
java.lang.String |
readHexString(int byteCount,
int timeout)
Read Hex string from port (example: FF 0A FF).
|
java.lang.String |
readHexString(int byteCount,
java.lang.String separator)
Read Hex string from port with setted separator (example if separator is "::": FF::0A::FF)
|
java.lang.String |
readHexString(int byteCount,
java.lang.String separator,
int timeout)
Read Hex string from port with setted separator (example if separator is "::": FF::0A::FF)
|
java.lang.String |
readHexString(java.lang.String separator)
Read all available bytes from port like a Hex String with setted separator
|
java.lang.String[] |
readHexStringArray()
Read all available bytes from port like a Hex String array
|
java.lang.String[] |
readHexStringArray(int byteCount)
Read Hex String array from port
|
java.lang.String[] |
readHexStringArray(int byteCount,
int timeout)
Read Hex String array from port
|
int[] |
readIntArray()
Read all available bytes from port like a int array (values in range from 0 to 255)
|
int[] |
readIntArray(int byteCount)
Read int array from port
|
int[] |
readIntArray(int byteCount,
int timeout)
Read int array from port
|
java.lang.String |
readString()
Read all available bytes from port like a String
|
java.lang.String |
readString(int byteCount)
Read string from port
|
java.lang.String |
readString(int byteCount,
int timeout)
Read string from port
|
boolean |
removeEventListener()
Delete event listener.
|
boolean |
sendBreak(int duration)
Send Break singnal for setted duration
|
boolean |
setDTR(boolean enabled)
Change DTR line state.
|
boolean |
setEventsMask(int mask)
Set events mask.
|
boolean |
setFlowControlMode(int mask)
Set flow control mode.
|
boolean |
setParams(int baudRate,
int dataBits,
int stopBits,
int parity)
Setting the parameters of port.
|
boolean |
setParams(int baudRate,
int dataBits,
int stopBits,
int parity,
boolean setRTS,
boolean setDTR)
Setting the parameters of port
|
boolean |
setRTS(boolean enabled)
Change RTS line state.
|
boolean |
writeByte(byte singleByte)
Write single byte to port
|
boolean |
writeBytes(byte[] buffer)
Write byte array to port
|
boolean |
writeInt(int singleInt)
Write int value (in range from 0 to 255 (0x00 - 0xFF)) to port
|
boolean |
writeIntArray(int[] buffer)
Write int array (in range from 0 to 255 (0x00 - 0xFF)) to port
|
boolean |
writeString(java.lang.String string)
Write String to port
|
boolean |
writeString(java.lang.String string,
java.lang.String charsetName)
Write String to port
|
public static final int BAUDRATE_110
public static final int BAUDRATE_300
public static final int BAUDRATE_600
public static final int BAUDRATE_1200
public static final int BAUDRATE_4800
public static final int BAUDRATE_9600
public static final int BAUDRATE_14400
public static final int BAUDRATE_19200
public static final int BAUDRATE_38400
public static final int BAUDRATE_57600
public static final int BAUDRATE_115200
public static final int BAUDRATE_128000
public static final int BAUDRATE_256000
public 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 STOPBITS_1
public static final int STOPBITS_2
public static final int STOPBITS_1_5
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 PURGE_RXABORT
public static final int PURGE_RXCLEAR
public static final int PURGE_TXABORT
public static final int PURGE_TXCLEAR
public static final int MASK_RXCHAR
public static final int MASK_RXFLAG
public static final int MASK_TXEMPTY
public static final int MASK_CTS
public static final int MASK_DSR
public static final int MASK_RLSD
public static final int MASK_BREAK
public static final int MASK_ERR
public static final int MASK_RING
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 static final int ERROR_FRAME
public static final int ERROR_OVERRUN
public static final int ERROR_PARITY
public java.lang.String getPortName()
public boolean isOpened()
public boolean openPort()
throws SerialPortException
SerialPortExceptionpublic boolean setParams(int baudRate,
int dataBits,
int stopBits,
int parity)
throws SerialPortException
baudRate - data transfer ratedataBits - number of data bitsstopBits - number of stop bitsparity - paritySerialPortExceptionpublic boolean setParams(int baudRate,
int dataBits,
int stopBits,
int parity,
boolean setRTS,
boolean setDTR)
throws SerialPortException
baudRate - data transfer ratedataBits - number of data bitsstopBits - number of stop bitsparity - paritysetRTS - initial state of RTS line(ON/OFF)setDTR - initial state of DTR line(ON/OFF)SerialPortExceptionpublic boolean purgePort(int flags)
throws SerialPortException
SerialPortExceptionpublic boolean setEventsMask(int mask)
throws SerialPortException
SerialPortExceptionpublic int getEventsMask()
throws SerialPortException
SerialPortExceptionpublic boolean setRTS(boolean enabled)
throws SerialPortException
SerialPortExceptionpublic boolean setDTR(boolean enabled)
throws SerialPortException
SerialPortExceptionpublic boolean writeBytes(byte[] buffer)
throws SerialPortException
SerialPortExceptionpublic boolean writeByte(byte singleByte)
throws SerialPortException
SerialPortExceptionpublic boolean writeString(java.lang.String string)
throws SerialPortException
SerialPortExceptionpublic boolean writeString(java.lang.String string,
java.lang.String charsetName)
throws SerialPortException,
java.io.UnsupportedEncodingException
SerialPortExceptionjava.io.UnsupportedEncodingExceptionpublic boolean writeInt(int singleInt)
throws SerialPortException
SerialPortExceptionpublic boolean writeIntArray(int[] buffer)
throws SerialPortException
SerialPortExceptionpublic byte[] readBytes(int byteCount)
throws SerialPortException
byteCount - count of bytes for readingSerialPortExceptionpublic java.lang.String readString(int byteCount)
throws SerialPortException
byteCount - count of bytes for readingSerialPortExceptionpublic java.lang.String readHexString(int byteCount)
throws SerialPortException
byteCount - count of bytes for readingSerialPortExceptionpublic java.lang.String readHexString(int byteCount,
java.lang.String separator)
throws SerialPortException
byteCount - count of bytes for readingSerialPortExceptionpublic java.lang.String[] readHexStringArray(int byteCount)
throws SerialPortException
byteCount - count of bytes for readingSerialPortExceptionpublic int[] readIntArray(int byteCount)
throws SerialPortException
byteCount - count of bytes for readingSerialPortExceptionpublic byte[] readBytes(int byteCount,
int timeout)
throws SerialPortException,
SerialPortTimeoutException
byteCount - count of bytes for readingtimeout - timeout in millisecondsSerialPortExceptionSerialPortTimeoutExceptionpublic java.lang.String readString(int byteCount,
int timeout)
throws SerialPortException,
SerialPortTimeoutException
byteCount - count of bytes for readingtimeout - timeout in millisecondsSerialPortExceptionSerialPortTimeoutExceptionpublic java.lang.String readHexString(int byteCount,
int timeout)
throws SerialPortException,
SerialPortTimeoutException
byteCount - count of bytes for readingtimeout - timeout in millisecondsSerialPortExceptionSerialPortTimeoutExceptionpublic java.lang.String readHexString(int byteCount,
java.lang.String separator,
int timeout)
throws SerialPortException,
SerialPortTimeoutException
byteCount - count of bytes for readingtimeout - timeout in millisecondsSerialPortExceptionSerialPortTimeoutExceptionpublic java.lang.String[] readHexStringArray(int byteCount,
int timeout)
throws SerialPortException,
SerialPortTimeoutException
byteCount - count of bytes for readingtimeout - timeout in millisecondsSerialPortExceptionSerialPortTimeoutExceptionpublic int[] readIntArray(int byteCount,
int timeout)
throws SerialPortException,
SerialPortTimeoutException
byteCount - count of bytes for readingtimeout - timeout in millisecondsSerialPortExceptionSerialPortTimeoutExceptionpublic byte[] readBytes()
throws SerialPortException
SerialPortExceptionpublic java.lang.String readString()
throws SerialPortException
SerialPortExceptionpublic java.lang.String readHexString()
throws SerialPortException
SerialPortExceptionpublic java.lang.String readHexString(java.lang.String separator)
throws SerialPortException
SerialPortExceptionpublic java.lang.String[] readHexStringArray()
throws SerialPortException
SerialPortExceptionpublic int[] readIntArray()
throws SerialPortException
SerialPortExceptionpublic int getInputBufferBytesCount()
throws SerialPortException
SerialPortExceptionpublic int getOutputBufferBytesCount()
throws SerialPortException
SerialPortExceptionpublic boolean setFlowControlMode(int mask)
throws SerialPortException
SerialPortExceptionpublic int getFlowControlMode()
throws SerialPortException
SerialPortExceptionpublic boolean sendBreak(int duration)
throws SerialPortException
duration - duration of Break signalSerialPortExceptionpublic int[] getLinesStatus()
throws SerialPortException
SerialPortExceptionpublic boolean isCTS()
throws SerialPortException
SerialPortExceptionpublic boolean isDSR()
throws SerialPortException
SerialPortExceptionpublic boolean isRING()
throws SerialPortException
SerialPortExceptionpublic boolean isRLSD()
throws SerialPortException
SerialPortExceptionpublic void addEventListener(SerialPortEventListener listener) throws SerialPortException
SerialPortExceptionpublic void addEventListener(SerialPortEventListener listener, int mask) throws SerialPortException
SerialPortExceptionsetEventsMask(int mask)public boolean removeEventListener()
throws SerialPortException
SerialPortExceptionpublic boolean closePort()
throws SerialPortException
SerialPortException