com.digi.xbee.api.connection.serial

## Class SerialPortRxTx

- java.lang.Object
- - com.digi.xbee.api.connection.serial.AbstractSerialPort
  - - com.digi.xbee.api.connection.serial.SerialPortRxTx

- All Implemented Interfaces:
    IConnectionInterface, gnu.io.CommPortOwnershipListener, gnu.io.SerialPortEventListener, EventListener

      public class SerialPortRxTx
      extends AbstractSerialPort
      implements gnu.io.SerialPortEventListener, gnu.io.CommPortOwnershipListener

  This class represents a serial port using the RxTx library to communicate with it.

- - ### Field Summary

    - ### Fields inherited from class com.digi.xbee.api.connection.serial.AbstractSerialPort

      `DEFAULT_DATA_BITS, DEFAULT_FLOW_CONTROL, DEFAULT_PARITY, DEFAULT_PORT_TIMEOUT, DEFAULT_STOP_BITS`

    - ### Fields inherited from interface gnu.io.CommPortOwnershipListener

      `PORT_OWNED, PORT_OWNERSHIP_REQUESTED, PORT_UNOWNED`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SerialPortRxTx(String port, int baudRate)` Class constructor.
    `SerialPortRxTx(String port, int baudRate, int receiveTimeout)` Class constructor.
    `SerialPortRxTx(String port, SerialPortParameters parameters)` Class constructor.
    `SerialPortRxTx(String port, SerialPortParameters parameters, int receiveTimeout)` Class constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Attempts to close the connection interface.
    `InputStream` | `getInputStream()` Returns the connection interface input stream to read data from.
    `OutputStream` | `getOutputStream()` Returns the connection interface output stream to write data to.
    `int` | `getReadTimeout()` Returns the read timeout of the serial port (in milliseconds).
    `boolean` | `isCD()` Returns the state of the CD line.
    `boolean` | `isCTS()` Returns the state of the CTS line.
    `boolean` | `isDSR()` Returns the state of the DSR line.
    `static String[]` | `listSerialPorts()` Retrieves the list of available serial ports in the system.
    `static ArrayList<SerialPortInfo>` | `listSerialPortsInfo()` Retrieves the list of available serial ports with their information.
    `void` | `open()` Attempts to open the connection interface.
    `void` | `ownershipChange(int nType)`
    `void` | `sendBreak(int duration)` Sends a break signal to the serial port with the given duration (in milliseconds).
    `void` | `serialEvent(gnu.io.SerialPortEvent event)`
    `void` | `setBreak(boolean enabled)` Enables or disables the break line.
    `void` | `setDTR(boolean state)` Sets the state of the DTR.
    `void` | `setPortParameters(int baudRate, int dataBits, int stopBits, int parity, int flowControl)` Sets the new parameters of the serial port.
    `void` | `setReadTimeout(int timeout)` Sets the read timeout of the serial port (in milliseconds).
    `void` | `setRTS(boolean state)` Sets the state of the RTS line.
    `String` | `toString()`

    - ### Methods inherited from class com.digi.xbee.api.connection.serial.AbstractSerialPort

      `flush, getPort, getPortParameters, getReceiveTimeout, isHardwareFlowControl, isOpen, purge, readData, readData, setPortParameters, writeData, writeData`

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

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### SerialPortRxTx

          public SerialPortRxTx(String port,
                        int baudRate)

      Class constructor. Instances a new `SerialPortRxTx` object using the given parameters.
      Parameters:
        `port` - Serial port name to use.
        `baudRate` - Serial port baud rate, the rest of parameters will be set by default.
      Throws:
        `NullPointerException` - if `port == null`.
      See Also:
        `AbstractSerialPort.DEFAULT_DATA_BITS`, `AbstractSerialPort.DEFAULT_FLOW_CONTROL`, `AbstractSerialPort.DEFAULT_PARITY`, `AbstractSerialPort.DEFAULT_STOP_BITS`, `AbstractSerialPort.DEFAULT_PORT_TIMEOUT`, `SerialPortRxTx(String, int, int)`, `SerialPortRxTx(String, SerialPortParameters)`, `SerialPortRxTx(String, SerialPortParameters, int)`, `SerialPortParameters`

    - #### SerialPortRxTx

          public SerialPortRxTx(String port,
                        int baudRate,
                        int receiveTimeout)

      Class constructor. Instances a new `SerialPortRxTx` object using the given parameters.
      Parameters:
        `port` - Serial port name to use.
        `baudRate` - Serial port baud rate, the rest of parameters will be set by default.
        `receiveTimeout` - Serial port receive timeout in milliseconds.
      Throws:
        `IllegalArgumentException` - if `receiveTimeout < 0`.
        `NullPointerException` - if `port == null`.
      See Also:
        `AbstractSerialPort.DEFAULT_DATA_BITS`, `AbstractSerialPort.DEFAULT_FLOW_CONTROL`, `AbstractSerialPort.DEFAULT_PARITY`, `AbstractSerialPort.DEFAULT_STOP_BITS`, `SerialPortRxTx(String, int)`, `SerialPortRxTx(String, SerialPortParameters)`, `SerialPortRxTx(String, SerialPortParameters, int)`, `SerialPortParameters`

    - #### SerialPortRxTx

          public SerialPortRxTx(String port,
                        SerialPortParameters parameters)

      Class constructor. Instances a new `SerialPortRxTx` object using the given parameters.
      Parameters:
        `port` - Serial port name to use.
        `parameters` - Serial port parameters.
      Throws:
        `NullPointerException` - if `port == null` or if `parameters == null`.
      See Also:
        `SerialPortRxTx(String, int)`, `SerialPortRxTx(String, int, int)`, `SerialPortRxTx(String, SerialPortParameters, int)`, `SerialPortParameters`

    - #### SerialPortRxTx

          public SerialPortRxTx(String port,
                        SerialPortParameters parameters,
                        int receiveTimeout)

      Class constructor. Instances a new `SerialPortRxTx` object using the given parameters.
      Parameters:
        `port` - Serial port name to use.
        `parameters` - Serial port parameters.
        `receiveTimeout` - Serial port receive timeout in milliseconds.
      Throws:
        `IllegalArgumentException` - if `receiveTimeout < 0`.
        `NullPointerException` - if `port == null` or if `parameters == null`.
      See Also:
        `SerialPortRxTx(String, int)`, `SerialPortRxTx(String, int, int)`, `SerialPortRxTx(String, SerialPortParameters)`, `SerialPortParameters`

  - ### Method Detail

    - #### close

          public void close()

      Description copied from interface: `IConnectionInterface`
      Attempts to close the connection interface.
      Specified by:
        `close` in interface `IConnectionInterface`
      See Also:
        `IConnectionInterface.isOpen()`, `IConnectionInterface.open()`

    - #### getInputStream

          public InputStream getInputStream()

      Description copied from interface: `IConnectionInterface`
      Returns the connection interface input stream to read data from.
      Specified by:
        `getInputStream` in interface `IConnectionInterface`
      Returns:
        The connection interface input stream to read data from.
      See Also:
        `IConnectionInterface.getOutputStream()`, `InputStream`

    - #### getOutputStream

          public OutputStream getOutputStream()

      Description copied from interface: `IConnectionInterface`
      Returns the connection interface output stream to write data to.
      Specified by:
        `getOutputStream` in interface `IConnectionInterface`
      Returns:
        The connection interface output stream to write data to.
      See Also:
        `IConnectionInterface.getInputStream()`, `OutputStream`

    - #### getReadTimeout

          public int getReadTimeout()

      Description copied from class: `AbstractSerialPort`
      Returns the read timeout of the serial port (in milliseconds).
      Specified by:
        `getReadTimeout` in class `AbstractSerialPort`
      Returns:
        The read timeout of the serial port in milliseconds.
      See Also:
        `AbstractSerialPort.setReadTimeout(int)`

    - #### isCD

          public boolean isCD()

      Description copied from class: `AbstractSerialPort`
      Returns the state of the CD line.
      Specified by:
        `isCD` in class `AbstractSerialPort`
      Returns:
        `true` if the line is high, `false` otherwise.
      See Also:
        `AbstractSerialPort.isCTS()`, `AbstractSerialPort.isDSR()`, `AbstractSerialPort.setDTR(boolean)`, `AbstractSerialPort.setRTS(boolean)`

    - #### isCTS

          public boolean isCTS()

      Description copied from class: `AbstractSerialPort`
      Returns the state of the CTS line.
      Specified by:
        `isCTS` in class `AbstractSerialPort`
      Returns:
        `true` if the line is high, `false` otherwise.
      See Also:
        `AbstractSerialPort.isCD()`, `AbstractSerialPort.isDSR()`, `AbstractSerialPort.setDTR(boolean)`, `AbstractSerialPort.setRTS(boolean)`

    - #### isDSR

          public boolean isDSR()

      Description copied from class: `AbstractSerialPort`
      Returns the state of the DSR line.
      Specified by:
        `isDSR` in class `AbstractSerialPort`
      Returns:
        `true` if the line is high, `false` otherwise.
      See Also:
        `AbstractSerialPort.isCD()`, `AbstractSerialPort.isCTS()`, `AbstractSerialPort.setDTR(boolean)`, `AbstractSerialPort.setRTS(boolean)`

    - #### listSerialPorts

          public static String[] listSerialPorts()

      Retrieves the list of available serial ports in the system.
      Returns:
        List of available serial ports.
      See Also:
        `listSerialPortsInfo()`

    - #### listSerialPortsInfo

          public static ArrayList<SerialPortInfo> listSerialPortsInfo()

      Retrieves the list of available serial ports with their information.
      Returns:
        List of available serial ports with their information.
      See Also:
        `listSerialPorts()`, `SerialPortInfo`

    - #### open

          public void open()
                    throws InterfaceInUseException,
                           InvalidInterfaceException,
                           InvalidConfigurationException,
                           PermissionDeniedException

      Description copied from interface: `IConnectionInterface`
      Attempts to open the connection interface.
      Specified by:
        `open` in interface `IConnectionInterface`
      Throws:
        `InterfaceInUseException` - if the interface is in use by other application(s).
        `InvalidInterfaceException` - if the interface is invalid or does not exist.
        `InvalidConfigurationException` - if the configuration used to open the interface is invalid.
        `PermissionDeniedException` - if you do not have permissions to access the interface.
      See Also:
        `IConnectionInterface.close()`, `IConnectionInterface.isOpen()`

    - #### ownershipChange

          public void ownershipChange(int nType)

      Specified by:
        `ownershipChange` in interface `gnu.io.CommPortOwnershipListener`

    - #### sendBreak

          public void sendBreak(int duration)

      Description copied from class: `AbstractSerialPort`
      Sends a break signal to the serial port with the given duration (in milliseconds).
      Specified by:
        `sendBreak` in class `AbstractSerialPort`
      Parameters:
        `duration` - Duration of the break signal in milliseconds.
      See Also:
        `AbstractSerialPort.setBreak(boolean)`

    - #### serialEvent

          public void serialEvent(gnu.io.SerialPortEvent event)

      Specified by:
        `serialEvent` in interface `gnu.io.SerialPortEventListener`

    - #### setBreak

          public void setBreak(boolean enabled)

      Description copied from class: `AbstractSerialPort`
      Enables or disables the break line.
      Specified by:
        `setBreak` in class `AbstractSerialPort`
      Parameters:
        `enabled` - `true` to enable the Break line, `false` to disable it.
      See Also:
        `AbstractSerialPort.sendBreak(int)`

    - #### setDTR

          public void setDTR(boolean state)

      Description copied from class: `AbstractSerialPort`
      Sets the state of the DTR.
      Specified by:
        `setDTR` in class `AbstractSerialPort`
      Parameters:
        `state` - `true` to set the line status high, `false` to set it low.
      See Also:
        `AbstractSerialPort.isCD()`, `AbstractSerialPort.isCTS()`, `AbstractSerialPort.isDSR()`, `AbstractSerialPort.setRTS(boolean)`

    - #### setPortParameters

          public void setPortParameters(int baudRate,
                               int dataBits,
                               int stopBits,
                               int parity,
                               int flowControl)
                                 throws InvalidConfigurationException,
                                        ConnectionException

      Description copied from class: `AbstractSerialPort`
      Sets the new parameters of the serial port.
      Overrides:
        `setPortParameters` in class `AbstractSerialPort`
      Parameters:
        `baudRate` - The new value of baud rate.
        `dataBits` - The new value of data bits.
        `stopBits` - The new value of stop bits.
        `parity` - The new value of parity.
        `flowControl` - The new value of flow control.
      Throws:
        `InvalidConfigurationException` - if the configuration is invalid.
        `ConnectionException` - if any error occurs when setting the serial port parameters
      See Also:
        `AbstractSerialPort.getPortParameters()`, `AbstractSerialPort.setPortParameters(SerialPortParameters)`

    - #### setReadTimeout

          public void setReadTimeout(int timeout)

      Description copied from class: `AbstractSerialPort`
      Sets the read timeout of the serial port (in milliseconds).
      Specified by:
        `setReadTimeout` in class `AbstractSerialPort`
      Parameters:
        `timeout` - The new read timeout of the serial port in milliseconds.
      See Also:
        `AbstractSerialPort.getReadTimeout()`

    - #### setRTS

          public void setRTS(boolean state)

      Description copied from class: `AbstractSerialPort`
      Sets the state of the RTS line.
      Specified by:
        `setRTS` in class `AbstractSerialPort`
      Parameters:
        `state` - `true` to set the line status high, `false` to set it low.
      See Also:
        `AbstractSerialPort.isCD()`, `AbstractSerialPort.isCTS()`, `AbstractSerialPort.isDSR()`, `AbstractSerialPort.setDTR(boolean)`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `AbstractSerialPort`

© Copyright 2014–2014 Digi International Inc. All rights reserved.