..
 #############################################################
 # 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 - Rotary Encoder Bricklet

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

.. _rotary_encoder_bricklet_modbus:

Modbus - Rotary Encoder Bricklet
================================

This is the description of the :ref:`Modbus protocol <llproto_modbus>` for the :ref:`Rotary Encoder Bricklet <rotary_encoder_bricklet>`. General information and technical
specifications for the Rotary Encoder Bricklet are summarized in its :ref:`hardware description
<rotary_encoder_bricklet_description>`.

.. _rotary_encoder_bricklet_modbus_api:

API
---

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




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



.. modbus:function:: BrickletRotaryEncoder.get_count

 :functionid: 1
 :request reset: bool

 :response count: int32

 Returns the current count of the encoder. If you set reset
 to true, the count is set back to 0 directly after the
 current count is read.
 
 The encoder has 24 steps per rotation
 
 Turning the encoder to the left decrements the counter,
 so a negative count is possible.
 
.. modbus:function:: BrickletRotaryEncoder.is_pressed

 :functionid: 10
 :emptyrequest: empty payload

 :response pressed: bool

 Returns *true* if the button is pressed and *false* otherwise.
 
 It is recommended to use the :modbus:func:`CALLBACK_PRESSED <BrickletRotaryEncoder.CALLBACK_PRESSED>` and :modbus:func:`CALLBACK_RELEASED <BrickletRotaryEncoder.CALLBACK_RELEASED>` callbacks
 to handle the button.
 


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

.. modbus:function:: BrickletRotaryEncoder.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:: BrickletRotaryEncoder.set_count_callback_period

 :functionid: 2
 :request period: uint32

 :noresponse: no response

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

 :functionid: 3
 :emptyrequest: empty payload

 :response period: uint32

 Returns the period as set by :modbus:func:`set_count_callback_period <BrickletRotaryEncoder.set_count_callback_period>`.
 
.. modbus:function:: BrickletRotaryEncoder.set_count_callback_threshold

 :functionid: 4
 :request option: char
 :request min: int32
 :request max: int32

 :noresponse: no response

 Sets the thresholds for the :modbus:func:`CALLBACK_COUNT_REACHED <BrickletRotaryEncoder.CALLBACK_COUNT_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 count is *outside* the min and max values"
  "'i'",    "Callback is triggered when the count is *inside* the min and max values"
  "'<'",    "Callback is triggered when the count is smaller than the min value (max is ignored)"
  "'>'",    "Callback is triggered when the count is greater than the min value (max is ignored)"
 
 The default value is ('x', 0, 0).
 
.. modbus:function:: BrickletRotaryEncoder.get_count_callback_threshold

 :functionid: 5
 :emptyrequest: empty payload

 :response option: char
 :response min: int32
 :response max: int32

 Returns the threshold as set by :modbus:func:`set_count_callback_threshold <BrickletRotaryEncoder.set_count_callback_threshold>`.
 
.. modbus:function:: BrickletRotaryEncoder.set_debounce_period

 :functionid: 6
 :request debounce: uint32

 :noresponse: no response

 Sets the period in ms with which the threshold callback
 
 * :modbus:func:`CALLBACK_COUNT_REACHED <BrickletRotaryEncoder.CALLBACK_COUNT_REACHED>`
 
 is triggered, if the thresholds
 
 * :modbus:func:`set_count_callback_threshold <BrickletRotaryEncoder.set_count_callback_threshold>`
 
 keeps being reached.
 
 The default value is 100.
 
.. modbus:function:: BrickletRotaryEncoder.get_debounce_period

 :functionid: 7
 :emptyrequest: empty payload

 :response debounce: uint32

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


.. _rotary_encoder_bricklet_modbus_callbacks:

Callbacks
^^^^^^^^^

.. modbus:function:: BrickletRotaryEncoder.CALLBACK_COUNT

 :functionid: 8

 :response count: int32


 This callback is triggered periodically with the period that is set by
 :modbus:func:`set_count_callback_period <BrickletRotaryEncoder.set_count_callback_period>`. The response value is the count of
 the encoder.
 
 :modbus:func:`CALLBACK_COUNT <BrickletRotaryEncoder.CALLBACK_COUNT>` is only triggered if the count has changed since the
 last triggering.
 
.. modbus:function:: BrickletRotaryEncoder.CALLBACK_COUNT_REACHED

 :functionid: 9

 :response count: int32


 This callback is triggered when the threshold as set by
 :modbus:func:`set_count_callback_threshold <BrickletRotaryEncoder.set_count_callback_threshold>` is reached.
 The response value is the count of the encoder.
 
 If the threshold keeps being reached, the callback is triggered periodically
 with the period as set by :modbus:func:`set_debounce_period <BrickletRotaryEncoder.set_debounce_period>`.
 
.. modbus:function:: BrickletRotaryEncoder.CALLBACK_PRESSED

 :functionid: 11

 :emptyresponse: empty payload


 This callback is triggered when the button is pressed.
 
.. modbus:function:: BrickletRotaryEncoder.CALLBACK_RELEASED

 :functionid: 12

 :emptyresponse: empty payload


 This callback is triggered when the button is released.
 


