..
 #############################################################
 # This file was automatically generated on 2015-05-19.      #
 #                                                           #
 # 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       #
 #############################################################

:orphan:
:breadcrumbs: <a href="../../index.html">Home</a> / <a href="../../index.html#software-shell">Software</a> / Shell - RS232 Bricklet

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

.. _rs232_bricklet_shell:

Shell - RS232 Bricklet
======================

.. note::
 This Bricklet is currently in the prototype stage and the software/hardware
 as well as the documentation is in an incomplete state.


This is the description of the :ref:`Shell API bindings <api_bindings_shell>` for the :ref:`RS232 Bricklet <rs232_bricklet>`. General information and technical
specifications for the RS232 Bricklet are summarized in its :ref:`hardware description
<rs232_bricklet_description>`.

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

.. _rs232_bricklet_shell_examples:


Examples
--------

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

Loopback
^^^^^^^^

`Download (example-loopback.sh) <https://github.com/Tinkerforge/rs232-bricklet/raw/master/software/examples/shell/example-loopback.sh>`__

.. literalinclude:: RS232_Bricklet_Shell_example-loopback.sh
 :language: bash
 :linenos:
 :tab-width: 4

.. _rs232_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 Nrs232-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 RS232 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 RS232 Bricklet and exits


.. sh:function:: X Stinkerforge Pdispatch Nrs232-bricklet A[<option>..] L<uid> L<callback>

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

 The ``dispatch`` command is used to dispatch a callback of the RS232 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 RS232 Bricklet and exits


.. sh:function:: X Stinkerforge Scall Prs232-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 Prs232-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 rs232-bricklet <uid> write <message> <length> 

 :param <message>: char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char
 :param <length>: int

 :returns written: int

 Writes a string of up to 60 characters to the RS232 interface. The string
 can be binary data, ASCII or similar is not necessary.
 
 The length of the string has to be given as an additional parameter.
 
 The return value is the number of bytes that could be written.
 
 See :func:`SetConfigurations` for configuration possibilities
 regarding baudrate, parity and so on.
 
.. sh:function:: tinkerforge call rs232-bricklet <uid> read  


 :returns message: char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char
 :returns length: int

 Returns the currently buffered message. The maximum length
 of message is 60. If the length is given as 0, there was no
 new data available.
 
 Instead of polling with this function, you can also use
 callbacks. See :sh:func:`enable-callback <rs232-bricklet enable-callback>` and :sh:func:`read-callback <rs232-bricklet read-callback>`.
 
.. sh:function:: tinkerforge call rs232-bricklet <uid> set-configuration <baudrate> <parity> <stopbits> <wordlength> <hardware-flowcontrol> <software-flowcontrol> 

 :param <baudrate>: int (has symbols)
 :param <parity>: int (has symbols)
 :param <stopbits>: int (has symbols)
 :param <wordlength>: int (has symbols)
 :param <hardware-flowcontrol>: int (has symbols)
 :param <software-flowcontrol>: int (has symbols)

 :noreturn: no output

 Sets the configuration for the RS232 communication. Available options:
 
 * Baudrate between 300 and 230400 baud.
 * Parity of none, odd, even or forced parity.
 * Stopbits can be 1 or 2.
 * Word length of 5 to 8.
 * Hard-/Software flow control can each be on or off.
 
 The default is: 115200 baud, parity none, 1 stop bit, word length 8, hard-/software flow control off.
 
 The following symbols are available for this function:
 
 * ``300`` = 0, for <baudrate>
 * ``600`` = 1, for <baudrate>
 * ``1200`` = 2, for <baudrate>
 * ``2400`` = 3, for <baudrate>
 * ``4800`` = 4, for <baudrate>
 * ``9600`` = 5, for <baudrate>
 * ``14400`` = 6, for <baudrate>
 * ``28800`` = 7, for <baudrate>
 * ``38400`` = 8, for <baudrate>
 * ``57600`` = 9, for <baudrate>
 * ``115200`` = 10, for <baudrate>
 * ``230400`` = 11, for <baudrate>
 * ``none`` = 0, for <parity>
 * ``odd`` = 1, for <parity>
 * ``even`` = 2, for <parity>
 * ``forced-parity-1`` = 3, for <parity>
 * ``forced-parity-0`` = 4, for <parity>
 * ``1`` = 1, for <stopbits>
 * ``2`` = 2, for <stopbits>
 * ``5`` = 5, for <wordlength>
 * ``6`` = 6, for <wordlength>
 * ``7`` = 7, for <wordlength>
 * ``8`` = 8, for <wordlength>
 * ``off`` = 0, for <hardware-flowcontrol>
 * ``on`` = 1, for <hardware-flowcontrol>
 * ``off`` = 0, for <software-flowcontrol>
 * ``on`` = 1, for <software-flowcontrol>
 
.. sh:function:: tinkerforge call rs232-bricklet <uid> get-configuration  


 :returns baudrate: int (has symbols)
 :returns parity: int (has symbols)
 :returns stopbits: int (has symbols)
 :returns wordlength: int (has symbols)
 :returns hardware-flowcontrol: int (has symbols)
 :returns software-flowcontrol: int (has symbols)

 Returns the configuration as set by :sh:func:`set-configuration <rs232-bricklet set-configuration>`.
 
 The following symbols are available for this function:
 
 * ``300`` = 0, for baudrate
 * ``600`` = 1, for baudrate
 * ``1200`` = 2, for baudrate
 * ``2400`` = 3, for baudrate
 * ``4800`` = 4, for baudrate
 * ``9600`` = 5, for baudrate
 * ``14400`` = 6, for baudrate
 * ``28800`` = 7, for baudrate
 * ``38400`` = 8, for baudrate
 * ``57600`` = 9, for baudrate
 * ``115200`` = 10, for baudrate
 * ``230400`` = 11, for baudrate
 * ``none`` = 0, for parity
 * ``odd`` = 1, for parity
 * ``even`` = 2, for parity
 * ``forced-parity-1`` = 3, for parity
 * ``forced-parity-0`` = 4, for parity
 * ``1`` = 1, for stopbits
 * ``2`` = 2, for stopbits
 * ``5`` = 5, for wordlength
 * ``6`` = 6, for wordlength
 * ``7`` = 7, for wordlength
 * ``8`` = 8, for wordlength
 * ``off`` = 0, for hardware-flowcontrol
 * ``on`` = 1, for hardware-flowcontrol
 * ``off`` = 0, for software-flowcontrol
 * ``on`` = 1, for software-flowcontrol
 


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

.. sh:function:: tinkerforge call rs232-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|
 


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



.. sh:function:: tinkerforge call rs232-bricklet <uid> enable-callback  


 :noreturn: no output

 Enables the :sh:func:`read-callback <rs232-bricklet read-callback>`.
 
 By default the callback is disabled.
 
.. sh:function:: tinkerforge call rs232-bricklet <uid> disable-callback  


 :noreturn: no output

 Disables the :sh:func:`read-callback <rs232-bricklet read-callback>`.
 
 By default the callback is disabled.
 
.. sh:function:: tinkerforge call rs232-bricklet <uid> is-callback-enabled  


 :returns enable: bool

 Returns *true* if the :sh:func:`read-callback <rs232-bricklet read-callback>` is enabled,
 *false* otherwise.
 


.. _rs232_bricklet_shell_callbacks:

Callbacks
^^^^^^^^^

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

.. code-block:: bash

    tinkerforge dispatch rs232-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 rs232-bricklet <uid> read-callback

 :returns message: char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char,char
 :returns length: int


 This callback is called if new data is available. The message has
 a maximum size of 60 characters. The actual length of the message
 is given in addition.
 
 To enable this callback, use :sh:func:`enable-callback <rs232-bricklet enable-callback>`.
 


