Shell - RS232 Bricklet

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).

Loopback

Download (example-loopback.sh)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
# Connects to localhost:4223 by default, use --host and --port to change this

# For this example connect the RX1 and TX pin to receive the send message

uid=XYZ # Change XYZ to the UID of your RS232 Bricklet

# Handle incoming read callbacks
tinkerforge dispatch rs232-bricklet $uid read &

# Enable read callback
tinkerforge call rs232-bricklet $uid enable-read-callback

# Write "test" string
tinkerforge call rs232-bricklet $uid write t,e,s,t,.. 4

echo "Press key to exit"; read dummy

kill -- -$$ # Stop callback dispatch in background

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,..57x..,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 set-configuration for configuration possibilities regarding baudrate, parity and so on.

tinkerforge call rs232-bricklet <uid> read
Output:
  • message -- char,char,..57x..,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-read-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 either be on or off but not both simultaneously on.

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:

  • baudrate-300 = 0, for <baudrate>
  • baudrate-600 = 1, for <baudrate>
  • baudrate-1200 = 2, for <baudrate>
  • baudrate-2400 = 3, for <baudrate>
  • baudrate-4800 = 4, for <baudrate>
  • baudrate-9600 = 5, for <baudrate>
  • baudrate-14400 = 6, for <baudrate>
  • baudrate-19200 = 7, for <baudrate>
  • baudrate-28800 = 8, for <baudrate>
  • baudrate-38400 = 9, for <baudrate>
  • baudrate-57600 = 10, for <baudrate>
  • baudrate-115200 = 11, for <baudrate>
  • baudrate-230400 = 12, for <baudrate>
  • parity-none = 0, for <parity>
  • parity-odd = 1, for <parity>
  • parity-even = 2, for <parity>
  • parity-forced-parity-1 = 3, for <parity>
  • parity-forced-parity-0 = 4, for <parity>
  • stopbits-1 = 1, for <stopbits>
  • stopbits-2 = 2, for <stopbits>
  • wordlength-5 = 5, for <wordlength>
  • wordlength-6 = 6, for <wordlength>
  • wordlength-7 = 7, for <wordlength>
  • wordlength-8 = 8, for <wordlength>
  • hardware-flowcontrol-off = 0, for <hardware-flowcontrol>
  • hardware-flowcontrol-on = 1, for <hardware-flowcontrol>
  • software-flowcontrol-off = 0, for <software-flowcontrol>
  • 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:

  • baudrate-300 = 0, for baudrate
  • baudrate-600 = 1, for baudrate
  • baudrate-1200 = 2, for baudrate
  • baudrate-2400 = 3, for baudrate
  • baudrate-4800 = 4, for baudrate
  • baudrate-9600 = 5, for baudrate
  • baudrate-14400 = 6, for baudrate
  • baudrate-19200 = 7, for baudrate
  • baudrate-28800 = 8, for baudrate
  • baudrate-38400 = 9, for baudrate
  • baudrate-57600 = 10, for baudrate
  • baudrate-115200 = 11, for baudrate
  • baudrate-230400 = 12, for baudrate
  • parity-none = 0, for parity
  • parity-odd = 1, for parity
  • parity-even = 2, for parity
  • parity-forced-parity-1 = 3, for parity
  • parity-forced-parity-0 = 4, for parity
  • stopbits-1 = 1, for stopbits
  • stopbits-2 = 2, for stopbits
  • wordlength-5 = 5, for wordlength
  • wordlength-6 = 6, for wordlength
  • wordlength-7 = 7, for wordlength
  • wordlength-8 = 8, for wordlength
  • hardware-flowcontrol-off = 0, for hardware-flowcontrol
  • hardware-flowcontrol-on = 1, for hardware-flowcontrol
  • software-flowcontrol-off = 0, for software-flowcontrol
  • software-flowcontrol-on = 1, for software-flowcontrol
tinkerforge call rs232-bricklet <uid> set-break-condition <break-time>
Parameters:
  • <break-time> -- int
Output:

no output

Sets a break condition (the TX output is forced to a logic 0 state). The parameter sets the hold-time of the break condition (in ms).

New in version 2.0.2 (Plugin).

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-read-callback
Output:no output

Enables the read callback.

By default the callback is disabled.

tinkerforge call rs232-bricklet <uid> disable-read-callback
Output:no output

Disables the read callback.

By default the callback is disabled.

tinkerforge call rs232-bricklet <uid> is-read-callback-enabled
Output:
  • enabled -- 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
Output:
  • message -- char,char,..57x..,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-read-callback.

tinkerforge dispatch rs232-bricklet <uid> error
Output:
  • error -- int (has symbols)

This callback is called if an error occurs. Possible errors are overrun, parity or framing error.

The following symbols are available for this function:

  • error-overrun = 1, for error
  • error-parity = 2, for error
  • error-framing = 4, for error

New in version 2.0.1 (Plugin).