Package jssc
Class SerialPort
- java.lang.Object
-
- jssc.SerialPort
-
public class SerialPort extends Object
- Author:
- scream3r
-
-
Field Summary
Fields Modifier and Type Field Description static intBAUDRATE_110Baud rate 110 symbols/secondstatic intBAUDRATE_115200Baud rate 115200 symbols/secondstatic intBAUDRATE_1200Baud rate 1200 symbols/secondstatic intBAUDRATE_128000Baud rate 128000 symbols/secondstatic intBAUDRATE_14400Baud rate 14400 symbols/secondstatic intBAUDRATE_19200Baud rate 19200 symbols/secondstatic intBAUDRATE_2400Baud rate 2400 symbols/secondstatic intBAUDRATE_256000Baud rate 256000 symbols/secondstatic intBAUDRATE_300Baud rate 300 symbols/secondstatic intBAUDRATE_38400Baud rate 38400 symbols/secondstatic intBAUDRATE_4800Baud rate 4800 symbols/secondstatic intBAUDRATE_57600Baud rate 57600 symbols/secondstatic intBAUDRATE_600Baud rate 600 symbols/secondstatic intBAUDRATE_9600Baud rate 9600 symbols/secondstatic intDATABITS_5Five (5) data bits per bytestatic intDATABITS_6Six (6) data bits per bytestatic intDATABITS_7Seven (7) data bits per bytestatic intDATABITS_8Eight (8) data bits per bytestatic intERROR_FRAMEIndicates faulty data or framestatic intERROR_OVERRUNOverrun error; receiver hardware unable to handle receive datastatic intERROR_PARITYParity/check bit errorstatic intFLOWCONTROL_NONEDisable flow controlstatic intFLOWCONTROL_RTSCTS_INLegacy hardware control: RTS/CTS (request to send/clear to send) flow control on inputstatic intFLOWCONTROL_RTSCTS_OUTLegacy hardware control: RTS/CTS (request to send/clear to send) flow control on outputstatic intFLOWCONTROL_XONXOFF_INSoftware flow control: XON/XOFF flow control on inputstatic intFLOWCONTROL_XONXOFF_OUTSoftware flow control: XON/XOFF flow control on outputstatic intMASK_BREAKBreak (reset a communications line or change the operating mode) flagstatic intMASK_CTSCTS (clear to send) maskstatic intMASK_DSRDSR (data set to ready) flagstatic intMASK_ERRError flagstatic intMASK_RINGState of RING line (0 - OFF, 1 - ON)static intMASK_RLSDRLSD (Receive Line Signal Detected) flagstatic intMASK_RXCHARReceive character flagstatic intMASK_RXFLAGReceive flagstatic intMASK_TXEMPTYReceive empty flagstatic intPARITY_EVENUse a very basic checksum: Send an additional bit to report if even number of data bitsstatic intPARITY_MARKUse a very basic checksum: Send a parity bit to indicate "mark signal" condition (rarely used)static intPARITY_NONEDo not send a parity bitstatic intPARITY_ODDUse a very basic checksum: Send an additional bit to report if odd number of data bitsstatic intPARITY_SPACEUse a very basic checksum: Send a parity bit to indicate "space signal" condition (rarely used)static intPURGE_RXABORTReceive "abort" status codestatic intPURGE_RXCLEARReceive "clear" status codestatic intPURGE_TXABORTTransfer "abort" status codestatic intPURGE_TXCLEARTransfer "clear" status codestatic intSTOPBITS_1One (1) stop bits per bytestatic intSTOPBITS_1_5One and a half (1.5) stop bits per bytestatic intSTOPBITS_2Two (2) stop bits per byte
-
Constructor Summary
Constructors Constructor Description SerialPort(String portName)Construct a serial port object with the specifiedportName
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEventListener(SerialPortEventListener listener)Add event listener.voidaddEventListener(SerialPortEventListener listener, int mask)Add event listener.booleanclosePort()Close port.intgetEventsMask()Getting events mask for the portintgetFlowControlMode()Get flow control modeintgetInputBufferBytesCount()Get count of bytes in input bufferint[]getLinesStatus()Getting lines status.intgetOutputBufferBytesCount()Get count of bytes in output bufferStringgetPortName()Getting port name under operationbooleanisCTS()Get state of CTS linebooleanisDSR()Get state of DSR linebooleanisOpened()Getting port statebooleanisRING()Get state of RING linebooleanisRLSD()Get state of RLSD linebooleanopenPort()Port opening
Note: If port busy TYPE_PORT_BUSY exception will be thrown.booleanpurgePort(int flags)Purge of input and output buffer.byte[]readBytes()Read all available bytes from port like a byte arraybyte[]readBytes(int byteCount)Read byte array from portbyte[]readBytes(int byteCount, int timeout)Read byte array from portStringreadHexString()Read all available bytes from port like a Hex StringStringreadHexString(int byteCount)Read Hex string from port (example: FF 0A FF).StringreadHexString(int byteCount, int timeout)Read Hex string from port (example: FF 0A FF).StringreadHexString(int byteCount, String separator)Read Hex string from port with set separator (example if separator is "::": FF::0A::FF)StringreadHexString(int byteCount, String separator, int timeout)Read Hex string from port with set separator (example if separator is "::": FF::0A::FF)StringreadHexString(String separator)Read all available bytes from port like a Hex String with set separatorString[]readHexStringArray()Read all available bytes from port like a Hex String arrayString[]readHexStringArray(int byteCount)Read Hex String array from portString[]readHexStringArray(int byteCount, int timeout)Read Hex String array from portint[]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 portint[]readIntArray(int byteCount, int timeout)Read int array from portStringreadString()Read all available bytes from port like a StringStringreadString(int byteCount)Read string from portStringreadString(int byteCount, int timeout)Read string from portbooleanremoveEventListener()Delete event listener.booleansendBreak(int duration)Send Break singnal for set durationbooleansetDTR(boolean enabled)Change DTR line state.booleansetEventsMask(int mask)Set events mask.booleansetFlowControlMode(int mask)Set flow control mode.booleansetParams(int baudRate, int dataBits, int stopBits, int parity)Setting the parameters of port.booleansetParams(int baudRate, int dataBits, int stopBits, int parity, boolean setRTS, boolean setDTR)Setting the parameters of portbooleansetRTS(boolean enabled)Change RTS line state.booleanwriteByte(byte singleByte)Write single byte to portbooleanwriteBytes(byte[] buffer)Write byte array to portbooleanwriteInt(int singleInt)Write int value (in range from 0 to 255 (0x00 - 0xFF)) to portbooleanwriteIntArray(int[] buffer)Write int array (in range from 0 to 255 (0x00 - 0xFF)) to portbooleanwriteString(String string)Write String to portbooleanwriteString(String string, String charsetName)Write String to port
-
-
-
Field Detail
-
BAUDRATE_110
public static final int BAUDRATE_110
Baud rate 110 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_300
public static final int BAUDRATE_300
Baud rate 300 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_600
public static final int BAUDRATE_600
Baud rate 600 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_1200
public static final int BAUDRATE_1200
Baud rate 1200 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_2400
public static final int BAUDRATE_2400
Baud rate 2400 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_4800
public static final int BAUDRATE_4800
Baud rate 4800 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_9600
public static final int BAUDRATE_9600
Baud rate 9600 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_14400
public static final int BAUDRATE_14400
Baud rate 14400 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_19200
public static final int BAUDRATE_19200
Baud rate 19200 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_38400
public static final int BAUDRATE_38400
Baud rate 38400 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_57600
public static final int BAUDRATE_57600
Baud rate 57600 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_115200
public static final int BAUDRATE_115200
Baud rate 115200 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_128000
public static final int BAUDRATE_128000
Baud rate 128000 symbols/second- See Also:
- Constant Field Values
-
BAUDRATE_256000
public static final int BAUDRATE_256000
Baud rate 256000 symbols/second- See Also:
- Constant Field Values
-
DATABITS_5
public static final int DATABITS_5
Five (5) data bits per byte- See Also:
- Constant Field Values
-
DATABITS_6
public static final int DATABITS_6
Six (6) data bits per byte- See Also:
- Constant Field Values
-
DATABITS_7
public static final int DATABITS_7
Seven (7) data bits per byte- See Also:
- Constant Field Values
-
DATABITS_8
public static final int DATABITS_8
Eight (8) data bits per byte- See Also:
- Constant Field Values
-
STOPBITS_1
public static final int STOPBITS_1
One (1) stop bits per byte- See Also:
- Constant Field Values
-
STOPBITS_2
public static final int STOPBITS_2
Two (2) stop bits per byte- See Also:
- Constant Field Values
-
STOPBITS_1_5
public static final int STOPBITS_1_5
One and a half (1.5) stop bits per byte- See Also:
- Constant Field Values
-
PARITY_NONE
public static final int PARITY_NONE
Do not send a parity bit- See Also:
- Constant Field Values
-
PARITY_ODD
public static final int PARITY_ODD
Use a very basic checksum: Send an additional bit to report if odd number of data bits- See Also:
- Constant Field Values
-
PARITY_EVEN
public static final int PARITY_EVEN
Use a very basic checksum: Send an additional bit to report if even number of data bits- See Also:
- Constant Field Values
-
PARITY_MARK
public static final int PARITY_MARK
Use a very basic checksum: Send a parity bit to indicate "mark signal" condition (rarely used)- See Also:
- Constant Field Values
-
PARITY_SPACE
public static final int PARITY_SPACE
Use a very basic checksum: Send a parity bit to indicate "space signal" condition (rarely used)- See Also:
- Constant Field Values
-
PURGE_RXABORT
public static final int PURGE_RXABORT
Receive "abort" status code- See Also:
- Constant Field Values
-
PURGE_RXCLEAR
public static final int PURGE_RXCLEAR
Receive "clear" status code- See Also:
- Constant Field Values
-
PURGE_TXABORT
public static final int PURGE_TXABORT
Transfer "abort" status code- See Also:
- Constant Field Values
-
PURGE_TXCLEAR
public static final int PURGE_TXCLEAR
Transfer "clear" status code- See Also:
- Constant Field Values
-
MASK_RXCHAR
public static final int MASK_RXCHAR
Receive character flag- See Also:
- Constant Field Values
-
MASK_RXFLAG
public static final int MASK_RXFLAG
Receive flag- See Also:
- Constant Field Values
-
MASK_TXEMPTY
public static final int MASK_TXEMPTY
Receive empty flag- See Also:
- Constant Field Values
-
MASK_CTS
public static final int MASK_CTS
CTS (clear to send) mask- See Also:
- Constant Field Values
-
MASK_DSR
public static final int MASK_DSR
DSR (data set to ready) flag- See Also:
- Constant Field Values
-
MASK_RLSD
public static final int MASK_RLSD
RLSD (Receive Line Signal Detected) flag- See Also:
- Constant Field Values
-
MASK_BREAK
public static final int MASK_BREAK
Break (reset a communications line or change the operating mode) flag- See Also:
- Constant Field Values
-
MASK_ERR
public static final int MASK_ERR
Error flag- See Also:
- Constant Field Values
-
MASK_RING
public static final int MASK_RING
State of RING line (0 - OFF, 1 - ON)- See Also:
- Constant Field Values
-
FLOWCONTROL_NONE
public static final int FLOWCONTROL_NONE
Disable flow control- See Also:
- Constant Field Values
-
FLOWCONTROL_RTSCTS_IN
public static final int FLOWCONTROL_RTSCTS_IN
Legacy hardware control: RTS/CTS (request to send/clear to send) flow control on input- See Also:
- Constant Field Values
-
FLOWCONTROL_RTSCTS_OUT
public static final int FLOWCONTROL_RTSCTS_OUT
Legacy hardware control: RTS/CTS (request to send/clear to send) flow control on output- See Also:
- Constant Field Values
-
FLOWCONTROL_XONXOFF_IN
public static final int FLOWCONTROL_XONXOFF_IN
Software flow control: XON/XOFF flow control on input- See Also:
- Constant Field Values
-
FLOWCONTROL_XONXOFF_OUT
public static final int FLOWCONTROL_XONXOFF_OUT
Software flow control: XON/XOFF flow control on output- See Also:
- Constant Field Values
-
ERROR_FRAME
public static final int ERROR_FRAME
Indicates faulty data or frame- See Also:
- Constant Field Values
-
ERROR_OVERRUN
public static final int ERROR_OVERRUN
Overrun error; receiver hardware unable to handle receive data- See Also:
- Constant Field Values
-
ERROR_PARITY
public static final int ERROR_PARITY
Parity/check bit error- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SerialPort
public SerialPort(String portName)
Construct a serial port object with the specifiedportName- Parameters:
portName- Name of the port, e.g.COM1,/dev/tty.FOO, etc.
-
-
Method Detail
-
getPortName
public String getPortName()
Getting port name under operation- Returns:
- Method returns port name under operation as a String
-
isOpened
public boolean isOpened()
Getting port state- Returns:
- Method returns true if port is open, otherwise false
-
openPort
public boolean openPort() throws SerialPortExceptionPort opening
Note: If port busy TYPE_PORT_BUSY exception will be thrown. If port not found TYPE_PORT_NOT_FOUND exception will be thrown.- Returns:
- If the operation is successfully completed, the method returns true
- Throws:
SerialPortException- if exception occurred
-
setParams
public boolean setParams(int baudRate, int dataBits, int stopBits, int parity) throws SerialPortExceptionSetting the parameters of port. RTS and DTR lines are enabled by default- Parameters:
baudRate- data transfer ratedataBits- number of data bitsstopBits- number of stop bitsparity- parity- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred
-
setParams
public boolean setParams(int baudRate, int dataBits, int stopBits, int parity, boolean setRTS, boolean setDTR) throws SerialPortExceptionSetting the parameters of port- Parameters:
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)- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
purgePort
public boolean purgePort(int flags) throws SerialPortExceptionPurge of input and output buffer. Required flags shall be sent to the input. Variables with prefix "PURGE_", for example "PURGE_RXCLEAR". Sent parameter "flags" is additive value, so addition of flags is allowed. For example, if input or output buffer shall be purged, parameter "PURGE_RXCLEAR | PURGE_TXCLEAR".
Note: some devices or drivers may not support this function- Parameters:
flags- One or moreSerialPort.PURGE_*flag- Returns:
- If the operation is successfully completed, the method returns true, otherwise false.
- Throws:
SerialPortException- if exception occurred
-
setEventsMask
public boolean setEventsMask(int mask) throws SerialPortExceptionSet events mask. Required flags shall be sent to the input. Variables with prefix "MASK_", shall be used as flags, for example "MASK_RXCHAR". Sent parameter "mask" is additive value, so addition of flags is allowed. For example if messages about data receipt and CTS and DSR status changing shall be received, it is required to set the mask - "MASK_RXCHAR | MASK_CTS | MASK_DSR"- Parameters:
mask- One or moreSerialPort.MASK_*value- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred
-
getEventsMask
public int getEventsMask() throws SerialPortExceptionGetting events mask for the port- Returns:
- Method returns events mask as int type variable. This variable is an additive value
- Throws:
SerialPortException- if exception occurred
-
setRTS
public boolean setRTS(boolean enabled) throws SerialPortExceptionChange RTS line state. Set "true" for switching ON and "false" for switching OFF RTS line- Parameters:
enabled- on/off flag- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred
-
setDTR
public boolean setDTR(boolean enabled) throws SerialPortExceptionChange DTR line state. Set "true" for switching ON and "false" for switching OFF DTR line- Parameters:
enabled- on/off flag- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred
-
writeBytes
public boolean writeBytes(byte[] buffer) throws SerialPortExceptionWrite byte array to port- Parameters:
buffer-byte[]array to write- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred
-
writeByte
public boolean writeByte(byte singleByte) throws SerialPortExceptionWrite single byte to port- Parameters:
singleByte- singlebytevalue to write- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
writeString
public boolean writeString(String string) throws SerialPortException
Write String to port- Parameters:
string-Stringvalue to write- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
writeString
public boolean writeString(String string, String charsetName) throws SerialPortException, UnsupportedEncodingException
Write String to port- Parameters:
string-Stringvalue to writecharsetName- validCharsetname, e.g."UTF-8"- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurredUnsupportedEncodingException- if encoding exception occurred- Since:
- 2.8.0
-
writeInt
public boolean writeInt(int singleInt) throws SerialPortExceptionWrite int value (in range from 0 to 255 (0x00 - 0xFF)) to port- Parameters:
singleInt- singleintvalue to write- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
writeIntArray
public boolean writeIntArray(int[] buffer) throws SerialPortExceptionWrite int array (in range from 0 to 255 (0x00 - 0xFF)) to port- Parameters:
buffer-int[]array to write- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
readBytes
public byte[] readBytes(int byteCount) throws SerialPortExceptionRead byte array from port- Parameters:
byteCount- count of bytes for reading- Returns:
- byte array with "byteCount" length
- Throws:
SerialPortException- if exception occurred
-
readString
public String readString(int byteCount) throws SerialPortException
Read string from port- Parameters:
byteCount- count of bytes for reading- Returns:
- byte array with "byteCount" length converted to String
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
readHexString
public String readHexString(int byteCount) throws SerialPortException
Read Hex string from port (example: FF 0A FF). Separator by default is a space- Parameters:
byteCount- count of bytes for reading- Returns:
- byte array with "byteCount" length converted to Hexadecimal String
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
readHexString
public String readHexString(int byteCount, String separator) throws SerialPortException
Read Hex string from port with set separator (example if separator is "::": FF::0A::FF)- Parameters:
byteCount- count of bytes for readingseparator- the hex string separator, e.g. "::", etc- Returns:
- byte array with "byteCount" length converted to Hexadecimal String
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
readHexStringArray
public String[] readHexStringArray(int byteCount) throws SerialPortException
Read Hex String array from port- Parameters:
byteCount- count of bytes for reading- Returns:
- String array with "byteCount" length and Hexadecimal String values
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
readIntArray
public int[] readIntArray(int byteCount) throws SerialPortExceptionRead int array from port- Parameters:
byteCount- count of bytes for reading- Returns:
- int array with values in range from 0 to 255
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
readBytes
public byte[] readBytes(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutExceptionRead byte array from port- Parameters:
byteCount- count of bytes for readingtimeout- timeout in milliseconds- Returns:
- byte array with "byteCount" length
- Throws:
SerialPortException- if exception occurredSerialPortTimeoutException- if timeout exception occurred- Since:
- 2.0
-
readString
public String readString(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException
Read string from port- Parameters:
byteCount- count of bytes for readingtimeout- timeout in milliseconds- Returns:
- byte array with "byteCount" length converted to String
- Throws:
SerialPortException- if exception occurredSerialPortTimeoutException- if timeout exception occurred- Since:
- 2.0
-
readHexString
public String readHexString(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException
Read Hex string from port (example: FF 0A FF). Separator by default is a space- Parameters:
byteCount- count of bytes for readingtimeout- timeout in milliseconds- Returns:
- byte array with "byteCount" length converted to Hexadecimal String
- Throws:
SerialPortException- if exception occurredSerialPortTimeoutException- if timeout exception occurred- Since:
- 2.0
-
readHexString
public String readHexString(int byteCount, String separator, int timeout) throws SerialPortException, SerialPortTimeoutException
Read Hex string from port with set separator (example if separator is "::": FF::0A::FF)- Parameters:
byteCount- count of bytes for readingseparator- the hex string separator, e.g. "::", etctimeout- timeout in milliseconds- Returns:
- byte array with "byteCount" length converted to Hexadecimal String
- Throws:
SerialPortException- if exception occurredSerialPortTimeoutException- if timeout exception occurred- Since:
- 2.0
-
readHexStringArray
public String[] readHexStringArray(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException
Read Hex String array from port- Parameters:
byteCount- count of bytes for readingtimeout- timeout in milliseconds- Returns:
- String array with "byteCount" length and Hexadecimal String values
- Throws:
SerialPortException- if exception occurredSerialPortTimeoutException- if timeout exception occurred- Since:
- 2.0
-
readIntArray
public int[] readIntArray(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutExceptionRead int array from port- Parameters:
byteCount- count of bytes for readingtimeout- timeout in milliseconds- Returns:
- int array with values in range from 0 to 255
- Throws:
SerialPortException- if exception occurredSerialPortTimeoutException- if timeout exception occurred- Since:
- 2.0
-
readBytes
public byte[] readBytes() throws SerialPortExceptionRead all available bytes from port like a byte array- Returns:
- If input buffer is empty null will be returned, else byte array with all data from port
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
readString
public String readString() throws SerialPortException
Read all available bytes from port like a String- Returns:
- If input buffer is empty null will be returned, else byte array with all data from port converted to String
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
readHexString
public String readHexString() throws SerialPortException
Read all available bytes from port like a Hex String- Returns:
- If input buffer is empty null will be returned, else byte array with all data from port converted to Hex String
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
readHexString
public String readHexString(String separator) throws SerialPortException
Read all available bytes from port like a Hex String with set separator- Parameters:
separator- the hex string separator, e.g. "::", etc- Returns:
- If input buffer is empty null will be returned, else byte array with all data from port converted to Hex String
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
readHexStringArray
public String[] readHexStringArray() throws SerialPortException
Read all available bytes from port like a Hex String array- Returns:
- If input buffer is empty null will be returned, else byte array with all data from port converted to Hex String array
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
readIntArray
public int[] readIntArray() throws SerialPortExceptionRead all available bytes from port like a int array (values in range from 0 to 255)- Returns:
- If input buffer is empty null will be returned, else byte array with all data from port converted to int array
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
getInputBufferBytesCount
public int getInputBufferBytesCount() throws SerialPortExceptionGet count of bytes in input buffer- Returns:
- Count of bytes in input buffer or -1 if error occured
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
getOutputBufferBytesCount
public int getOutputBufferBytesCount() throws SerialPortExceptionGet count of bytes in output buffer- Returns:
- Count of bytes in output buffer or -1 if error occured
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
setFlowControlMode
public boolean setFlowControlMode(int mask) throws SerialPortExceptionSet flow control mode. For required mode use variables with prefix "FLOWCONTROL_". Example of hardware flow control mode(RTS/CTS): setFlowControlMode(FLOWCONTROL_RTSCTS_IN | FLOWCONTROL_RTSCTS_OUT);- Parameters:
mask- mask of flow control mode- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
getFlowControlMode
public int getFlowControlMode() throws SerialPortExceptionGet flow control mode- Returns:
- Mask of set flow control mode
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
sendBreak
public boolean sendBreak(int duration) throws SerialPortExceptionSend Break singnal for set duration- Parameters:
duration- duration of Break signal- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred- Since:
- 0.8
-
getLinesStatus
public int[] getLinesStatus() throws SerialPortExceptionGetting lines status. Lines status is sent as 0 – OFF and 1 - ON- Returns:
- Method returns the array containing information about lines in following order:
element 0 - CTS line state
element 1 - DSR line state
element 2 - RING line state
element 3 - RLSD line state - Throws:
SerialPortException- if exception occurred
-
isCTS
public boolean isCTS() throws SerialPortExceptionGet state of CTS line- Returns:
- If line is active, method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred
-
isDSR
public boolean isDSR() throws SerialPortExceptionGet state of DSR line- Returns:
- If line is active, method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred
-
isRING
public boolean isRING() throws SerialPortExceptionGet state of RING line- Returns:
- If line is active, method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred
-
isRLSD
public boolean isRLSD() throws SerialPortExceptionGet state of RLSD line- Returns:
- If line is active, method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred
-
addEventListener
public void addEventListener(SerialPortEventListener listener) throws SerialPortException
Add event listener. Object of "SerialPortEventListener" type shall be sent to the method. This object shall be properly described, as it will be in charge for handling of occurred events. This method will independently set the mask in "MASK_RXCHAR" state if it was not set beforehand- Parameters:
listener- Event Listener of typeSerialPortListener- Throws:
SerialPortException- if exception occurred
-
addEventListener
public void addEventListener(SerialPortEventListener listener, int mask) throws SerialPortException
Add event listener. Object of "SerialPortEventListener" type shall be sent to the method. This object shall be properly described, as it will be in charge for handling of occurred events. Also events mask shall be sent to this method, to do it use variables with prefix "MASK_" for example "MASK_RXCHAR"- Parameters:
listener- Event Listener of typeSerialPortListenermask-SerialPort.MASK_*representing the event mask to listen upon- Throws:
SerialPortException- if exception occurred- See Also:
setEventsMask(int mask)
-
removeEventListener
public boolean removeEventListener() throws SerialPortExceptionDelete event listener. Mask is set to 0. So at the next addition of event handler you shall set required event mask again- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred
-
closePort
public boolean closePort() throws SerialPortExceptionClose port. This method deletes event listener first, then closes the port- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Throws:
SerialPortException- if exception occurred
-
-