SerialNativeInterface
Date: 2017-02-09

jssc

## Class SerialNativeInterface

- java.lang.Object
- - jssc.SerialNativeInterface

-     public class SerialNativeInterface
      extends java.lang.Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static long` | `ERR_INCORRECT_SERIAL_PORT`
    `static long` | `ERR_PERMISSION_DENIED`
    `static long` | `ERR_PORT_BUSY`
    `static long` | `ERR_PORT_NOT_FOUND`
    `static int` | `OS_LINUX`
    `static int` | `OS_MAC_OS_X`
    `static int` | `OS_SOLARIS`
    `static int` | `OS_WINDOWS`
    `static java.lang.String` | `PROPERTY_JSSC_IGNPAR`
    `static java.lang.String` | `PROPERTY_JSSC_NO_TIOCEXCL`
    `static java.lang.String` | `PROPERTY_JSSC_PARMRK`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SerialNativeInterface()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `closePort(long handle)` Close port
    `int[]` | `getBuffersBytesCount(long handle)` Get bytes count in buffers of port
    `int` | `getEventsMask(long handle)` Get events mask
    `int` | `getFlowControlMode(long handle)` Get flow control mode
    `static java.lang.String` | `getLibraryBaseVersion()` Get jSSC Base Version
    `static java.lang.String` | `getLibraryMinorSuffix()` Get jSSC minor suffix.
    `static java.lang.String` | `getLibraryVersion()` Get jSSC version.
    `int[]` | `getLinesStatus(long handle)` Getting lines states
    `static java.lang.String` | `getNativeLibraryVersion()` Get jSSC native library version
    `static int` | `getOsType()` Get OS type (OS_LINUX || OS_WINDOWS || OS_SOLARIS)
    `java.lang.String[]` | `getSerialPortNames()` Get serial port names like an array of String
    `long` | `openPort(java.lang.String portName, boolean useTIOCEXCL)` Open port
    `boolean` | `purgePort(long handle, int flags)` Purge of input and output buffer
    `byte[]` | `readBytes(long handle, int byteCount)` Read data from port
    `boolean` | `sendBreak(long handle, int duration)` Send Break singnal for setted duration
    `boolean` | `setDTR(long handle, boolean value)` Change DTR line state
    `boolean` | `setEventsMask(long handle, int mask)` Set events mask
    `boolean` | `setFlowControlMode(long handle, int mask)` Set flow control mode
    `boolean` | `setParams(long handle, int baudRate, int dataBits, int stopBits, int parity, boolean setRTS, boolean setDTR, int flags)` Setting the parameters of opened port
    `boolean` | `setRTS(long handle, boolean value)` Change RTS line state
    `int[][]` | `waitEvents(long handle)` Wait events
    `boolean` | `writeBytes(long handle, byte[] buffer)` Write data to port

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### OS_LINUX

          public static final int OS_LINUX

      See Also:
        Constant Field Values

    - #### OS_WINDOWS

          public static final int OS_WINDOWS

      See Also:
        Constant Field Values

    - #### OS_SOLARIS

          public static final int OS_SOLARIS

      See Also:
        Constant Field Values

    - #### OS_MAC_OS_X

          public static final int OS_MAC_OS_X

      See Also:
        Constant Field Values

    - #### ERR_PORT_BUSY

          public static final long ERR_PORT_BUSY

      Since:
        2.3.0
      See Also:
        Constant Field Values

    - #### ERR_PORT_NOT_FOUND

          public static final long ERR_PORT_NOT_FOUND

      Since:
        2.3.0
      See Also:
        Constant Field Values

    - #### ERR_PERMISSION_DENIED

          public static final long ERR_PERMISSION_DENIED

      Since:
        2.3.0
      See Also:
        Constant Field Values

    - #### ERR_INCORRECT_SERIAL_PORT

          public static final long ERR_INCORRECT_SERIAL_PORT

      Since:
        2.3.0
      See Also:
        Constant Field Values

    - #### PROPERTY_JSSC_NO_TIOCEXCL

          public static final java.lang.String PROPERTY_JSSC_NO_TIOCEXCL

      Since:
        2.6.0
      See Also:
        Constant Field Values

    - #### PROPERTY_JSSC_IGNPAR

          public static final java.lang.String PROPERTY_JSSC_IGNPAR

      Since:
        2.6.0
      See Also:
        Constant Field Values

    - #### PROPERTY_JSSC_PARMRK

          public static final java.lang.String PROPERTY_JSSC_PARMRK

      Since:
        2.6.0
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SerialNativeInterface

          public SerialNativeInterface()

  - ### Method Detail

    - #### getOsType

          public static int getOsType()

      Get OS type (OS_LINUX || OS_WINDOWS || OS_SOLARIS)
      Since:
        0.8

    - #### getLibraryVersion

          public static java.lang.String getLibraryVersion()

      Get jSSC version. The version of library is Base Version + Minor Suffix
      Since:
        0.8

    - #### getLibraryBaseVersion

          public static java.lang.String getLibraryBaseVersion()

      Get jSSC Base Version
      Since:
        0.9.0

    - #### getLibraryMinorSuffix

          public static java.lang.String getLibraryMinorSuffix()

      Get jSSC minor suffix. For example in version 0.8.1 - 1 is a minor suffix
      Since:
        0.9.0

    - #### getNativeLibraryVersion

          public static java.lang.String getNativeLibraryVersion()

      Get jSSC native library version
      Returns:
        native lib version (for jSSC-2.8.0 should be 2.8 for example)
      Since:
        2.8.0

    - #### openPort

          public long openPort(java.lang.String portName,
                      boolean useTIOCEXCL)

      Open port
      Parameters:
        `portName` - name of port for opening
        `useTIOCEXCL` - 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 port
        `baudRate` - data transfer rate
        `dataBits` - number of data bits
        `stopBits` - number of stop bits
        `parity` - parity
        `setRTS` - 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 port
        `flags` - 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 port
        `mask` - 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 port
        `value` - 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 port
        `value` - 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 port
        `byteCount` - 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 port
        `buffer` - 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 port
        `mask` - 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 setted flow control mode
      Since:
        0.8

    - #### getSerialPortNames

          public java.lang.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 singnal for setted duration
      Parameters:
        `handle` - handle of opened port
        `duration` - duration of Break signal
      Returns:
        If the operation is successfully completed, the method returns true, otherwise false
      Since:
        0.8