com.digi.xbee.api.connection.serial

## Class AbstractSerialPort

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

- All Implemented Interfaces:
    IConnectionInterface
  Direct Known Subclasses:
    SerialPortRxTx

      public abstract class AbstractSerialPort
      extends Object
      implements IConnectionInterface

  Abstract class that provides common functionality to work with serial ports.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_DATA_BITS` Default number of data bits: 8.
    `static int` | `DEFAULT_FLOW_CONTROL` Default flow control: 0 (None).
    `static int` | `DEFAULT_PARITY` Default parity: 0 (None).
    `static int` | `DEFAULT_PORT_TIMEOUT` Default receive timeout: 10 seconds.
    `static int` | `DEFAULT_STOP_BITS` Default number of stop bits: 1.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `flush()` Flushes the available data of the output stream.
    `String` | `getPort()` Returns the name of the serial port.
    `SerialPortParameters` | `getPortParameters()` Returns the XBee serial port parameters.
    `abstract int` | `getReadTimeout()` Returns the read timeout of the serial port (in milliseconds).
    `int` | `getReceiveTimeout()` Returns the serial port receive timeout (in milliseconds).
    `abstract boolean` | `isCD()` Returns the state of the CD line.
    `abstract boolean` | `isCTS()` Returns the state of the CTS line.
    `abstract boolean` | `isDSR()` Returns the state of the DSR line.
    `boolean` | `isHardwareFlowControl()` Returns whether or not the port's flow control is configured in hardware mode.
    `boolean` | `isOpen()` Returns whether the connection interface is open or not.
    `void` | `purge()` Purges the serial port removing all the data from the input stream.
    `int` | `readData(byte[] data)` Reads data from the connection interface and stores it in the provided byte array returning the number of read bytes.
    `int` | `readData(byte[] data, int offset, int length)` Reads the given number of bytes at the given offset from the connection interface and stores it in the provided byte array returning the number of read bytes.
    `abstract void` | `sendBreak(int duration)` Sends a break signal to the serial port with the given duration (in milliseconds).
    `abstract void` | `setBreak(boolean enabled)` Enables or disables the break line.
    `abstract 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` | `setPortParameters(SerialPortParameters parameters)` Sets the new parameters of the serial port as `SerialPortParameters`.
    `abstract void` | `setReadTimeout(int timeout)` Sets the read timeout of the serial port (in milliseconds).
    `abstract void` | `setRTS(boolean state)` Sets the state of the RTS line.
    `String` | `toString()`
    `void` | `writeData(byte[] data)` Writes the given data in the connection interface.
    `void` | `writeData(byte[] data, int offset, int length)` Writes the given data in the connection interface.

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

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

    - ### Methods inherited from interface com.digi.xbee.api.connection.IConnectionInterface

      `close, getInputStream, getOutputStream, open`

- - ### Field Detail

    - #### DEFAULT_DATA_BITS

          public static final int DEFAULT_DATA_BITS

      Default number of data bits: 8.
      See Also:
        Constant Field Values

    - #### DEFAULT_FLOW_CONTROL

          public static final int DEFAULT_FLOW_CONTROL

      Default flow control: 0 (None).
      See Also:
        Constant Field Values

    - #### DEFAULT_PARITY

          public static final int DEFAULT_PARITY

      Default parity: 0 (None).
      See Also:
        Constant Field Values

    - #### DEFAULT_PORT_TIMEOUT

          public static final int DEFAULT_PORT_TIMEOUT

      Default receive timeout: 10 seconds.

      When the specified number of milliseconds have elapsed, read will return immediately.

      See Also:
        Constant Field Values

    - #### DEFAULT_STOP_BITS

          public static final int DEFAULT_STOP_BITS

      Default number of stop bits: 1.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### flush

          public void flush()

      Flushes the available data of the output stream.
      See Also:
        `purge()`

    - #### getPort

          public String getPort()

      Returns the name of the serial port.
      Returns:
        Port name.

    - #### getPortParameters

          public SerialPortParameters getPortParameters()

      Returns the XBee serial port parameters.
      Returns:
        The XBee serial port parameters.
      See Also:
        `setPortParameters(SerialPortParameters)`, `setPortParameters(int, int, int, int, int)`, `SerialPortParameters`

    - #### getReadTimeout

          public abstract int getReadTimeout()

      Returns the read timeout of the serial port (in milliseconds).
      Returns:
        The read timeout of the serial port in milliseconds.
      See Also:
        `setReadTimeout(int)`

    - #### getReceiveTimeout

          public int getReceiveTimeout()

      Returns the serial port receive timeout (in milliseconds).
      Returns:
        The serial port receive timeout in milliseconds.
      See Also:
        `getReadTimeout()`, `setReadTimeout(int)`

    - #### isCD

          public abstract boolean isCD()

      Returns the state of the CD line.
      Returns:
        `true` if the line is high, `false` otherwise.
      See Also:
        `isCTS()`, `isDSR()`, `setDTR(boolean)`, `setRTS(boolean)`

    - #### isCTS

          public abstract boolean isCTS()

      Returns the state of the CTS line.
      Returns:
        `true` if the line is high, `false` otherwise.
      See Also:
        `isCD()`, `isDSR()`, `setDTR(boolean)`, `setRTS(boolean)`

    - #### isDSR

          public abstract boolean isDSR()

      Returns the state of the DSR line.
      Returns:
        `true` if the line is high, `false` otherwise.
      See Also:
        `isCD()`, `isCTS()`, `setDTR(boolean)`, `setRTS(boolean)`

    - #### isHardwareFlowControl

          public boolean isHardwareFlowControl()

      Returns whether or not the port's flow control is configured in hardware mode.
      Returns:
        `true` if the flow control is hardware, `false` otherwise.
      See Also:
        `getPortParameters()`, `setPortParameters(SerialPortParameters)`, `setPortParameters(int, int, int, int, int)`

    - #### isOpen

          public boolean isOpen()

      Description copied from interface: `IConnectionInterface`
      Returns whether the connection interface is open or not.
      Specified by:
        `isOpen` in interface `IConnectionInterface`
      Returns:
        `true` if the connection interface is open, `false` otherwise.
      See Also:
        `IConnectionInterface.close()`, `IConnectionInterface.open()`

    - #### purge

          public void purge()

      Purges the serial port removing all the data from the input stream.
      See Also:
        `flush()`

    - #### readData

          public int readData(byte[] data)
                       throws IOException

      Description copied from interface: `IConnectionInterface`
      Reads data from the connection interface and stores it in the provided byte array returning the number of read bytes.
      Specified by:
        `readData` in interface `IConnectionInterface`
      Parameters:
        `data` - The byte array to store the read data.
      Returns:
        The number of bytes read.
      Throws:
        `IOException` - if there is any problem reading from the input stream.
      See Also:
        `IConnectionInterface.readData(byte[], int, int)`

    - #### readData

          public int readData(byte[] data,
                     int offset,
                     int length)
                       throws IOException

      Description copied from interface: `IConnectionInterface`
      Reads the given number of bytes at the given offset from the connection interface and stores it in the provided byte array returning the number of read bytes.
      Specified by:
        `readData` in interface `IConnectionInterface`
      Parameters:
        `data` - The byte array to store the read data.
        `offset` - The start offset in data array at which the data is written.
        `length` - Maximum number of bytes to read.
      Returns:
        The number of bytes read.
      Throws:
        `IOException` - if there is any problem reading from the input stream.
      See Also:
        `IConnectionInterface.readData(byte[])`

    - #### sendBreak

          public abstract void sendBreak(int duration)

      Sends a break signal to the serial port with the given duration (in milliseconds).
      Parameters:
        `duration` - Duration of the break signal in milliseconds.
      See Also:
        `setBreak(boolean)`

    - #### setBreak

          public abstract void setBreak(boolean enabled)

      Enables or disables the break line.
      Parameters:
        `enabled` - `true` to enable the Break line, `false` to disable it.
      See Also:
        `sendBreak(int)`

    - #### setDTR

          public abstract void setDTR(boolean state)

      Sets the state of the DTR.
      Parameters:
        `state` - `true` to set the line status high, `false` to set it low.
      See Also:
        `isCD()`, `isCTS()`, `isDSR()`, `setRTS(boolean)`

    - #### setPortParameters

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

      Sets the new parameters of the serial port.
      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:
        `ConnectionException` - if any error occurs when setting the serial port parameters
        `IllegalArgumentException` - if `baudRate < 0` or if `dataBits < 0` or if `stopBits < 0` or if `parity < 0` or if `flowControl < 0`.
        `InvalidConfigurationException` - if the configuration is invalid.
      See Also:
        `getPortParameters()`, `setPortParameters(SerialPortParameters)`

    - #### setPortParameters

          public void setPortParameters(SerialPortParameters parameters)
                                 throws InvalidConfigurationException,
                                        ConnectionException

      Sets the new parameters of the serial port as `SerialPortParameters`.
      Parameters:
        `parameters` - The new serial port parameters.
      Throws:
        `ConnectionException` - if any error occurs when setting the serial port parameters.
        `InvalidConfigurationException` - if the configuration is invalid.
        `NullPointerException` - if `parameters == null`.
      See Also:
        `getPortParameters()`, `setPortParameters(int, int, int, int, int)`, `SerialPortParameters`

    - #### setReadTimeout

          public abstract void setReadTimeout(int timeout)

      Sets the read timeout of the serial port (in milliseconds).
      Parameters:
        `timeout` - The new read timeout of the serial port in milliseconds.
      See Also:
        `getReadTimeout()`

    - #### setRTS

          public abstract void setRTS(boolean state)

      Sets the state of the RTS line.
      Parameters:
        `state` - `true` to set the line status high, `false` to set it low.
      See Also:
        `isCD()`, `isCTS()`, `isDSR()`, `setDTR(boolean)`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### writeData

          public void writeData(byte[] data)
                         throws IOException

      Description copied from interface: `IConnectionInterface`
      Writes the given data in the connection interface.
      Specified by:
        `writeData` in interface `IConnectionInterface`
      Parameters:
        `data` - The data to be written in the connection interface.
      Throws:
        `IOException` - if there is any problem writing to the output stream.
      See Also:
        `IConnectionInterface.writeData(byte[], int, int)`

    - #### writeData

          public void writeData(byte[] data,
                       int offset,
                       int length)
                         throws IOException

      Description copied from interface: `IConnectionInterface`
      Writes the given data in the connection interface.
      Specified by:
        `writeData` in interface `IConnectionInterface`
      Parameters:
        `data` - The data to be written in the connection interface.
        `offset` - The start offset in the data to write.
        `length` - The number of bytes to write.
      Throws:
        `IOException` - if there is any problem writing to the output stream.
      See Also:
        `IConnectionInterface.writeData(byte[])`

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