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
|
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
SerialPortException
public boolean setParams(int baudRate, int dataBits, int stopBits, int parity) throws SerialPortException
baudRate
- data transfer ratedataBits
- number of data bitsstopBits
- number of stop bitsparity
- paritySerialPortException
public 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)SerialPortException
public boolean purgePort(int flags) throws SerialPortException
SerialPortException
public boolean setEventsMask(int mask) throws SerialPortException
SerialPortException
public int getEventsMask() throws SerialPortException
SerialPortException
public boolean setRTS(boolean enabled) throws SerialPortException
SerialPortException
public boolean setDTR(boolean enabled) throws SerialPortException
SerialPortException
public boolean writeBytes(byte[] buffer) throws SerialPortException
SerialPortException
public boolean writeByte(byte singleByte) throws SerialPortException
SerialPortException
public boolean writeString(java.lang.String string) throws SerialPortException
SerialPortException
public boolean writeInt(int singleInt) throws SerialPortException
SerialPortException
public boolean writeIntArray(int[] buffer) throws SerialPortException
SerialPortException
public byte[] readBytes(int byteCount) throws SerialPortException
byteCount
- count of bytes for readingSerialPortException
public java.lang.String readString(int byteCount) throws SerialPortException
byteCount
- count of bytes for readingSerialPortException
public java.lang.String readHexString(int byteCount) throws SerialPortException
byteCount
- count of bytes for readingSerialPortException
public java.lang.String readHexString(int byteCount, java.lang.String separator) throws SerialPortException
byteCount
- count of bytes for readingSerialPortException
public java.lang.String[] readHexStringArray(int byteCount) throws SerialPortException
byteCount
- count of bytes for readingSerialPortException
public int[] readIntArray(int byteCount) throws SerialPortException
byteCount
- count of bytes for readingSerialPortException
public byte[] readBytes(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException
byteCount
- count of bytes for readingtimeout
- timeout in millisecondsSerialPortException
SerialPortTimeoutException
public java.lang.String readString(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException
byteCount
- count of bytes for readingtimeout
- timeout in millisecondsSerialPortException
SerialPortTimeoutException
public java.lang.String readHexString(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException
byteCount
- count of bytes for readingtimeout
- timeout in millisecondsSerialPortException
SerialPortTimeoutException
public java.lang.String readHexString(int byteCount, java.lang.String separator, int timeout) throws SerialPortException, SerialPortTimeoutException
byteCount
- count of bytes for readingtimeout
- timeout in millisecondsSerialPortException
SerialPortTimeoutException
public java.lang.String[] readHexStringArray(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException
byteCount
- count of bytes for readingtimeout
- timeout in millisecondsSerialPortException
SerialPortTimeoutException
public int[] readIntArray(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException
byteCount
- count of bytes for readingtimeout
- timeout in millisecondsSerialPortException
SerialPortTimeoutException
public byte[] readBytes() throws SerialPortException
SerialPortException
public java.lang.String readString() throws SerialPortException
SerialPortException
public java.lang.String readHexString() throws SerialPortException
SerialPortException
public java.lang.String readHexString(java.lang.String separator) throws SerialPortException
SerialPortException
public java.lang.String[] readHexStringArray() throws SerialPortException
SerialPortException
public int[] readIntArray() throws SerialPortException
SerialPortException
public int getInputBufferBytesCount() throws SerialPortException
SerialPortException
public int getOutputBufferBytesCount() throws SerialPortException
SerialPortException
public boolean setFlowControlMode(int mask) throws SerialPortException
SerialPortException
public int getFlowControlMode() throws SerialPortException
SerialPortException
public boolean sendBreak(int duration) throws SerialPortException
duration
- duration of Break signalSerialPortException
public int[] getLinesStatus() throws SerialPortException
SerialPortException
public boolean isCTS() throws SerialPortException
SerialPortException
public boolean isDSR() throws SerialPortException
SerialPortException
public boolean isRING() throws SerialPortException
SerialPortException
public boolean isRLSD() throws SerialPortException
SerialPortException
public void addEventListener(SerialPortEventListener listener) throws SerialPortException
SerialPortException
public void addEventListener(SerialPortEventListener listener, int mask) throws SerialPortException
SerialPortException
setEventsMask(int mask)
public boolean removeEventListener() throws SerialPortException
SerialPortException
public boolean closePort() throws SerialPortException
SerialPortException