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> – Type: String
  • <function> – Type: 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> – Type: String
  • <callback> – Type: 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> – Type: String
  • <function> – Type: 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 sent and errors are silently ignored, because they cannot be detected.

tinkerforge dispatch rs232-bricklet <uid> <callback> [<option>..]
Parameters:
  • <uid> – Type: String
  • <callback> – Type: 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> – Type: Char Array, Length: 60
  • <length> – Type: Int, Range: [0 to 60]
Output:
  • written – Type: Int, Range: [0 to 60]

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 – Type: Char Array, Length: 60
  • length – Type: Int, Range: [0 to 60]

Returns the currently buffered message. The maximum length of message is 60. If the returned length is 0, no new data was 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> – Type: Int, Range: See symbols, Default: 11
  • <parity> – Type: Int, Range: See symbols, Default: 0
  • <stopbits> – Type: Int, Range: See symbols, Default: 1
  • <wordlength> – Type: Int, Range: See symbols, Default: 8
  • <hardware-flowcontrol> – Type: Int, Range: See symbols, Default: 0
  • <software-flowcontrol> – Type: Int, Range: See symbols, Default: 0
Output:
  • no output

Sets the configuration for the RS232 communication.

Hard-/Software flow control can either be on or off but not both simultaneously on.

The following symbols are available for this function:

For <baudrate>:

  • baudrate-300 = 0
  • baudrate-600 = 1
  • baudrate-1200 = 2
  • baudrate-2400 = 3
  • baudrate-4800 = 4
  • baudrate-9600 = 5
  • baudrate-14400 = 6
  • baudrate-19200 = 7
  • baudrate-28800 = 8
  • baudrate-38400 = 9
  • baudrate-57600 = 10
  • baudrate-115200 = 11
  • baudrate-230400 = 12

For <parity>:

  • parity-none = 0
  • parity-odd = 1
  • parity-even = 2
  • parity-forced-parity-1 = 3
  • parity-forced-parity-0 = 4

For <stopbits>:

  • stopbits-1 = 1
  • stopbits-2 = 2

For <wordlength>:

  • wordlength-5 = 5
  • wordlength-6 = 6
  • wordlength-7 = 7
  • wordlength-8 = 8

For <hardware-flowcontrol>:

  • hardware-flowcontrol-off = 0
  • hardware-flowcontrol-on = 1

For <software-flowcontrol>:

  • software-flowcontrol-off = 0
  • software-flowcontrol-on = 1
tinkerforge call rs232-bricklet <uid> get-configuration
Output:
  • baudrate – Type: Int, Range: See symbols, Default: 11
  • parity – Type: Int, Range: See symbols, Default: 0
  • stopbits – Type: Int, Range: See symbols, Default: 1
  • wordlength – Type: Int, Range: See symbols, Default: 8
  • hardware-flowcontrol – Type: Int, Range: See symbols, Default: 0
  • software-flowcontrol – Type: Int, Range: See symbols, Default: 0

Returns the configuration as set by set-configuration.

The following symbols are available for this function:

For baudrate:

  • baudrate-300 = 0
  • baudrate-600 = 1
  • baudrate-1200 = 2
  • baudrate-2400 = 3
  • baudrate-4800 = 4
  • baudrate-9600 = 5
  • baudrate-14400 = 6
  • baudrate-19200 = 7
  • baudrate-28800 = 8
  • baudrate-38400 = 9
  • baudrate-57600 = 10
  • baudrate-115200 = 11
  • baudrate-230400 = 12

For parity:

  • parity-none = 0
  • parity-odd = 1
  • parity-even = 2
  • parity-forced-parity-1 = 3
  • parity-forced-parity-0 = 4

For stopbits:

  • stopbits-1 = 1
  • stopbits-2 = 2

For wordlength:

  • wordlength-5 = 5
  • wordlength-6 = 6
  • wordlength-7 = 7
  • wordlength-8 = 8

For hardware-flowcontrol:

  • hardware-flowcontrol-off = 0
  • hardware-flowcontrol-on = 1

For software-flowcontrol:

  • software-flowcontrol-off = 0
  • software-flowcontrol-on = 1
tinkerforge call rs232-bricklet <uid> set-break-condition <break-time>
Parameters:
  • <break-time> – Type: Int, Unit: 1 ms, Range: [0 to 216 - 1]
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.

New in version 2.0.2 (Plugin).

tinkerforge call rs232-bricklet <uid> read-frame
Output:
  • message – Type: Char Array, Length: 60
  • length – Type: Int, Range: [0 to 60]

Returns up to one frame of bytes from the read buffer. The frame size is configured with set-frame-readable-callback-configuration. If the returned length is 0, no new data was available.

New in version 2.0.4 (Plugin).

Advanced Functions

tinkerforge call rs232-bricklet <uid> get-identity
Output:
  • uid – Type: String, Length: up to 8
  • connected-uid – Type: String, Length: up to 8
  • position – Type: Char, Range: [a to h, z]
  • hardware-version – Type: Int Array, Length: 3
    • 0: major – Type: Int, Range: [0 to 255]
    • 1: minor – Type: Int, Range: [0 to 255]
    • 2: revision – Type: Int, Range: [0 to 255]
  • firmware-version – Type: Int Array, Length: 3
    • 0: major – Type: Int, Range: [0 to 255]
    • 1: minor – Type: Int, Range: [0 to 255]
    • 2: revision – Type: Int, Range: [0 to 255]
  • device-identifier – Type: Int, Range: [0 to 216 - 1]

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', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an Isolator Bricklet is always at position 'z'.

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. This will disable the frame-readable 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 – Type: Bool, Default: false

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

tinkerforge call rs232-bricklet <uid> set-frame-readable-callback-configuration <frame-size>
Parameters:
  • <frame-size> – Type: Int, Unit: 1 B, Range: [0 to 100], Default: 0
Output:
  • no output

Configures the frame-readable callback. The frame size is the number of bytes, that have to be readable to trigger the callback. A frame size of 0 disables the callback. A frame size greater than 0 enables the callback and disables the read callback.

By default the callback is disabled.

New in version 2.0.4 (Plugin).

tinkerforge call rs232-bricklet <uid> get-frame-readable-callback-configuration
Output:
  • frame-size – Type: Int, Unit: 1 B, Range: [0 to 100], Default: 0

Returns the callback configuration as set by set-frame-readable-callback-configuration.

New in version 2.0.4 (Plugin).

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 – Type: Char Array, Length: 60
  • length – Type: Int, Range: [1 to 60]

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 – Type: Int, Range: See 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:

For error:

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

New in version 2.0.1 (Plugin).

tinkerforge dispatch rs232-bricklet <uid> frame-readable
Output:
  • frame-count – Type: Int, Range: [0 to 255]

This callback is called if at least one frame of data is readable. The frame size is configured with set-frame-readable-callback-configuration. The frame count parameter is the number of frames that can be read. This callback is triggered only once until read or read-frame is called. This means, that if you have configured a frame size of X bytes, you can read exactly X bytes using the read-frame function, every time the callback triggers without checking the frame count parameter.

New in version 2.0.4 (Plugin).