..
 #############################################################
 # This file was automatically generated on 2015-05-08.      #
 #                                                           #
 # If you have a bugfix for this file and want to commit it, #
 # please fix the bug in the generator. You can find a link  #
 # to the generators git repository on tinkerforge.com       #
 #############################################################


:breadcrumbs: <a href="../../index.html">Home</a> / <a href="../../index.html#software-shell">Software</a> / Shell - Industrial Digital Out 4 Bricklet

.. |device_identifier_constant| unicode:: 0xA0
   :trim:

.. _industrial_digital_out_4_bricklet_shell:

Shell - Industrial Digital Out 4 Bricklet
=========================================

This is the description of the :ref:`Shell API bindings <api_bindings_shell>` for the :ref:`Industrial Digital Out 4 Bricklet <industrial_digital_out_4_bricklet>`. General information and technical
specifications for the Industrial Digital Out 4 Bricklet are summarized in its :ref:`hardware description
<industrial_digital_out_4_bricklet_description>`.

An :ref:`installation guide <api_bindings_shell_install>` for the Shell API
bindings is part of their general description.

.. _industrial_digital_out_4_bricklet_shell_examples:


Examples
--------

The example code below is `Public Domain (CC0 1.0)
<http://creativecommons.org/publicdomain/zero/1.0/>`__.

Simple
^^^^^^

`Download (example-simple.sh) <https://github.com/Tinkerforge/industrial-digital-out-4-bricklet/raw/master/software/examples/shell/example-simple.sh>`__

.. literalinclude:: IndustrialDigitalOut4_Bricklet_Shell_example-simple.sh
 :language: bash
 :linenos:
 :tab-width: 4

.. _industrial_digital_out_4_bricklet_shell_api:

API
---

Possible exit codes for all ``tinkerforge`` commands are:

* 1: interrupted (ctrl+c)
* 2: syntax error
* 21: Python 2.5 or newer is required
* 22: Python ``argparse`` module is missing
* 23: socket error
* 24: other exception
* 25: invalid placeholder in format string
* 26: authentication error
* 201: timeout occurred
* 209: invalid argument value
* 210: function is not supported
* 211: unknown error



Command Structure
^^^^^^^^^^^^^^^^^

The common options of the ``call`` and ``dispatch`` commands are documented
:ref:`here <ipcon_shell_api>`. The specific command structure is shown below.

.. sh:function:: X Stinkerforge Pcall Nindustrial-digital-out-4-bricklet A[<option>..] L<uid> L<function> L[<argument>..]

 :param <uid>: string
 :param <function>: string

 The ``call`` command is used to call a function of the Industrial Digital Out 4 Bricklet. It can take several
 options:

 * ``--help`` shows help for the specific ``call`` command and exits
 * ``--list-functions`` shows a list of known functions of the Industrial Digital Out 4 Bricklet and exits


.. sh:function:: X Stinkerforge Pdispatch Nindustrial-digital-out-4-bricklet A[<option>..] L<uid> L<callback>

 :param <uid>: string
 :param <callback>: string

 The ``dispatch`` command is used to dispatch a callback of the Industrial Digital Out 4 Bricklet. It can
 take several options:

 * ``--help`` shows help for the specific ``dispatch`` command and exits
 * ``--list-callbacks`` shows a list of known callbacks of the Industrial Digital Out 4 Bricklet and exits


.. sh:function:: X Stinkerforge Scall Pindustrial-digital-out-4-bricklet L<uid> N<function> A[<option>..] L[<argument>..]

 :param <uid>: string
 :param <function>: string

 The ``<function>`` to be called can take different options depending of its
 kind. All functions can take the following options:

 * ``--help`` shows help for the specific function and exits

 Getter functions can take the following options:

 * ``--execute <command>`` shell command line to execute for each incoming
   response (see section about :ref:`output formatting <ipcon_shell_output>`
   for details)

 Setter functions can take the following options:

 * ``--expect-response`` requests response and waits for it

 The ``--expect-response`` option for setter functions allows to detect
 timeouts and other error conditions calls of setters as well. The device will
 then send a response for this purpose. If this option is not given for a
 setter function then no response is send and errors are silently ignored,
 because they cannot be detected.


.. sh:function:: X Stinkerforge Sdispatch Pindustrial-digital-out-4-bricklet L<uid> N<callback> A[<option>..]

 :param <uid>: string
 :param <callback>: string

 The ``<callback>`` to be dispatched can take several options:

 * ``--help`` shows help for the specific callback and exits
 * ``--execute <command>`` shell command line to execute for each incoming
   response (see section about :ref:`output formatting <ipcon_shell_output>`
   for details)



Basic Functions
^^^^^^^^^^^^^^^



.. sh:function:: tinkerforge call industrial-digital-out-4-bricklet <uid> set-value <value-mask> 

 :param <value-mask>: int

 :noreturn: no output

 Sets the output value with a bitmask (16bit). A 1 in the bitmask means high
 and a 0 in the bitmask means low.
 
 For example: The value 3 or 0b0011 will turn pins 0-1 high and the other pins
 low.
 
 If no groups are used (see :sh:func:`set-group <industrial-digital-out-4-bricklet set-group>`), the pins correspond to the
 markings on the Digital Out 4 Bricklet.
 
 If groups are used, the pins correspond to the element in the group.
 Element 1 in the group will get pins 0-3, element 2 pins 4-7, element 3
 pins 8-11 and element 4 pins 12-15.
 
.. sh:function:: tinkerforge call industrial-digital-out-4-bricklet <uid> get-value  


 :returns value-mask: int

 Returns the bitmask as set by :sh:func:`set-value <industrial-digital-out-4-bricklet set-value>`.
 
.. sh:function:: tinkerforge call industrial-digital-out-4-bricklet <uid> set-selected-values <selection-mask> <value-mask> 

 :param <selection-mask>: int
 :param <value-mask>: int

 :noreturn: no output

 Sets the output value with a bitmask, according to the selection mask.
 The bitmask is 16 bit long, *true* refers to high and *false* refers to 
 low.
 
 For example: The values (3, 1) or (0b0011, 0b0001) will turn pin 0 high, pin 1
 low the other pins remain untouched.
 
 If no groups are used (see :sh:func:`set-group <industrial-digital-out-4-bricklet set-group>`), the pins correspond to the
 markings on the Digital Out 4 Bricklet.
 
 If groups are used, the pins correspond to the element in the group.
 Element 1 in the group will get pins 0-3, element 2 pins 4-7, element 3
 pins 8-11 and element 4 pins 12-15.
 


Advanced Functions
^^^^^^^^^^^^^^^^^^

.. sh:function:: tinkerforge call industrial-digital-out-4-bricklet <uid> set-monoflop <selection-mask> <value-mask> <time> 

 :param <selection-mask>: int
 :param <value-mask>: int
 :param <time>: int

 :noreturn: no output

 Configures a monoflop of the pins specified by the first parameter
 bitmask.
 
 The second parameter is a bitmask with the desired value of the specified
 pins. A 1 in the bitmask means high and a 0 in the bitmask means low.
 
 The third parameter indicates the time (in ms) that the pins should hold
 the value.
 
 If this function is called with the parameters (9, 1, 1500) or
 (0b1001, 0b0001, 1500): Pin 0 will get high and pin 3 will get low. In 1.5s
 pin 0 will get low and pin 3 will get high again.
 
 A monoflop can be used as a fail-safe mechanism. For example: Lets assume you
 have a RS485 bus and a Digital Out 4 Bricklet connected to one of the slave
 stacks. You can now call this function every second, with a time parameter
 of two seconds and pin 0 high. Pin 0 will be high all the time. If now
 the RS485 connection is lost, then pin 0 will turn low in at most two seconds.
 
.. sh:function:: tinkerforge call industrial-digital-out-4-bricklet <uid> get-monoflop <pin> 

 :param <pin>: int

 :returns value: int
 :returns time: int
 :returns time-remaining: int

 Returns (for the given pin) the current value and the time as set by
 :sh:func:`set-monoflop <industrial-digital-out-4-bricklet set-monoflop>` as well as the remaining time until the value flips.
 
 If the timer is not running currently, the remaining time will be returned
 as 0.
 
.. sh:function:: tinkerforge call industrial-digital-out-4-bricklet <uid> set-group <group> 

 :param <group>: char,char,char,char

 :noreturn: no output

 Sets a group of Digital Out 4 Bricklets that should work together. You can
 find Bricklets that can be grouped together with :sh:func:`get-available-for-group <industrial-digital-out-4-bricklet get-available-for-group>`.
 
 The group consists of 4 elements. Element 1 in the group will get pins 0-3,
 element 2 pins 4-7, element 3 pins 8-11 and element 4 pins 12-15.
 
 Each element can either be one of the ports ('a' to 'd') or 'n' if it should
 not be used.
 
 For example: If you have two Digital Out 4 Bricklets connected to port A and
 port B respectively, you could call with ``['a', 'b', 'n', 'n']``.
 
 Now the pins on the Digital Out 4 on port A are assigned to 0-3 and the
 pins on the Digital Out 4 on port B are assigned to 4-7. It is now possible
 to call :sh:func:`set-value <industrial-digital-out-4-bricklet set-value>` and control two Bricklets at the same time.
 
.. sh:function:: tinkerforge call industrial-digital-out-4-bricklet <uid> get-group  


 :returns group: char,char,char,char

 Returns the group as set by :sh:func:`set-group <industrial-digital-out-4-bricklet set-group>`
 
.. sh:function:: tinkerforge call industrial-digital-out-4-bricklet <uid> get-available-for-group  


 :returns available: int

 Returns a bitmask of ports that are available for grouping. For example the
 value 5 or 0b0101 means: Port A and port C are connected to Bricklets that
 can be grouped together.
 
.. sh:function:: tinkerforge call industrial-digital-out-4-bricklet <uid> get-identity  


 :returns uid: string
 :returns connected-uid: string
 :returns position: char
 :returns hardware-version: int,int,int
 :returns firmware-version: int,int,int
 :returns device-identifier: int (has symbols)

 Returns the UID, the UID where the Bricklet is connected to, 
 the position, the hardware and firmware version as well as the
 device identifier.
 
 The position can be 'a', 'b', 'c' or 'd'.
 
 The device identifier numbers can be found :ref:`here <device_identifier>`.
 |device_identifier_constant|
 


.. _industrial_digital_out_4_bricklet_shell_callbacks:

Callbacks
^^^^^^^^^

Callbacks can be used to receive time critical or recurring data from the
device:

.. code-block:: bash

    tinkerforge dispatch industrial-digital-out-4-bricklet <uid> example

The available callbacks are described below.

.. note::
 Using callbacks for recurring events is *always* preferred
 compared to using getters. It will use less USB bandwidth and the latency
 will be a lot better, since there is no round trip time.

.. sh:function::  tinkerforge dispatch industrial-digital-out-4-bricklet <uid> monoflop-done

 :returns selection-mask: int
 :returns value-mask: int


 This callback is triggered whenever a monoflop timer reaches 0. The
 parameters contain the involved pins and the current value of the pins
 (the value after the monoflop).
 


