.. _local-io:

******************************
Local IO (Analog and Digital)
******************************

.. index:: devices

Overview
====================
A Dia driver for the analog and digital functionality present locally on
the gateway on some devices.  This driver presents a subset of the
:ref:`xbee-aio` and :ref:`xbee-dio` driver options.

Configuration
====================

A typical local io configuration block for a device that has 2 analog
ports and 2 digital ports might look like this::

    - name: local_io0
      driver: devices.local_io:LocalIO
      settings:
        xbee_device_manager: <instance name>
        sample_rate_ms: 60000
        calibration_rate_ms: 900000
        channel1_mode: "TenV"
        channel2_mode: "TenV"
        channel3_dir: In
        channel4_dir: Out
        channel4_source: dio0.channel1_value


Settings
--------------------

xbee_device_manager (required)
    The name of an XBeeDeviceManager instance to manage this device

power (optional, default: On)
   Turns on or off the aux power on the local IO interface.
   NOTE:  Not all devices support this option.  Only the Digi X3 products supports turning power off.
          All other Digi products have the power output always on.

sample_rate_ms (required)
    The sample rate of the XBee adapter in milliseconds.

calibration_rate_ms (optional, default: 900000)
    The rate in which the analog ports calibrate themselves to the
    current local environment.


Specific settings for Analog channels:

    channel(1-4)_mode (optional, default: TenV)
        Operating input mode for pin 1 of the adapter.

        Must be a string value comprised of one of the following:

         ``TenV``
             0-10v input available on any channel.

         ``CurrentLoop``
             0-20 mA current loop available on any channel.


Specific settings Digital channels:

    channel(1-4)_dir (required)
        Operating I/O mode for appropriate pin of the adapter.

        Must be a string value comprised of one of the following:

        ``In``
            Pin is configured to be an input.
        ``Out``
            Pin is configured to be an output.

    channel(1-4)_source (optional)
        If channel<x>_dir is configured as an output, this option setting
        may be specified to a ``device.channel`` channel name.  The Boolean
        value of this channel will specify to logic state for pin ``x`` on the
        adapter.


Channels
====================

For Analog channels:

    channel(1-4)_value (Get, type: float, units: V(TenV) or mA(CurrentLoop))
        The value measured by the device.  The units will depend on the
        configuration of the appropriate ``mode`` setting.


For Digital channels:

    channel(1-4)_input (Get, type: bool, units: bool)
        The value measured by the device.  The units will depend on the
        configuration of the appropriate ``mode`` setting.

