Package jssc
Class SerialNativeInterface
- java.lang.Object
-
- jssc.SerialNativeInterface
-
public class SerialNativeInterface extends Object
- Author:
- scream3r
-
-
Field Summary
Fields Modifier and Type Field Description static longERR_INCORRECT_SERIAL_PORTSerial port handle is incorrectstatic longERR_PERMISSION_DENIEDInsufficient permissions to access portstatic longERR_PORT_BUSYPort is busystatic longERR_PORT_NOT_FOUNDPort is not foundstatic intOS_LINUXLinuxstatic intOS_MAC_OS_XMacOSstatic intOS_SOLARISSolarisstatic intOS_UNKNOWNUnknownstatic intOS_WINDOWSWindowsstatic StringPROPERTY_JSSC_IGNPARIgnore bytes with framing error or parity error Usage:System.setProperty("jssc_ignpar", "true");static StringPROPERTY_JSSC_NO_TIOCEXCLDisable exclusive lock for serial port Usage:System.setProperty("jssc_no_tiocexcl", "true");static StringPROPERTY_JSSC_PARMRKMark bytes with parity error or framing error Usage:System.setProperty("jssc_iparmrk", "true");
-
Constructor Summary
Constructors Constructor Description SerialNativeInterface()Default constructor TODO: This class is effectively static, why instantiate it?
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanclosePort(long handle)Close portint[]getBuffersBytesCount(long handle)Get bytes count in buffers of portintgetEventsMask(long handle)Get events maskintgetFlowControlMode(long handle)Get flow control modestatic StringgetLibraryVersion()Get library versionint[]getLinesStatus(long handle)Getting lines statesstatic StringgetNativeLibraryVersion()Get native library versionstatic intgetOsType()Get OS typeString[]getSerialPortNames()Get serial port names like an array of StringlongopenPort(String portName, boolean useTIOCEXCL)Open portbooleanpurgePort(long handle, int flags)Purge of input and output bufferbyte[]readBytes(long handle, int byteCount)Read data from portbooleansendBreak(long handle, int duration)Send Break signal for set durationbooleansetDTR(long handle, boolean value)Change DTR line statebooleansetEventsMask(long handle, int mask)Set events maskbooleansetFlowControlMode(long handle, int mask)Set flow control modebooleansetParams(long handle, int baudRate, int dataBits, int stopBits, int parity, boolean setRTS, boolean setDTR, int flags)Setting the parameters of opened portbooleansetRTS(long handle, boolean value)Change RTS line stateint[][]waitEvents(long handle)Wait eventsbooleanwriteBytes(long handle, byte[] buffer)Write data to port
-
-
-
Field Detail
-
OS_LINUX
public static final int OS_LINUX
Linux- See Also:
- Constant Field Values
-
OS_WINDOWS
public static final int OS_WINDOWS
Windows- See Also:
- Constant Field Values
-
OS_SOLARIS
public static final int OS_SOLARIS
Solaris- See Also:
- Constant Field Values
-
OS_MAC_OS_X
public static final int OS_MAC_OS_X
MacOS- See Also:
- Constant Field Values
-
OS_UNKNOWN
public static final int OS_UNKNOWN
Unknown- See Also:
- Constant Field Values
-
ERR_PORT_BUSY
public static final long ERR_PORT_BUSY
Port is busy- Since:
- 2.3.0
- See Also:
- Constant Field Values
-
ERR_PORT_NOT_FOUND
public static final long ERR_PORT_NOT_FOUND
Port is not found- Since:
- 2.3.0
- See Also:
- Constant Field Values
-
ERR_PERMISSION_DENIED
public static final long ERR_PERMISSION_DENIED
Insufficient permissions to access port- Since:
- 2.3.0
- See Also:
- Constant Field Values
-
ERR_INCORRECT_SERIAL_PORT
public static final long ERR_INCORRECT_SERIAL_PORT
Serial port handle is incorrect- Since:
- 2.3.0
- See Also:
- Constant Field Values
-
PROPERTY_JSSC_NO_TIOCEXCL
public static final String PROPERTY_JSSC_NO_TIOCEXCL
Disable exclusive lock for serial port Usage:System.setProperty("jssc_no_tiocexcl", "true");- Since:
- 2.6.0
- See Also:
- Constant Field Values
-
PROPERTY_JSSC_IGNPAR
public static final String PROPERTY_JSSC_IGNPAR
Ignore bytes with framing error or parity error Usage:System.setProperty("jssc_ignpar", "true");- Since:
- 2.6.0
- See Also:
- Constant Field Values
-
PROPERTY_JSSC_PARMRK
public static final String PROPERTY_JSSC_PARMRK
Mark bytes with parity error or framing error Usage:System.setProperty("jssc_iparmrk", "true");- Since:
- 2.6.0
- See Also:
- Constant Field Values
-
-
Method Detail
-
getOsType
public static int getOsType()
Get OS type- Returns:
OS_LINUX,OS_WINDOWS,OS_SOLARIS,OS_MACOSorOS_UNKNOWNif unknown.- Since:
- 0.8
-
getLibraryVersion
public static String getLibraryVersion()
Get library version- Returns:
- Full library version in "major.minor.patch" format.
- Since:
- 0.8
-
getNativeLibraryVersion
public static String getNativeLibraryVersion()
Get native library version- Returns:
- Full native library version in "major.minor.patch" format.
- Since:
- 2.8.0
-
openPort
public long openPort(String portName, boolean useTIOCEXCL)
Open port- Parameters:
portName- name of port for openinguseTIOCEXCL- enable/disable using of TIOCEXCL. Take effect only on *nix based systems- Returns:
- handle of opened port or -1 if opening of the port was unsuccessful
-
setParams
public boolean setParams(long handle, int baudRate, int dataBits, int stopBits, int parity, boolean setRTS, boolean setDTR, int flags)Setting the parameters of opened port- Parameters:
handle- handle of opened portbaudRate- 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)flags- additional Native settings. Take effect only on *nix based systems- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
-
purgePort
public boolean purgePort(long handle, int flags)Purge of input and output buffer- Parameters:
handle- handle of opened portflags- flags specifying required actions for purgePort method- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
-
closePort
public boolean closePort(long handle)
Close port- Parameters:
handle- handle of opened port- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
-
setEventsMask
public boolean setEventsMask(long handle, int mask)Set events mask- Parameters:
handle- handle of opened portmask- events mask- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
-
getEventsMask
public int getEventsMask(long handle)
Get events mask- Parameters:
handle- handle of opened port- Returns:
- Method returns event mask as a variable of int type
-
waitEvents
public int[][] waitEvents(long handle)
Wait events- Parameters:
handle- handle of opened port- Returns:
- Method returns two-dimensional array containing event types and their values (events[i][0] - event type, events[i][1] - event value).
-
setRTS
public boolean setRTS(long handle, boolean value)Change RTS line state- Parameters:
handle- handle of opened portvalue- true - ON, false - OFF- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
-
setDTR
public boolean setDTR(long handle, boolean value)Change DTR line state- Parameters:
handle- handle of opened portvalue- true - ON, false - OFF- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
-
readBytes
public byte[] readBytes(long handle, int byteCount)Read data from port- Parameters:
handle- handle of opened portbyteCount- count of bytes required to read- Returns:
- Method returns the array of read bytes
-
writeBytes
public boolean writeBytes(long handle, byte[] buffer)Write data to port- Parameters:
handle- handle of opened portbuffer- array of bytes to write- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
-
getBuffersBytesCount
public int[] getBuffersBytesCount(long handle)
Get bytes count in buffers of port- Parameters:
handle- handle of opened port- Returns:
- Method returns the array that contains info about bytes count in buffers:
element 0 - input buffer
element 1 - output buffer - Since:
- 0.8
-
setFlowControlMode
public boolean setFlowControlMode(long handle, int mask)Set flow control mode- Parameters:
handle- handle of opened portmask- mask of flow control mode- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Since:
- 0.8
-
getFlowControlMode
public int getFlowControlMode(long handle)
Get flow control mode- Parameters:
handle- handle of opened port- Returns:
- Mask of set flow control mode
- Since:
- 0.8
-
getSerialPortNames
public String[] getSerialPortNames()
Get serial port names like an array of String- Returns:
- unsorted array of String with port names
-
getLinesStatus
public int[] getLinesStatus(long handle)
Getting lines states- Parameters:
handle- handle of opened port- 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
-
sendBreak
public boolean sendBreak(long handle, int duration)Send Break signal for set duration- Parameters:
handle- handle of opened portduration- duration of Break signal, in milliseconds- Returns:
- If the operation is successfully completed, the method returns true, otherwise false
- Since:
- 0.8
-
-