..
 #############################################################
 # 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-modbus">Software</a> / Modbus - Industrial Digital In 4 Bricklet

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

.. _industrial_digital_in_4_bricklet_modbus:

Modbus - Industrial Digital In 4 Bricklet
=========================================

This is the description of the :ref:`Modbus protocol <llproto_modbus>` for the :ref:`Industrial Digital In 4 Bricklet <industrial_digital_in_4_bricklet>`. General information and technical
specifications for the Industrial Digital In 4 Bricklet are summarized in its :ref:`hardware description
<industrial_digital_in_4_bricklet_description>`.

.. _industrial_digital_in_4_bricklet_modbus_api:

API
---

A general description of the Modbus protocol structure can be found
:ref:`here <llproto_modbus>`.




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



.. modbus:function:: BrickletIndustrialDigitalIn4.get_value

 :functionid: 1
 :emptyrequest: empty payload

 :response value_mask: uint16

 Returns the input value with a bitmask. The bitmask is 16bit long, *true*
 refers to high and *false* refers to low.
 
 For example: The value 3 or 0b0011 means that pins 0-1 are high and the other
 pins are low.
 
 If no groups are used (see :modbus:func:`set_group <BrickletIndustrialDigitalIn4.set_group>`), the pins correspond to the
 markings on the Digital In 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.
 
.. modbus:function:: BrickletIndustrialDigitalIn4.get_edge_count

 :functionid: 10
 :request pin: uint8
 :request reset_counter: bool

 :response count: uint32

 Returns the current value of the edge counter for the selected pin. You can
 configure the edges that are counted with :modbus:func:`set_edge_count_config <BrickletIndustrialDigitalIn4.set_edge_count_config>`.
 
 If you set the reset counter to *true*, the count is set back to 0
 directly after it is read.
 
 .. versionadded:: 2.0.1~(Plugin)
 


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

.. modbus:function:: BrickletIndustrialDigitalIn4.set_group

 :functionid: 2
 :request group: char[4]

 :noresponse: no response

 Sets a group of Digital In 4 Bricklets that should work together. You can
 find Bricklets that can be grouped together with :modbus:func:`get_available_for_group <BrickletIndustrialDigitalIn4.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 In 4 Bricklets connected to port A and
 port B respectively, you could call with ``['a', 'b', 'n', 'n']``.
 
 Now the pins on the Digital In 4 on port A are assigned to 0-3 and the
 pins on the Digital In 4 on port B are assigned to 4-7. It is now possible
 to call :modbus:func:`get_value <BrickletIndustrialDigitalIn4.get_value>` and read out two Bricklets at the same time.
 
 Changing the group configuration resets all edge counter configurations
 and values.
 
.. modbus:function:: BrickletIndustrialDigitalIn4.get_group

 :functionid: 3
 :emptyrequest: empty payload

 :response group: char[4]

 Returns the group as set by :modbus:func:`set_group <BrickletIndustrialDigitalIn4.set_group>`
 
.. modbus:function:: BrickletIndustrialDigitalIn4.get_available_for_group

 :functionid: 4
 :emptyrequest: empty payload

 :response available: uint8

 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.
 
.. modbus:function:: BrickletIndustrialDigitalIn4.set_edge_count_config

 :functionid: 11
 :request selection_mask: uint16
 :request edge_type: uint8
 :request debounce: uint8

 :noresponse: no response

 Configures the edge counter for the selected pins. A bitmask of 9 or 0b1001 will
 enable the edge counter for pins 0 and 3.
 
 The edge type parameter configures if rising edges, falling edges or
 both are counted if the pin is configured for input. Possible edge types are:
 
 * 0 = rising (default)
 * 1 = falling
 * 2 = both
 
 The debounce time is given in ms.
 
 Configuring an edge counter resets its value to 0.
 
 If you don't know what any of this means, just leave it at default. The
 default configuration is very likely OK for you.
 
 Default values: 0 (edge type) and 100ms (debounce time)
 
 .. versionadded:: 2.0.1~(Plugin)
 
.. modbus:function:: BrickletIndustrialDigitalIn4.get_edge_count_config

 :functionid: 12
 :request pin: uint8

 :response edge_type: uint8
 :response debounce: uint8

 Returns the edge type and debounce time for the selected pin as set by
 :modbus:func:`set_edge_count_config <BrickletIndustrialDigitalIn4.set_edge_count_config>`.
 
 .. versionadded:: 2.0.1~(Plugin)
 
.. modbus:function:: BrickletIndustrialDigitalIn4.get_identity

 :functionid: 255
 :emptyrequest: empty payload

 :response uid: char[8]
 :response connected_uid: char[8]
 :response position: char
 :response hardware_version: uint8[3]
 :response firmware_version: uint8[3]
 :response device_identifier: uint16

 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|
 


Callback Configuration Functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



.. modbus:function:: BrickletIndustrialDigitalIn4.set_debounce_period

 :functionid: 5
 :request debounce: uint32

 :noresponse: no response

 Sets the debounce period of the :modbus:func:`CALLBACK_INTERRUPT <BrickletIndustrialDigitalIn4.CALLBACK_INTERRUPT>` callback in ms.
 
 For example: If you set this value to 100, you will get the interrupt
 maximal every 100ms. This is necessary if something that bounces is
 connected to the Digital In 4 Bricklet, such as a button.
 
 The default value is 100.
 
.. modbus:function:: BrickletIndustrialDigitalIn4.get_debounce_period

 :functionid: 6
 :emptyrequest: empty payload

 :response debounce: uint32

 Returns the debounce period as set by :modbus:func:`set_debounce_period <BrickletIndustrialDigitalIn4.set_debounce_period>`.
 
.. modbus:function:: BrickletIndustrialDigitalIn4.set_interrupt

 :functionid: 7
 :request interrupt_mask: uint16

 :noresponse: no response

 Sets the pins on which an interrupt is activated with a bitmask.
 Interrupts are triggered on changes of the voltage level of the pin,
 i.e. changes from high to low and low to high.
 
 For example: An interrupt bitmask of 9 or 0b1001 will enable the interrupt for
 pins 0 and 3.
 
 The interrupts use the grouping as set by :modbus:func:`set_group <BrickletIndustrialDigitalIn4.set_group>`.
 
 The interrupt is delivered with the callback :modbus:func:`CALLBACK_INTERRUPT <BrickletIndustrialDigitalIn4.CALLBACK_INTERRUPT>`.
 
.. modbus:function:: BrickletIndustrialDigitalIn4.get_interrupt

 :functionid: 8
 :emptyrequest: empty payload

 :response interrupt_mask: uint16

 Returns the interrupt bitmask as set by :modbus:func:`set_interrupt <BrickletIndustrialDigitalIn4.set_interrupt>`.
 


.. _industrial_digital_in_4_bricklet_modbus_callbacks:

Callbacks
^^^^^^^^^

.. modbus:function:: BrickletIndustrialDigitalIn4.CALLBACK_INTERRUPT

 :functionid: 9

 :response interrupt_mask: uint16
 :response value_mask: uint16


 This callback is triggered whenever a change of the voltage level is detected
 on pins where the interrupt was activated with :modbus:func:`set_interrupt <BrickletIndustrialDigitalIn4.set_interrupt>`.
 
 The values are a bitmask that specifies which interrupts occurred
 and the current value bitmask.
 
 For example:
 
 * (1, 1) or (0b0001, 0b0001) means that an interrupt on pin 0 occurred and
   currently pin 0 is high and pins 1-3 are low.
 * (9, 14) or (0b1001, 0b1110) means that interrupts on pins 0 and 3
   occurred and currently pin 0 is low and pins 1-3 are high.
 


