Shell - RS232 Bricklet – Tinkerforge

- Getting Started
  - Primer
  - Tutorials
  - FAQ
- Hardware
  - Bricks
  - Bricklets
  - Master Extensions
  - Power Supplies
  - Accessories
  - Timeline
- Software
  - Brick Daemon (brickd)
  - Brick Viewer (brickv)
  - API Bindings
  - Firmwares and Plugins
  - Device Identifier
  - Source Code and Bug Tracking
  - Programming Interface
- Starter Kits
  - Weather Station
  - Hardware Hacking
  - Server Room Monitoring
  - Blinkenlights
  - Internet of Things
  - Camera Slider
- Embedded Boards
  - Raspberry Pi
- Specifications
  - Technical Data
  - TCP/IP Protocol
  - Modbus Protocol
  - Wireshark Dissector

# 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 Shell API bindings for the RS232 Bricklet. General information and technical specifications for the RS232 Bricklet are summarized in its hardware description.

An installation guide for the Shell API bindings is part of their general description.

## Examples

The example code below is Public Domain (CC0 1.0).

## 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 here. The specific command structure is shown below.

tinkerforge `call` `rs232-bricklet` [<option>..] <uid> <function> [<argument>..]

  Parameters:

  - <uid> -- string
  - <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

tinkerforge `dispatch` `rs232-bricklet` [<option>..] <uid> <callback>

  Parameters:

  - <uid> -- string
  - <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

tinkerforge call `rs232-bricklet` <uid> `<function>` [<option>..] [<argument>..]

  Parameters:

  - <uid> -- string
  - <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 output formatting 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.

tinkerforge dispatch `rs232-bricklet` <uid> `<callback>` [<option>..]

  Parameters:

  - <uid> -- string
  - <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 output formatting for details)

### Basic Functions

tinkerforge call `rs232-bricklet` <uid> `write` <message> <length>

  Parameters:

  - <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
  - <length> -- int

  Output:

  - 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 `SetConfigurations()` for configuration possibilities regarding baudrate, parity and so on.

tinkerforge call `rs232-bricklet` <uid> `read`

  Output:

  - 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
  - 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 `enable-callback` and `read-callback`.

tinkerforge call `rs232-bricklet` <uid> `set-configuration` <baudrate> <parity> <stopbits> <wordlength> <hardware-flowcontrol> <software-flowcontrol>

  Parameters:

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

  Output: | 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>

tinkerforge call `rs232-bricklet` <uid> `get-configuration`

  Output:

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

  Returns the configuration as set by `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

tinkerforge call `rs232-bricklet` <uid> `get-identity`

  Output:

  - uid -- string
  - connected-uid -- string
  - position -- char
  - hardware-version -- int,int,int
  - firmware-version -- int,int,int
  - 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 here.

### Callback Configuration Functions

tinkerforge call `rs232-bricklet` <uid> `enable-callback`

  Output: | no output

  Enables the `read-callback`.

  By default the callback is disabled.

tinkerforge call `rs232-bricklet` <uid> `disable-callback`

  Output: | no output

  Disables the `read-callback`.

  By default the callback is disabled.

tinkerforge call `rs232-bricklet` <uid> `is-callback-enabled`

  Output:

  - enable -- bool

  Returns true if the `read-callback` is enabled, false otherwise.

### Callbacks

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

    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.

tinkerforge dispatch `rs232-bricklet` <uid> `read-callback`

  Output:

  - 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
  - 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 `enable-callback`.

The content of this page is licensed under Creative Commons Attribution 3.0 Unported License.