Shell - CAN Bricklet 2.0

This is the description of the Shell API bindings for the CAN Bricklet 2.0. General information and technical specifications for the CAN Bricklet 2.0 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
20
21
22
#!/bin/sh
# Connects to localhost:4223 by default, use --host and --port to change this

uid=XYZ # Change XYZ to the UID of your CAN Bricklet 2.0

# Configure transceiver for loopback mode
tinkerforge call can-v2-bricklet $uid set-transceiver-configuration 1000000 625 transceiver-mode-loopback

# Handle incoming frame read callbacks
tinkerforge dispatch can-v2-bricklet $uid frame-read &

# Enable frame read callback
tinkerforge call can-v2-bricklet $uid set-frame-read-callback-configuration true

# Write standard data frame with identifier 1742 and 3 bytes of data
tinkerforge call can-v2-bricklet $uid write-frame frame-type-standard-data 1742 42,23,17

echo "Press key to exit"; read dummy

tinkerforge call can-v2-bricklet $uid set-frame-read-callback-configuration false

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 can-v2-bricklet [<option>..] <uid> <function> [<argument>..]
Parameters:
  • <uid> – Type: String
  • <function> – Type: String

The call command is used to call a function of the CAN Bricklet 2.0. 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 CAN Bricklet 2.0 and exits
tinkerforge dispatch can-v2-bricklet [<option>..] <uid> <callback>
Parameters:
  • <uid> – Type: String
  • <callback> – Type: String

The dispatch command is used to dispatch a callback of the CAN Bricklet 2.0. 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 CAN Bricklet 2.0 and exits
tinkerforge call can-v2-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 can-v2-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 can-v2-bricklet <uid> write-frame <frame-type> <identifier> <data>
Parameters:
  • <frame-type> – Type: Int, Range: See symbols
  • <identifier> – Type: Int, Range: [0 to 230 - 1]
  • <data> – Type: Int Array, Length: variable, Range: [0 to 255]
Output:
  • success – Type: Bool

Writes a data or remote frame to the write queue to be transmitted over the CAN transceiver.

The Bricklet supports the standard 11-bit (CAN 2.0A) and the additional extended 29-bit (CAN 2.0B) identifiers. For standard frames the Bricklet uses bit 0 to 10 from the identifier parameter as standard 11-bit identifier. For extended frames the Bricklet uses bit 0 to 28 from the identifier parameter as extended 29-bit identifier.

The data parameter can be up to 15 bytes long. For data frames up to 8 bytes will be used as the actual data. The length (DLC) field in the data or remote frame will be set to the actual length of the data parameter. This allows to transmit data and remote frames with excess length. For remote frames only the length of the data parameter is used. The actual data bytes are ignored.

Returns true if the frame was successfully added to the write queue. Returns false if the frame could not be added because write queue is already full or because the write buffer or the write backlog are configured with a size of zero (see set-queue-configuration).

The write queue can overflow if frames are written to it at a higher rate than the Bricklet can transmitted them over the CAN transceiver. This may happen if the CAN transceiver is configured as read-only or is using a low baud rate (see set-transceiver-configuration). It can also happen if the CAN bus is congested and the frame cannot be transmitted because it constantly loses arbitration or because the CAN transceiver is currently disabled due to a high write error level (see get-error-log).

The following symbols are available for this function:

For <frame-type>:

  • frame-type-standard-data = 0
  • frame-type-standard-remote = 1
  • frame-type-extended-data = 2
  • frame-type-extended-remote = 3
tinkerforge call can-v2-bricklet <uid> read-frame
Output:
  • success – Type: Bool
  • frame-type – Type: Int, Range: See symbols
  • identifier – Type: Int, Range: [0 to 230 - 1]
  • data – Type: Int Array, Length: variable, Range: [0 to 255]

Tries to read the next data or remote frame from the read queue and returns it. If a frame was successfully read, then the success return value is set to true and the other return values contain the frame. If the read queue is empty and no frame could be read, then the success return value is set to false and the other return values contain invalid data.

The identifier return value follows the identifier format described for write-frame.

The data return value can be up to 15 bytes long. For data frames up to the first 8 bytes are the actual received data. All bytes after the 8th byte are always zero and only there to indicate the length of a data or remote frame with excess length. For remote frames the length of the data return value represents the requested length. The actual data bytes are always zero.

A configurable read filter can be used to define which frames should be received by the CAN transceiver and put into the read queue (see set-read-filter-configuration).

Instead of polling with this function, you can also use callbacks. See the set-frame-read-callback-configuration function and the frame-read callback.

The following symbols are available for this function:

For frame-type:

  • frame-type-standard-data = 0
  • frame-type-standard-remote = 1
  • frame-type-extended-data = 2
  • frame-type-extended-remote = 3
tinkerforge call can-v2-bricklet <uid> set-transceiver-configuration <baud-rate> <sample-point> <transceiver-mode>
Parameters:
  • <baud-rate> – Type: Int, Unit: 1 bit/s, Range: [10000 to 1000000], Default: 125000
  • <sample-point> – Type: Int, Unit: 1/10 %, Range: [500 to 900], Default: 625
  • <transceiver-mode> – Type: Int, Range: See symbols, Default: 0
Output:
  • no output

Sets the transceiver configuration for the CAN bus communication.

The CAN transceiver has three different modes:

  • Normal: Reads from and writes to the CAN bus and performs active bus error detection and acknowledgement.
  • Loopback: All reads and writes are performed internally. The transceiver is disconnected from the actual CAN bus.
  • Read-Only: Only reads from the CAN bus, but does neither active bus error detection nor acknowledgement. Only the receiving part of the transceiver is connected to the CAN bus.

The following symbols are available for this function:

For <transceiver-mode>:

  • transceiver-mode-normal = 0
  • transceiver-mode-loopback = 1
  • transceiver-mode-read-only = 2
tinkerforge call can-v2-bricklet <uid> get-transceiver-configuration
Output:
  • baud-rate – Type: Int, Unit: 1 bit/s, Range: [10000 to 1000000], Default: 125000
  • sample-point – Type: Int, Unit: 1/10 %, Range: [500 to 900], Default: 625
  • transceiver-mode – Type: Int, Range: See symbols, Default: 0

Returns the configuration as set by set-transceiver-configuration.

The following symbols are available for this function:

For transceiver-mode:

  • transceiver-mode-normal = 0
  • transceiver-mode-loopback = 1
  • transceiver-mode-read-only = 2

Advanced Functions

tinkerforge call can-v2-bricklet <uid> set-queue-configuration <write-buffer-size> <write-buffer-timeout> <write-backlog-size> <read-buffer-sizes> <read-backlog-size>
Parameters:
  • <write-buffer-size> – Type: Int, Range: [0 to 32], Default: 8
  • <write-buffer-timeout> – Type: Int, Range: [-1 to 231 - 1], Default: 0
  • <write-backlog-size> – Type: Int, Range: [0 to 768], Default: 383
  • <read-buffer-sizes> – Type: Int Array, Length: variable, Range: [-32 to -1, 1 to 32], Default: 16,-8
  • <read-backlog-size> – Type: Int, Range: [0 to 768], Default: 383
Output:
  • no output

Sets the write and read queue configuration.

The CAN transceiver has 32 buffers in total in hardware for transmitting and receiving frames. Additionally, the Bricklet has a backlog for 768 frames in total in software. The buffers and the backlog can be freely assigned to the write and read queues.

write-frame writes a frame into the write backlog. The Bricklet moves the frame from the backlog into a free write buffer. The CAN transceiver then transmits the frame from the write buffer to the CAN bus. If there are no write buffers (write_buffer_size is zero) or there is no write backlog (write_backlog_size is zero) then no frames can be transmitted and write-frame returns always false.

The CAN transceiver receives a frame from the CAN bus and stores it into a free read buffer. The Bricklet moves the frame from the read buffer into the read backlog. read-frame reads the frame from the read backlog and returns it. If there are no read buffers (read_buffer_sizes is empty) or there is no read backlog (read_backlog_size is zero) then no frames can be received and read-frame returns always false.

There can be multiple read buffers, because the CAN transceiver cannot receive data and remote frames into the same read buffer. A positive read buffer size represents a data frame read buffer and a negative read buffer size represents a remote frame read buffer. A read buffer size of zero is not allowed. By default the first read buffer is configured for data frames and the second read buffer is configured for remote frame. There can be up to 32 different read buffers, assuming that no write buffer is used. Each read buffer has its own filter configuration (see set-read-filter-configuration).

A valid queue configuration fulfills these conditions:

write_buffer_size + abs(read_buffer_size_0) + abs(read_buffer_size_1) + ... + abs(read_buffer_size_31) <= 32
write_backlog_size + read_backlog_size <= 768

The write buffer timeout has three different modes that define how a failed frame transmission should be handled:

  • Single-Shot (< 0): Only one transmission attempt will be made. If the transmission fails then the frame is discarded.
  • Infinite (= 0): Infinite transmission attempts will be made. The frame will never be discarded.
  • Milliseconds (> 0): A limited number of transmission attempts will be made. If the frame could not be transmitted successfully after the configured number of milliseconds then the frame is discarded.

The current content of the queues is lost when this function is called.

tinkerforge call can-v2-bricklet <uid> get-queue-configuration
Output:
  • write-buffer-size – Type: Int, Range: [0 to 32], Default: 8
  • write-buffer-timeout – Type: Int, Range: [-1 to 231 - 1], Default: 0
  • write-backlog-size – Type: Int, Range: [0 to 768], Default: 383
  • read-buffer-sizes – Type: Int Array, Length: variable, Range: [-32 to -1, 1 to 32], Default: 16,-8
  • read-backlog-size – Type: Int, Range: [0 to 768], Default: 383

Returns the queue configuration as set by set-queue-configuration.

tinkerforge call can-v2-bricklet <uid> set-read-filter-configuration <buffer-index> <filter-mode> <filter-mask> <filter-identifier>
Parameters:
  • <buffer-index> – Type: Int, Range: [0 to 31]
  • <filter-mode> – Type: Int, Range: See symbols, Default: 0
  • <filter-mask> – Type: Int, Range: [0 to 230 - 1]
  • <filter-identifier> – Type: Int, Range: [0 to 230 - 1]
Output:
  • no output

Set the read filter configuration for the given read buffer index. This can be used to define which frames should be received by the CAN transceiver and put into the read buffer.

The read filter has four different modes that define if and how the filter mask and the filter identifier are applied:

  • Accept-All: All frames are received.
  • Match-Standard-Only: Only standard frames with a matching identifier are received.
  • Match-Extended-Only: Only extended frames with a matching identifier are received.
  • Match-Standard-And-Extended: Standard and extended frames with a matching identifier are received.

The filter mask and filter identifier are used as bit masks. Their usage depends on the mode:

  • Accept-All: Mask and identifier are ignored.
  • Match-Standard-Only: Bit 0 to 10 (11 bits) of filter mask and filter identifier are used to match the 11-bit identifier of standard frames.
  • Match-Extended-Only: Bit 0 to 28 (29 bits) of filter mask and filter identifier are used to match the 29-bit identifier of extended frames.
  • Match-Standard-And-Extended: Bit 18 to 28 (11 bits) of filter mask and filter identifier are used to match the 11-bit identifier of standard frames, bit 0 to 17 (18 bits) are ignored in this case. Bit 0 to 28 (29 bits) of filter mask and filter identifier are used to match the 29-bit identifier of extended frames.

The filter mask and filter identifier are applied in this way: The filter mask is used to select the frame identifier bits that should be compared to the corresponding filter identifier bits. All unselected bits are automatically accepted. All selected bits have to match the filter identifier to be accepted. If all bits for the selected mode are accepted then the frame is accepted and is added to the read buffer.

Filter Mask Bit Filter Identifier Bit Frame Identifier Bit Result
0 X X Accept
1 0 0 Accept
1 0 1 Reject
1 1 0 Reject
1 1 1 Accept

For example, to receive standard frames with identifier 0x123 only, the mode can be set to Match-Standard-Only with 0x7FF as mask and 0x123 as identifier. The mask of 0x7FF selects all 11 identifier bits for matching so that the identifier has to be exactly 0x123 to be accepted.

To accept identifier 0x123 and identifier 0x456 at the same time, just set filter 2 to 0x456 and keep mask and filter 1 unchanged.

There can be up to 32 different read filters configured at the same time, because there can be up to 32 read buffer (see set-queue-configuration).

The default mode is accept-all for all read buffers.

The following symbols are available for this function:

For <filter-mode>:

  • filter-mode-accept-all = 0
  • filter-mode-match-standard-only = 1
  • filter-mode-match-extended-only = 2
  • filter-mode-match-standard-and-extended = 3
tinkerforge call can-v2-bricklet <uid> get-read-filter-configuration <buffer-index>
Parameters:
  • <buffer-index> – Type: Int, Range: [0 to 31]
Output:
  • filter-mode – Type: Int, Range: See symbols, Default: 0
  • filter-mask – Type: Int, Range: [0 to 230 - 1]
  • filter-identifier – Type: Int, Range: [0 to 230 - 1]

Returns the read filter configuration as set by set-read-filter-configuration.

The following symbols are available for this function:

For filter-mode:

  • filter-mode-accept-all = 0
  • filter-mode-match-standard-only = 1
  • filter-mode-match-extended-only = 2
  • filter-mode-match-standard-and-extended = 3
tinkerforge call can-v2-bricklet <uid> get-error-log
Output:
  • transceiver-state – Type: Int, Range: See symbols
  • transceiver-write-error-level – Type: Int, Range: [0 to 255]
  • transceiver-read-error-level – Type: Int, Range: [0 to 255]
  • transceiver-stuffing-error-count – Type: Int, Range: [0 to 232 - 1]
  • transceiver-format-error-count – Type: Int, Range: [0 to 232 - 1]
  • transceiver-ack-error-count – Type: Int, Range: [0 to 232 - 1]
  • transceiver-bit1-error-count – Type: Int, Range: [0 to 232 - 1]
  • transceiver-bit0-error-count – Type: Int, Range: [0 to 232 - 1]
  • transceiver-crc-error-count – Type: Int, Range: [0 to 232 - 1]
  • write-buffer-timeout-error-count – Type: Int, Range: [0 to 232 - 1]
  • read-buffer-overflow-error-count – Type: Int, Range: [0 to 232 - 1]
  • read-buffer-overflow-error-occurred – Type: Bool Array, Length: variable
  • read-backlog-overflow-error-count – Type: Int, Range: [0 to 232 - 1]

Returns information about different kinds of errors.

The write and read error levels indicate the current level of stuffing, form, acknowledgement, bit and checksum errors during CAN bus write and read operations. For each of this error kinds there is also an individual counter.

When the write error level extends 255 then the CAN transceiver gets disabled and no frames can be transmitted or received anymore. The CAN transceiver will automatically be activated again after the CAN bus is idle for a while.

The write buffer timeout, read buffer and backlog overflow counts represents the number of these errors:

  • A write buffer timeout occurs if a frame could not be transmitted before the configured write buffer timeout expired (see set-queue-configuration).
  • A read buffer overflow occurs if a read buffer of the CAN transceiver still contains the last received frame when the next frame arrives. In this case the last received frame is lost. This happens if the CAN transceiver receives more frames than the Bricklet can handle. Using the read filter (see set-read-filter-configuration) can help to reduce the amount of received frames. This count is not exact, but a lower bound, because the Bricklet might not able detect all overflows if they occur in rapid succession.
  • A read backlog overflow occurs if the read backlog of the Bricklet is already full when the next frame should be read from a read buffer of the CAN transceiver. In this case the frame in the read buffer is lost. This happens if the CAN transceiver receives more frames to be added to the read backlog than are removed from the read backlog using the read-frame function. Using the frame-read callback ensures that the read backlog can not overflow.

The read buffer overflow counter counts the overflows of all configured read buffers. Which read buffer exactly suffered from an overflow can be figured out from the read buffer overflow occurrence list (read_buffer_overflow_error_occurred). Reading the error log clears the occurence list.

The following symbols are available for this function:

For transceiver-state:

  • transceiver-state-active = 0
  • transceiver-state-passive = 1
  • transceiver-state-disabled = 2
tinkerforge call can-v2-bricklet <uid> set-communication-led-config <config>
Parameters:
  • <config> – Type: Int, Range: See symbols, Default: 3
Output:
  • no output

Sets the communication LED configuration. By default the LED shows CAN-Bus traffic, it flickers once for every 40 transmitted or received frames.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is off.

The following symbols are available for this function:

For <config>:

  • communication-led-config-off = 0
  • communication-led-config-on = 1
  • communication-led-config-show-heartbeat = 2
  • communication-led-config-show-communication = 3
tinkerforge call can-v2-bricklet <uid> get-communication-led-config
Output:
  • config – Type: Int, Range: See symbols, Default: 3

Returns the configuration as set by set-communication-led-config

The following symbols are available for this function:

For config:

  • communication-led-config-off = 0
  • communication-led-config-on = 1
  • communication-led-config-show-heartbeat = 2
  • communication-led-config-show-communication = 3
tinkerforge call can-v2-bricklet <uid> set-error-led-config <config>
Parameters:
  • <config> – Type: Int, Range: See symbols, Default: 3
Output:
  • no output

Sets the error LED configuration.

By default (show-transceiver-state) the error LED turns on if the CAN transceiver is passive or disabled state (see get-error-log). If the CAN transceiver is in active state the LED turns off.

If the LED is configured as show-error then the error LED turns on if any error occurs. If you call this function with the show-error option again, the LED will turn off until the next error occurs.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is off.

The following symbols are available for this function:

For <config>:

  • error-led-config-off = 0
  • error-led-config-on = 1
  • error-led-config-show-heartbeat = 2
  • error-led-config-show-transceiver-state = 3
  • error-led-config-show-error = 4
tinkerforge call can-v2-bricklet <uid> get-error-led-config
Output:
  • config – Type: Int, Range: See symbols, Default: 3

Returns the configuration as set by set-error-led-config.

The following symbols are available for this function:

For config:

  • error-led-config-off = 0
  • error-led-config-on = 1
  • error-led-config-show-heartbeat = 2
  • error-led-config-show-transceiver-state = 3
  • error-led-config-show-error = 4
tinkerforge call can-v2-bricklet <uid> get-spitfp-error-count
Output:
  • error-count-ack-checksum – Type: Int, Range: [0 to 232 - 1]
  • error-count-message-checksum – Type: Int, Range: [0 to 232 - 1]
  • error-count-frame – Type: Int, Range: [0 to 232 - 1]
  • error-count-overflow – Type: Int, Range: [0 to 232 - 1]

Returns the error count for the communication between Brick and Bricklet.

The errors are divided into

  • ACK checksum errors,
  • message checksum errors,
  • framing errors and
  • overflow errors.

The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.

tinkerforge call can-v2-bricklet <uid> set-status-led-config <config>
Parameters:
  • <config> – Type: Int, Range: See symbols, Default: 3
Output:
  • no output

Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.

The following symbols are available for this function:

For <config>:

  • status-led-config-off = 0
  • status-led-config-on = 1
  • status-led-config-show-heartbeat = 2
  • status-led-config-show-status = 3
tinkerforge call can-v2-bricklet <uid> get-status-led-config
Output:
  • config – Type: Int, Range: See symbols, Default: 3

Returns the configuration as set by set-status-led-config

The following symbols are available for this function:

For config:

  • status-led-config-off = 0
  • status-led-config-on = 1
  • status-led-config-show-heartbeat = 2
  • status-led-config-show-status = 3
tinkerforge call can-v2-bricklet <uid> get-chip-temperature
Output:
  • temperature – Type: Int, Unit: 1 °C, Range: [-215 to 215 - 1]

Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!

The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.

tinkerforge call can-v2-bricklet <uid> reset
Output:
  • no output

Calling this function will reset the Bricklet. All configurations will be lost.

After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!

tinkerforge call can-v2-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 can-v2-bricklet <uid> set-frame-read-callback-configuration <enabled>
Parameters:
  • <enabled> – Type: Bool, Default: false
Output:
  • no output

Enables and disables the frame-read callback.

By default the callback is disabled. Enabling this callback will disable the frame-readable callback.

tinkerforge call can-v2-bricklet <uid> get-frame-read-callback-configuration
Output:
  • enabled – Type: Bool, Default: false

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

tinkerforge call can-v2-bricklet <uid> set-frame-readable-callback-configuration <enabled>
Parameters:
  • <enabled> – Type: Bool, Default: false
Output:
  • no output

Enables and disables the frame-readable callback.

By default the callback is disabled. Enabling this callback will disable the frame-read callback.

New in version 2.0.3 (Plugin).

tinkerforge call can-v2-bricklet <uid> get-frame-readable-callback-configuration
Output:
  • enabled – Type: Bool, Default: false

Returns true if the frame-readable callback is enabled, false otherwise.

New in version 2.0.3 (Plugin).

tinkerforge call can-v2-bricklet <uid> set-error-occurred-callback-configuration <enabled>
Parameters:
  • <enabled> – Type: Bool, Default: false
Output:
  • no output

Enables and disables the error-occurred callback.

By default the callback is disabled.

New in version 2.0.3 (Plugin).

tinkerforge call can-v2-bricklet <uid> get-error-occurred-callback-configuration
Output:
  • enabled – Type: Bool, Default: false

Returns true if the error-occurred callback is enabled, false otherwise.

New in version 2.0.3 (Plugin).

Callbacks

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

tinkerforge dispatch can-v2-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 can-v2-bricklet <uid> frame-read
Output:
  • frame-type – Type: Int, Range: See symbols
  • identifier – Type: Int, Range: [0 to 230 - 1]
  • data – Type: Int Array, Length: variable, Range: [0 to 255]

This callback is triggered if a data or remote frame was received by the CAN transceiver.

The identifier return value follows the identifier format described for write-frame.

For details on the data return value see read-frame.

A configurable read filter can be used to define which frames should be received by the CAN transceiver and put into the read queue (see set-read-filter-configuration).

To enable this callback, use set-frame-read-callback-configuration.

Note

If reconstructing the value fails, the callback is triggered with None for data.

The following symbols are available for this function:

For frame-type:

  • frame-type-standard-data = 0
  • frame-type-standard-remote = 1
  • frame-type-extended-data = 2
  • frame-type-extended-remote = 3
tinkerforge dispatch can-v2-bricklet <uid> frame-readable
Output:
  • no output

This callback is triggered if a data or remote frame was received by the CAN transceiver. The received frame can be read with read-frame. If additional frames are received, but read-frame was not called yet, the callback will not trigger again.

A configurable read filter can be used to define which frames should be received by the CAN transceiver and put into the read queue (see set-read-filter-configuration).

To enable this callback, use set-frame-readable-callback-configuration.

New in version 2.0.3 (Plugin).

tinkerforge dispatch can-v2-bricklet <uid> error-occurred
Output:
  • no output

This callback is triggered if any error occurred while writing, reading or transmitting CAN frames.

The callback is only triggered once until get-error-log is called. That function will return details abount the error(s) occurred.

To enable this callback, use set-error-occurred-callback-configuration.

New in version 2.0.3 (Plugin).

Internal Functions

Internal functions are used for maintenance tasks such as flashing a new firmware of changing the UID of a Bricklet. These task should be performed using Brick Viewer instead of using the internal functions directly.

tinkerforge call can-v2-bricklet <uid> set-bootloader-mode <mode>
Parameters:
  • <mode> – Type: Int, Range: See symbols
Output:
  • status – Type: Int, Range: See symbols

Sets the bootloader mode and returns the status after the requested mode change was instigated.

You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

The following symbols are available for this function:

For <mode>:

  • bootloader-mode-bootloader = 0
  • bootloader-mode-firmware = 1
  • bootloader-mode-bootloader-wait-for-reboot = 2
  • bootloader-mode-firmware-wait-for-reboot = 3
  • bootloader-mode-firmware-wait-for-erase-and-reboot = 4

For status:

  • bootloader-status-ok = 0
  • bootloader-status-invalid-mode = 1
  • bootloader-status-no-change = 2
  • bootloader-status-entry-function-not-present = 3
  • bootloader-status-device-identifier-incorrect = 4
  • bootloader-status-crc-mismatch = 5
tinkerforge call can-v2-bricklet <uid> get-bootloader-mode
Output:
  • mode – Type: Int, Range: See symbols

Returns the current bootloader mode, see set-bootloader-mode.

The following symbols are available for this function:

For mode:

  • bootloader-mode-bootloader = 0
  • bootloader-mode-firmware = 1
  • bootloader-mode-bootloader-wait-for-reboot = 2
  • bootloader-mode-firmware-wait-for-reboot = 3
  • bootloader-mode-firmware-wait-for-erase-and-reboot = 4
tinkerforge call can-v2-bricklet <uid> set-write-firmware-pointer <pointer>
Parameters:
  • <pointer> – Type: Int, Unit: 1 B, Range: [0 to 232 - 1]
Output:
  • no output

Sets the firmware pointer for write-firmware. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

tinkerforge call can-v2-bricklet <uid> write-firmware <data>
Parameters:
  • <data> – Type: Int Array, Length: 64, Range: [0 to 255]
Output:
  • status – Type: Int, Range: [0 to 255]

Writes 64 Bytes of firmware at the position as written by set-write-firmware-pointer before. The firmware is written to flash every 4 chunks.

You can only write firmware in bootloader mode.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

tinkerforge call can-v2-bricklet <uid> write-uid <uid>
Parameters:
  • <uid> – Type: Int, Range: [0 to 232 - 1]
Output:
  • no output

Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.

We recommend that you use Brick Viewer to change the UID.

tinkerforge call can-v2-bricklet <uid> read-uid
Output:
  • uid – Type: Int, Range: [0 to 232 - 1]

Returns the current UID as an integer. Encode as Base58 to get the usual string version.