..
 #############################################################
 # 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 - Distance IR Bricklet

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

.. _distance_ir_bricklet_modbus:

Modbus - Distance IR Bricklet
=============================

This is the description of the :ref:`Modbus protocol <llproto_modbus>` for the :ref:`Distance IR Bricklet <distance_ir_bricklet>`. General information and technical
specifications for the Distance IR Bricklet are summarized in its :ref:`hardware description
<distance_ir_bricklet_description>`.

.. _distance_ir_bricklet_modbus_api:

API
---

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




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



.. modbus:function:: BrickletDistanceIR.get_distance

 :functionid: 1
 :emptyrequest: empty payload

 :response distance: uint16

 Returns the distance measured by the sensor. The value is in mm and possible
 distance ranges are 40 to 300, 100 to 800 and 200 to 1500, depending on the
 selected IR sensor.
 
 If you want to get the distance periodically, it is recommended to use the
 callback :modbus:func:`CALLBACK_DISTANCE <BrickletDistanceIR.CALLBACK_DISTANCE>` and set the period with 
 :modbus:func:`set_distance_callback_period <BrickletDistanceIR.set_distance_callback_period>`.
 


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

.. modbus:function:: BrickletDistanceIR.get_analog_value

 :functionid: 2
 :emptyrequest: empty payload

 :response value: uint16

 Returns the value as read by a 12-bit analog-to-digital converter.
 The value is between 0 and 4095.
 
 .. note::
  The value returned by :modbus:func:`get_distance <BrickletDistanceIR.get_distance>` is averaged over several samples
  to yield less noise, while :modbus:func:`get_analog_value <BrickletDistanceIR.get_analog_value>` gives back raw
  unfiltered analog values. The only reason to use :modbus:func:`get_analog_value <BrickletDistanceIR.get_analog_value>` is,
  if you need the full resolution of the analog-to-digital converter.
 
 If you want the analog value periodically, it is recommended to use the 
 callback :modbus:func:`CALLBACK_ANALOG_VALUE <BrickletDistanceIR.CALLBACK_ANALOG_VALUE>` and set the period with 
 :modbus:func:`set_analog_value_callback_period <BrickletDistanceIR.set_analog_value_callback_period>`.
 
.. modbus:function:: BrickletDistanceIR.set_sampling_point

 :functionid: 3
 :request position: uint8
 :request distance: uint16

 :noresponse: no response

 Sets a sampling point value to a specific position of the lookup table.
 The lookup table comprises 128 equidistant analog values with
 corresponding distances.
 
 If you measure a distance of 50cm at the analog value 2048, you
 should call this function with (64, 5000). The utilized analog-to-digital
 converter has a resolution of 12 bit. With 128 sampling points on the
 whole range, this means that every sampling point has a size of 32
 analog values. Thus the analog value 2048 has the corresponding sampling
 point 64 = 2048/32.
 
 Sampling points are saved on the EEPROM of the Distance IR Bricklet and
 loaded again on startup.
 
 .. note::
  An easy way to calibrate the sampling points of the Distance IR Bricklet is
  implemented in the Brick Viewer. If you want to calibrate your Bricklet it is
  highly recommended to use this implementation.
 
.. modbus:function:: BrickletDistanceIR.get_sampling_point

 :functionid: 4
 :request position: uint8

 :response distance: uint16

 Returns the distance to a sampling point position as set by
 :modbus:func:`set_sampling_point <BrickletDistanceIR.set_sampling_point>`.
 
.. modbus:function:: BrickletDistanceIR.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:: BrickletDistanceIR.set_distance_callback_period

 :functionid: 5
 :request period: uint32

 :noresponse: no response

 Sets the period in ms with which the :modbus:func:`CALLBACK_DISTANCE <BrickletDistanceIR.CALLBACK_DISTANCE>` callback is triggered
 periodically. A value of 0 turns the callback off.
 
 :modbus:func:`CALLBACK_DISTANCE <BrickletDistanceIR.CALLBACK_DISTANCE>` is only triggered if the distance has changed since the
 last triggering.
 
 The default value is 0.
 
.. modbus:function:: BrickletDistanceIR.get_distance_callback_period

 :functionid: 6
 :emptyrequest: empty payload

 :response period: uint32

 Returns the period as set by :modbus:func:`set_distance_callback_period <BrickletDistanceIR.set_distance_callback_period>`.
 
.. modbus:function:: BrickletDistanceIR.set_analog_value_callback_period

 :functionid: 7
 :request period: uint32

 :noresponse: no response

 Sets the period in ms with which the :modbus:func:`CALLBACK_ANALOG_VALUE <BrickletDistanceIR.CALLBACK_ANALOG_VALUE>` callback is triggered
 periodically. A value of 0 turns the callback off.
 
 :modbus:func:`CALLBACK_ANALOG_VALUE <BrickletDistanceIR.CALLBACK_ANALOG_VALUE>` is only triggered if the analog value has changed since the
 last triggering.
 
 The default value is 0.
 
.. modbus:function:: BrickletDistanceIR.get_analog_value_callback_period

 :functionid: 8
 :emptyrequest: empty payload

 :response period: uint32

 Returns the period as set by :modbus:func:`set_analog_value_callback_period <BrickletDistanceIR.set_analog_value_callback_period>`.
 
.. modbus:function:: BrickletDistanceIR.set_distance_callback_threshold

 :functionid: 9
 :request option: char
 :request min: int16
 :request max: int16

 :noresponse: no response

 Sets the thresholds for the :modbus:func:`CALLBACK_DISTANCE_REACHED <BrickletDistanceIR.CALLBACK_DISTANCE_REACHED>` callback. 
 
 The following options are possible:
 
 .. csv-table::
  :header: "Option", "Description"
  :widths: 10, 100
 
  "'x'",    "Callback is turned off"
  "'o'",    "Callback is triggered when the distance is *outside* the min and max values"
  "'i'",    "Callback is triggered when the distance is *inside* the min and max values"
  "'<'",    "Callback is triggered when the distance is smaller than the min value (max is ignored)"
  "'>'",    "Callback is triggered when the distance is greater than the min value (max is ignored)"
 
 The default value is ('x', 0, 0).
 
.. modbus:function:: BrickletDistanceIR.get_distance_callback_threshold

 :functionid: 10
 :emptyrequest: empty payload

 :response option: char
 :response min: int16
 :response max: int16

 Returns the threshold as set by :modbus:func:`set_distance_callback_threshold <BrickletDistanceIR.set_distance_callback_threshold>`.
 
.. modbus:function:: BrickletDistanceIR.set_analog_value_callback_threshold

 :functionid: 11
 :request option: char
 :request min: uint16
 :request max: uint16

 :noresponse: no response

 Sets the thresholds for the :modbus:func:`CALLBACK_ANALOG_VALUE_REACHED <BrickletDistanceIR.CALLBACK_ANALOG_VALUE_REACHED>` callback. 
 
 The following options are possible:
 
 .. csv-table::
  :header: "Option", "Description"
  :widths: 10, 100
 
  "'x'",    "Callback is turned off"
  "'o'",    "Callback is triggered when the analog value is *outside* the min and max values"
  "'i'",    "Callback is triggered when the analog value is *inside* the min and max values"
  "'<'",    "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
  "'>'",    "Callback is triggered when the analog value is greater than the min value (max is ignored)"
 
 The default value is ('x', 0, 0).
 
.. modbus:function:: BrickletDistanceIR.get_analog_value_callback_threshold

 :functionid: 12
 :emptyrequest: empty payload

 :response option: char
 :response min: uint16
 :response max: uint16

 Returns the threshold as set by :modbus:func:`set_analog_value_callback_threshold <BrickletDistanceIR.set_analog_value_callback_threshold>`.
 
.. modbus:function:: BrickletDistanceIR.set_debounce_period

 :functionid: 13
 :request debounce: uint32

 :noresponse: no response

 Sets the period in ms with which the threshold callbacks
 
 * :modbus:func:`CALLBACK_DISTANCE_REACHED <BrickletDistanceIR.CALLBACK_DISTANCE_REACHED>`,
 * :modbus:func:`CALLBACK_ANALOG_VALUE_REACHED <BrickletDistanceIR.CALLBACK_ANALOG_VALUE_REACHED>`
 
 are triggered, if the thresholds
 
 * :modbus:func:`set_distance_callback_threshold <BrickletDistanceIR.set_distance_callback_threshold>`,
 * :modbus:func:`set_analog_value_callback_threshold <BrickletDistanceIR.set_analog_value_callback_threshold>`
 
 keep being reached.
 
 The default value is 100.
 
.. modbus:function:: BrickletDistanceIR.get_debounce_period

 :functionid: 14
 :emptyrequest: empty payload

 :response debounce: uint32

 Returns the debounce period as set by :modbus:func:`set_debounce_period <BrickletDistanceIR.set_debounce_period>`.
 


.. _distance_ir_bricklet_modbus_callbacks:

Callbacks
^^^^^^^^^

.. modbus:function:: BrickletDistanceIR.CALLBACK_DISTANCE

 :functionid: 15

 :response distance: uint16


 This callback is triggered periodically with the period that is set by
 :modbus:func:`set_distance_callback_period <BrickletDistanceIR.set_distance_callback_period>`. The response value is the distance of the
 sensor.
 
 :modbus:func:`CALLBACK_DISTANCE <BrickletDistanceIR.CALLBACK_DISTANCE>` is only triggered if the distance has changed since the
 last triggering.
 
.. modbus:function:: BrickletDistanceIR.CALLBACK_ANALOG_VALUE

 :functionid: 16

 :response value: uint16


 This callback is triggered periodically with the period that is set by
 :modbus:func:`set_analog_value_callback_period <BrickletDistanceIR.set_analog_value_callback_period>`. The response value is the analog value of the
 sensor.
 
 :modbus:func:`CALLBACK_ANALOG_VALUE <BrickletDistanceIR.CALLBACK_ANALOG_VALUE>` is only triggered if the analog value has changed since the
 last triggering.
 
.. modbus:function:: BrickletDistanceIR.CALLBACK_DISTANCE_REACHED

 :functionid: 17

 :response distance: uint16


 This callback is triggered when the threshold as set by
 :modbus:func:`set_distance_callback_threshold <BrickletDistanceIR.set_distance_callback_threshold>` is reached.
 The response value is the distance of the sensor.
 
 If the threshold keeps being reached, the callback is triggered periodically
 with the period as set by :modbus:func:`set_debounce_period <BrickletDistanceIR.set_debounce_period>`.
 
.. modbus:function:: BrickletDistanceIR.CALLBACK_ANALOG_VALUE_REACHED

 :functionid: 18

 :response value: uint16


 This callback is triggered when the threshold as set by
 :modbus:func:`set_analog_value_callback_threshold <BrickletDistanceIR.set_analog_value_callback_threshold>` is reached.
 The response value is the analog value of the sensor.
 
 If the threshold keeps being reached, the callback is triggered periodically
 with the period as set by :modbus:func:`set_debounce_period <BrickletDistanceIR.set_debounce_period>`.
 


