com.digi.xbee.api.connection

## Class DataReader

- java.lang.Object
- - java.lang.Thread
  - - com.digi.xbee.api.connection.DataReader

- All Implemented Interfaces:
    Runnable

      public class DataReader
      extends Thread

  Thread that constantly reads data from an input stream.

  Depending on the XBee operating mode, read data is notified as is to the subscribed listeners or is parsed to a packet using the packet parser and then notified to subscribed listeners.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.lang.Thread

      `Thread.State, Thread.UncaughtExceptionHandler`

  - ### Field Summary

    - ### Fields inherited from class java.lang.Thread

      `MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DataReader(IConnectionInterface connectionInterface, OperatingMode mode, XBeeDevice xbeeDevice)` Class constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addDataReceiveListener(IDataReceiveListener listener)` Adds the given data receive listener to the list of listeners that will be notified when XBee data packets are received.
    `void` | `addIOSampleReceiveListener(IIOSampleReceiveListener listener)` Adds the given IO sample receive listener to the list of listeners that will be notified when an IO sample packet is received.
    `void` | `addModemStatusReceiveListener(IModemStatusReceiveListener listener)` Adds the given Modem Status receive listener to the list of listeners that will be notified when a modem status packet is received.
    `void` | `addPacketReceiveListener(IPacketReceiveListener listener)` Adds the given packet receive listener to the list of listeners that will be notified when any XBee packet is received.
    `void` | `addPacketReceiveListener(IPacketReceiveListener listener, int frameID)` Adds the given packet receive listener to the list of listeners that will be notified when an XBee packet with the given frame ID is received.
    `XBeePacketsQueue` | `getXBeePacketsQueue()` Returns the queue of read XBee packets.
    `boolean` | `isRunning()` Returns whether this Data reader is running or not.
    `void` | `removeDataReceiveListener(IDataReceiveListener listener)` Removes the given data receive listener from the list of data receive listeners.
    `void` | `removeIOSampleReceiveListener(IIOSampleReceiveListener listener)` Removes the given IO sample receive listener from the list of IO sample receive listeners.
    `void` | `removeModemStatusReceiveListener(IModemStatusReceiveListener listener)` Removes the given Modem Status receive listener from the list of Modem Status receive listeners.
    `void` | `removePacketReceiveListener(IPacketReceiveListener listener)` Removes the given packet receive listener from the list of XBee packet receive listeners.
    `void` | `run()`
    `void` | `setXBeeReaderMode(OperatingMode mode)` Sets the XBee operating mode of this data reader.
    `void` | `stopReader()` Stops the Data reader thread.

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

      `activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield`

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

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

- - ### Constructor Detail

    - #### DataReader

          public DataReader(IConnectionInterface connectionInterface,
                    OperatingMode mode,
                    XBeeDevice xbeeDevice)

      Class constructor. Instantiates a new `DataReader` object for the given connection interface using the given XBee operating mode and XBee device.
      Parameters:
        `connectionInterface` - Connection interface to read data from.
        `mode` - XBee operating mode.
        `xbeeDevice` - Reference to the XBee device containing this `DataReader` object.
      Throws:
        `NullPointerException` - if `connectionInterface == null` or `mode == null`.
      See Also:
        `IConnectionInterface`, `XBeeDevice`, `OperatingMode`

  - ### Method Detail

    - #### addDataReceiveListener

          public void addDataReceiveListener(IDataReceiveListener listener)

      Adds the given data receive listener to the list of listeners that will be notified when XBee data packets are received.

      If the listener has been already added, this method does nothing.

      Parameters:
        `listener` - Listener to be notified when new XBee data packets are received.
      See Also:
        `removeDataReceiveListener(IDataReceiveListener)`, `IDataReceiveListener`

    - #### addIOSampleReceiveListener

          public void addIOSampleReceiveListener(IIOSampleReceiveListener listener)

      Adds the given IO sample receive listener to the list of listeners that will be notified when an IO sample packet is received.

      If the listener has been already added, this method does nothing.

      Parameters:
        `listener` - Listener to be notified when new IO sample packets are received.
      See Also:
        `removeIOSampleReceiveListener(IIOSampleReceiveListener)`, `IIOSampleReceiveListener`

    - #### addModemStatusReceiveListener

          public void addModemStatusReceiveListener(IModemStatusReceiveListener listener)

      Adds the given Modem Status receive listener to the list of listeners that will be notified when a modem status packet is received.

      If the listener has been already added, this method does nothing.

      Parameters:
        `listener` - Listener to be notified when new modem status packets are received.
      See Also:
        `removeModemStatusReceiveListener(IModemStatusReceiveListener)`, `IModemStatusReceiveListener`

    - #### addPacketReceiveListener

          public void addPacketReceiveListener(IPacketReceiveListener listener)

      Adds the given packet receive listener to the list of listeners that will be notified when any XBee packet is received.

      If the listener has been already added, this method does nothing.

      Parameters:
        `listener` - Listener to be notified when any XBee packet is received.
      See Also:
        `addPacketReceiveListener(IPacketReceiveListener, int)`, `removePacketReceiveListener(IPacketReceiveListener)`, `IPacketReceiveListener`

    - #### addPacketReceiveListener

          public void addPacketReceiveListener(IPacketReceiveListener listener,
                                      int frameID)

      Adds the given packet receive listener to the list of listeners that will be notified when an XBee packet with the given frame ID is received.

      If the listener has been already added, this method does nothing.

      Parameters:
        `listener` - Listener to be notified when an XBee packet with the provided frame ID is received.
        `frameID` - Frame ID for which this listener should be notified and removed after. Using `ALL_FRAME_IDS` this listener will be notified always and will be removed only by user request.
      See Also:
        `addPacketReceiveListener(IPacketReceiveListener)`, `removePacketReceiveListener(IPacketReceiveListener)`, `IPacketReceiveListener`

    - #### getXBeePacketsQueue

          public XBeePacketsQueue getXBeePacketsQueue()

      Returns the queue of read XBee packets.
      Returns:
        The queue of read XBee packets.
      See Also:
        `XBeePacketsQueue`

    - #### isRunning

          public boolean isRunning()

      Returns whether this Data reader is running or not.
      Returns:
        `true` if the Data reader is running, `false` otherwise.
      See Also:
        `stopReader()`

    - #### removeDataReceiveListener

          public void removeDataReceiveListener(IDataReceiveListener listener)

      Removes the given data receive listener from the list of data receive listeners.

      If the listener is not included in the list, this method does nothing.

      Parameters:
        `listener` - Data receive listener to be remove from the list.
      See Also:
        `addDataReceiveListener(IDataReceiveListener)`, `IDataReceiveListener`

    - #### removeIOSampleReceiveListener

          public void removeIOSampleReceiveListener(IIOSampleReceiveListener listener)

      Removes the given IO sample receive listener from the list of IO sample receive listeners.

      If the listener is not included in the list, this method does nothing.

      Parameters:
        `listener` - IO sample receive listener to remove from the list.
      See Also:
        `addIOSampleReceiveListener(IIOSampleReceiveListener)`, `IIOSampleReceiveListener`

    - #### removeModemStatusReceiveListener

          public void removeModemStatusReceiveListener(IModemStatusReceiveListener listener)

      Removes the given Modem Status receive listener from the list of Modem Status receive listeners.

      If the listener is not included in the list, this method does nothing.

      Parameters:
        `listener` - Modem Status receive listener to remove from the list.
      See Also:
        `addModemStatusReceiveListener(IModemStatusReceiveListener)`, `IModemStatusReceiveListener`

    - #### removePacketReceiveListener

          public void removePacketReceiveListener(IPacketReceiveListener listener)

      Removes the given packet receive listener from the list of XBee packet receive listeners.

      If the listener is not included in the list, this method does nothing.

      Parameters:
        `listener` - Packet receive listener to remove from the list.
      See Also:
        `addPacketReceiveListener(IPacketReceiveListener)`, `addPacketReceiveListener(IPacketReceiveListener, int)`, `IPacketReceiveListener`

    - #### run

          public void run()

      Specified by:
        `run` in interface `Runnable`
      Overrides:
        `run` in class `Thread`

    - #### setXBeeReaderMode

          public void setXBeeReaderMode(OperatingMode mode)

      Sets the XBee operating mode of this data reader.
      Parameters:
        `mode` - New XBee operating mode.
      Throws:
        `NullPointerException` - if `mode == null`.
      See Also:
        `OperatingMode`

    - #### stopReader

          public void stopReader()

      Stops the Data reader thread.
      See Also:
        `isRunning()`

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