..
 #############################################################
 # 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 - Piezo Speaker Bricklet

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

.. _piezo_speaker_bricklet_modbus:

Modbus - Piezo Speaker Bricklet
===============================

This is the description of the :ref:`Modbus protocol <llproto_modbus>` for the :ref:`Piezo Speaker Bricklet <piezo_speaker_bricklet>`. General information and technical
specifications for the Piezo Speaker Bricklet are summarized in its :ref:`hardware description
<piezo_speaker_bricklet_description>`.

.. _piezo_speaker_bricklet_modbus_api:

API
---

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




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



.. modbus:function:: BrickletPiezoSpeaker.beep

 :functionid: 1
 :request duration: uint32
 :request frequency: uint16

 :noresponse: no response

 Beeps with the given frequency for the duration in ms. For example: 
 If you set a duration of 1000, with a frequency value of 2000
 the piezo buzzer will beep for one second with a frequency of
 approximately 2 kHz.
 
 .. versionchanged:: 2.0.2~(Plugin)
    A duration of 0 stops the current beep if any, the frequency parameter is
    ignored. A duration of 4294967295 results in an infinite beep.
 
 The *frequency* parameter can be set between 585 and 7100.
 
 The Piezo Speaker Bricklet can only approximate the frequency, it will play
 the best possible match by applying the calibration (see :modbus:func:`calibrate <BrickletPiezoSpeaker.calibrate>`).
 
.. modbus:function:: BrickletPiezoSpeaker.morse_code

 :functionid: 2
 :request morse: char[60]
 :request frequency: uint16

 :noresponse: no response

 Sets morse code that will be played by the piezo buzzer. The morse code
 is given as a string consisting of "." (dot), "-" (minus) and " " (space)
 for *dits*, *dahs* and *pauses*. Every other character is ignored.
 The second parameter is the frequency (see :modbus:func:`beep <BrickletPiezoSpeaker.beep>`).
 
 For example: If you set the string "...---...", the piezo buzzer will beep
 nine times with the durations "short short short long long long short 
 short short".
 
 The maximum string size is 60.
 


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

.. modbus:function:: BrickletPiezoSpeaker.calibrate

 :functionid: 3
 :emptyrequest: empty payload

 :response calibration: bool

 The Piezo Speaker Bricklet can play 512 different tones. This function
 plays each tone and measures the exact frequency back. The result is a
 mapping between setting value and frequency. This mapping is stored
 in the EEPROM and loaded on startup.
 
 The Bricklet should come calibrated, you only need to call this
 function (once) every time you reflash the Bricklet plugin.
 
 Returns *true* after the calibration finishes.
 
.. modbus:function:: BrickletPiezoSpeaker.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|
 


.. _piezo_speaker_bricklet_modbus_callbacks:

Callbacks
^^^^^^^^^

.. modbus:function:: BrickletPiezoSpeaker.CALLBACK_BEEP_FINISHED

 :functionid: 4

 :emptyresponse: empty payload


 This callback is triggered if a beep set by :modbus:func:`beep <BrickletPiezoSpeaker.beep>` is finished
 
.. modbus:function:: BrickletPiezoSpeaker.CALLBACK_MORSE_CODE_FINISHED

 :functionid: 5

 :emptyresponse: empty payload


 This callback is triggered if the playback of the morse code set by
 :modbus:func:`morse_code <BrickletPiezoSpeaker.morse_code>` is finished.
 


