C/C++ for Microcontrollers - CAN Bricklet 2.0

This is the description of the C/C++ for Microcontrollers 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 C/C++ for Microcontrollers API bindings is part of their general description.

Examples

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

Loopback

Download (example_loopback.c)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// This example is not self-contained.
// It requires usage of the example driver specific to your platform.
// See the HAL documentation.

#include "src/bindings/hal_common.h"
#include "src/bindings/bricklet_can_v2.h"

void check(int rc, const char *msg);
void example_setup(TF_HAL *hal);
void example_loop(TF_HAL *hal);

static bool frame_readable = false;
// Callback function for frame readable callback
static void frame_readable_handler(TF_CANV2 *device, void *user_data) {
    (void)device; (void)user_data; // avoid unused parameter warning

    frame_readable = true;
}

static TF_CANV2 can;

void example_setup(TF_HAL *hal) {
    // Create device object
    check(tf_can_v2_create(&can, NULL, hal), "create device object");

    // Configure transceiver for loopback mode
    check(tf_can_v2_set_transceiver_configuration(&can, 1000000, 625,
                                                  TF_CAN_V2_TRANSCEIVER_MODE_LOOPBACK), "call set_transceiver_configuration");
    // Register frame readable callback to function frame_readable_handler
    tf_can_v2_register_frame_readable_callback(&can,
                                               frame_readable_handler,
                                               NULL);
    // Enable frame readable callback
    check(tf_can_v2_set_frame_readable_callback_configuration(&can,
                                                              true), "call set_frame_readable_callback_configuration");
    // Write standard data frame with identifier 1742 and 3 bytes of data
    uint8_t data[3] = {42, 23, 17};
    bool success;
    check(tf_can_v2_write_frame(&can, TF_CAN_V2_FRAME_TYPE_STANDARD_DATA, 1742,
                                data, 3, &success), "call write_frame");
    if(!success)
        tf_hal_printf("Failed to write frame.\n");
}

void example_loop(TF_HAL *hal) {
    // Poll for callbacks
    tf_hal_callback_tick(hal, 0);

    if(!frame_readable)
        return;

    frame_readable = false;

    bool success;
    uint8_t frame_type;
    uint32_t identifier;
    uint8_t data[15];
    uint8_t data_length;

    // Frame readable will only trigger once, even if there are multiple frames readable, so we use a loop to
    // read frames until there are none left.
    check(tf_can_v2_read_frame(&can, &success, &frame_type, &identifier, data, &data_length), "read frame");
    while (success) {
        if(frame_type == TF_CAN_V2_FRAME_TYPE_STANDARD_DATA) {
            tf_hal_printf("Frame Type: Standard Data\n");
        } else if(frame_type == TF_CAN_V2_FRAME_TYPE_STANDARD_REMOTE) {
            tf_hal_printf("Frame Type: Standard Remote\n");
        } else if(frame_type == TF_CAN_V2_FRAME_TYPE_EXTENDED_DATA) {
            tf_hal_printf("Frame Type: Extended Data\n");
        } else if(frame_type == TF_CAN_V2_FRAME_TYPE_EXTENDED_REMOTE) {
            tf_hal_printf("Frame Type: Extended Remote\n");
        }

        tf_hal_printf("Identifier: %I32u\n", identifier);
        tf_hal_printf("Data (Length: %I8d):", data_length);

        uint8_t i;
        for (i = 0; i < data_length && i < 8; ++i) {
            tf_hal_printf(" %I8d", data[i]);
        }

        tf_hal_printf("\n");
        check(tf_can_v2_read_frame(&can, &success, &frame_type, &identifier, data, &data_length), "read frame");
    }
}

API

Most functions of the C/C++ bindings for microcontrollers return an error code (e_code).

Possible error codes are:

  • TF_E_OK = 0
  • TF_E_TIMEOUT = -1
  • TF_E_INVALID_PARAMETER = -2
  • TF_E_NOT_SUPPORTED = -3
  • TF_E_UNKNOWN_ERROR_CODE = -4
  • TF_E_STREAM_OUT_OF_SYNC = -5
  • TF_E_INVALID_CHAR_IN_UID = -6
  • TF_E_UID_TOO_LONG = -7
  • TF_E_UID_OVERFLOW = -8
  • TF_E_TOO_MANY_DEVICES = -9
  • TF_E_DEVICE_NOT_FOUND = -10
  • TF_E_WRONG_DEVICE_TYPE = -11
  • TF_E_LOCKED = -12
  • TF_E_PORT_NOT_FOUND = -13

(as defined in errors.h) as well as the errors returned from the hardware abstraction layer (HAL) that is used.

Use :cpp:func`tf_hal_strerror` (defined in the HAL's header file) to get an error string for an error code.

Data returned from the device, when a getter is called, is handled via output parameters. These parameters are labeled with the ret_ prefix. The bindings will not write to an output parameter if NULL or nullptr is passed. This can be used to ignore outputs that you are not interested in.

None of the functions listed below are thread-safe. See the API bindings description for details.

Basic Functions

int tf_can_v2_create(TF_CANV2 *can_v2, const char *uid_or_port_name, TF_HAL *hal)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • uid – Type: const char *
  • hal – Type: TF_HAL *
Returns:
  • e_code – Type: int

Creates the device object can_v2 with the optional unique device ID or port name uid_or_port_name and adds it to the HAL hal:

TF_CANV2 can_v2;
tf_can_v2_create(&can_v2, NULL, &hal);

Normally uid_or_port_name can stay NULL. For more details about this see section UID or Port Name.

int tf_can_v2_destroy(TF_CANV2 *can_v2)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Returns:
  • e_code – Type: int

Removes the device object can_v2 from its HAL and destroys it. The device object cannot be used anymore afterwards.

int tf_can_v2_write_frame(TF_CANV2 *can_v2, uint8_t frame_type, uint32_t identifier, const uint8_t *data, uint8_t data_length, bool *ret_success)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • frame_type – Type: uint8_t, Range: See constants
  • identifier – Type: uint32_t, Range: [0 to 230 - 1]
  • data – Type: const uint8_t *, Range: [0 to 255]
  • data_length – Type: uint8_t
Output Parameters:
  • ret_success – Type: bool
Returns:
  • e_code – Type: int

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 tf_can_v2_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 tf_can_v2_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 tf_can_v2_get_error_log()).

The following constants are available for this function:

For frame_type:

  • TF_CAN_V2_FRAME_TYPE_STANDARD_DATA = 0
  • TF_CAN_V2_FRAME_TYPE_STANDARD_REMOTE = 1
  • TF_CAN_V2_FRAME_TYPE_EXTENDED_DATA = 2
  • TF_CAN_V2_FRAME_TYPE_EXTENDED_REMOTE = 3
int tf_can_v2_read_frame(TF_CANV2 *can_v2, bool *ret_success, uint8_t *ret_frame_type, uint32_t *ret_identifier, uint8_t *ret_data, uint8_t *ret_data_length)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_success – Type: bool
  • ret_frame_type – Type: uint8_t, Range: See constants
  • ret_identifier – Type: uint32_t, Range: [0 to 230 - 1]
  • ret_data – Type: uint8_t *, Range: [0 to 255]
  • ret_data_length – Type: uint8_t
Returns:
  • e_code – Type: int

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 tf_can_v2_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 tf_can_v2_set_read_filter_configuration()).

Instead of polling with this function, you can also use callbacks. See the tf_can_v2_set_frame_read_callback_configuration() function and the Frame Read Low Level callback.

The following constants are available for this function:

For ret_frame_type:

  • TF_CAN_V2_FRAME_TYPE_STANDARD_DATA = 0
  • TF_CAN_V2_FRAME_TYPE_STANDARD_REMOTE = 1
  • TF_CAN_V2_FRAME_TYPE_EXTENDED_DATA = 2
  • TF_CAN_V2_FRAME_TYPE_EXTENDED_REMOTE = 3
int tf_can_v2_set_transceiver_configuration(TF_CANV2 *can_v2, uint32_t baud_rate, uint16_t sample_point, uint8_t transceiver_mode)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • baud_rate – Type: uint32_t, Unit: 1 bit/s, Range: [10000 to 1000000], Default: 125000
  • sample_point – Type: uint16_t, Unit: 1/10 %, Range: [500 to 900], Default: 625
  • transceiver_mode – Type: uint8_t, Range: See constants, Default: 0
Returns:
  • e_code – Type: int

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 constants are available for this function:

For transceiver_mode:

  • TF_CAN_V2_TRANSCEIVER_MODE_NORMAL = 0
  • TF_CAN_V2_TRANSCEIVER_MODE_LOOPBACK = 1
  • TF_CAN_V2_TRANSCEIVER_MODE_READ_ONLY = 2
int tf_can_v2_get_transceiver_configuration(TF_CANV2 *can_v2, uint32_t *ret_baud_rate, uint16_t *ret_sample_point, uint8_t *ret_transceiver_mode)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_baud_rate – Type: uint32_t, Unit: 1 bit/s, Range: [10000 to 1000000], Default: 125000
  • ret_sample_point – Type: uint16_t, Unit: 1/10 %, Range: [500 to 900], Default: 625
  • ret_transceiver_mode – Type: uint8_t, Range: See constants, Default: 0
Returns:
  • e_code – Type: int

Returns the configuration as set by tf_can_v2_set_transceiver_configuration().

The following constants are available for this function:

For ret_transceiver_mode:

  • TF_CAN_V2_TRANSCEIVER_MODE_NORMAL = 0
  • TF_CAN_V2_TRANSCEIVER_MODE_LOOPBACK = 1
  • TF_CAN_V2_TRANSCEIVER_MODE_READ_ONLY = 2

Advanced Functions

int tf_can_v2_set_queue_configuration(TF_CANV2 *can_v2, uint8_t write_buffer_size, int32_t write_buffer_timeout, uint16_t write_backlog_size, const int8_t *read_buffer_sizes, uint8_t read_buffer_sizes_length, uint16_t read_backlog_size)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • write_buffer_size – Type: uint8_t, Range: [0 to 32], Default: 8
  • write_buffer_timeout – Type: int32_t, Range: [-1 to 231 - 1], Default: 0
  • write_backlog_size – Type: uint16_t, Range: [0 to 768], Default: 383
  • read_buffer_sizes – Type: const int8_t *, Range: [-32 to -1, 1 to 32], Default: {16, -8}
  • read_buffer_sizes_length – Type: uint8_t
  • read_backlog_size – Type: uint16_t, Range: [0 to 768], Default: 383
Returns:
  • e_code – Type: int

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.

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

int tf_can_v2_get_queue_configuration(TF_CANV2 *can_v2, uint8_t *ret_write_buffer_size, int32_t *ret_write_buffer_timeout, uint16_t *ret_write_backlog_size, int8_t *ret_read_buffer_sizes, uint8_t *ret_read_buffer_sizes_length, uint16_t *ret_read_backlog_size)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_write_buffer_size – Type: uint8_t, Range: [0 to 32], Default: 8
  • ret_write_buffer_timeout – Type: int32_t, Range: [-1 to 231 - 1], Default: 0
  • ret_write_backlog_size – Type: uint16_t, Range: [0 to 768], Default: 383
  • ret_read_buffer_sizes – Type: int8_t *, Range: [-32 to -1, 1 to 32], Default: {16, -8}
  • ret_read_buffer_sizes_length – Type: uint8_t
  • ret_read_backlog_size – Type: uint16_t, Range: [0 to 768], Default: 383
Returns:
  • e_code – Type: int

Returns the queue configuration as set by tf_can_v2_set_queue_configuration().

int tf_can_v2_set_read_filter_configuration(TF_CANV2 *can_v2, uint8_t buffer_index, uint8_t filter_mode, uint32_t filter_mask, uint32_t filter_identifier)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • buffer_index – Type: uint8_t, Range: [0 to 31]
  • filter_mode – Type: uint8_t, Range: See constants, Default: 0
  • filter_mask – Type: uint32_t, Range: [0 to 230 - 1]
  • filter_identifier – Type: uint32_t, Range: [0 to 230 - 1]
Returns:
  • e_code – Type: int

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

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

The following constants are available for this function:

For filter_mode:

  • TF_CAN_V2_FILTER_MODE_ACCEPT_ALL = 0
  • TF_CAN_V2_FILTER_MODE_MATCH_STANDARD_ONLY = 1
  • TF_CAN_V2_FILTER_MODE_MATCH_EXTENDED_ONLY = 2
  • TF_CAN_V2_FILTER_MODE_MATCH_STANDARD_AND_EXTENDED = 3
int tf_can_v2_get_read_filter_configuration(TF_CANV2 *can_v2, uint8_t buffer_index, uint8_t *ret_filter_mode, uint32_t *ret_filter_mask, uint32_t *ret_filter_identifier)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • buffer_index – Type: uint8_t, Range: [0 to 31]
Output Parameters:
  • ret_filter_mode – Type: uint8_t, Range: See constants, Default: 0
  • ret_filter_mask – Type: uint32_t, Range: [0 to 230 - 1]
  • ret_filter_identifier – Type: uint32_t, Range: [0 to 230 - 1]
Returns:
  • e_code – Type: int

Returns the read filter configuration as set by tf_can_v2_set_read_filter_configuration().

The following constants are available for this function:

For ret_filter_mode:

  • TF_CAN_V2_FILTER_MODE_ACCEPT_ALL = 0
  • TF_CAN_V2_FILTER_MODE_MATCH_STANDARD_ONLY = 1
  • TF_CAN_V2_FILTER_MODE_MATCH_EXTENDED_ONLY = 2
  • TF_CAN_V2_FILTER_MODE_MATCH_STANDARD_AND_EXTENDED = 3
int tf_can_v2_get_error_log(TF_CANV2 *can_v2, uint8_t *ret_transceiver_state, uint8_t *ret_transceiver_write_error_level, uint8_t *ret_transceiver_read_error_level, uint32_t *ret_transceiver_stuffing_error_count, uint32_t *ret_transceiver_format_error_count, uint32_t *ret_transceiver_ack_error_count, uint32_t *ret_transceiver_bit1_error_count, uint32_t *ret_transceiver_bit0_error_count, uint32_t *ret_transceiver_crc_error_count, uint32_t *ret_write_buffer_timeout_error_count, uint32_t *ret_read_buffer_overflow_error_count, bool *ret_read_buffer_overflow_error_occurred, uint8_t *ret_read_buffer_overflow_error_occurred_length, uint32_t *ret_read_backlog_overflow_error_count)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_transceiver_state – Type: uint8_t, Range: See constants
  • ret_transceiver_write_error_level – Type: uint8_t, Range: [0 to 255]
  • ret_transceiver_read_error_level – Type: uint8_t, Range: [0 to 255]
  • ret_transceiver_stuffing_error_count – Type: uint32_t, Range: [0 to 232 - 1]
  • ret_transceiver_format_error_count – Type: uint32_t, Range: [0 to 232 - 1]
  • ret_transceiver_ack_error_count – Type: uint32_t, Range: [0 to 232 - 1]
  • ret_transceiver_bit1_error_count – Type: uint32_t, Range: [0 to 232 - 1]
  • ret_transceiver_bit0_error_count – Type: uint32_t, Range: [0 to 232 - 1]
  • ret_transceiver_crc_error_count – Type: uint32_t, Range: [0 to 232 - 1]
  • ret_write_buffer_timeout_error_count – Type: uint32_t, Range: [0 to 232 - 1]
  • ret_read_buffer_overflow_error_count – Type: uint32_t, Range: [0 to 232 - 1]
  • ret_read_buffer_overflow_error_occurred – Type: bool *
  • ret_read_buffer_overflow_error_occurred_length – Type: uint8_t
  • ret_read_backlog_overflow_error_count – Type: uint32_t, Range: [0 to 232 - 1]
Returns:
  • e_code – Type: int

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 tf_can_v2_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 tf_can_v2_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 tf_can_v2_read_frame() function. Using the Frame Read Low Level 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 constants are available for this function:

For ret_transceiver_state:

  • TF_CAN_V2_TRANSCEIVER_STATE_ACTIVE = 0
  • TF_CAN_V2_TRANSCEIVER_STATE_PASSIVE = 1
  • TF_CAN_V2_TRANSCEIVER_STATE_DISABLED = 2
int tf_can_v2_set_communication_led_config(TF_CANV2 *can_v2, uint8_t config)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • config – Type: uint8_t, Range: See constants, Default: 3
Returns:
  • e_code – Type: int

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 constants are available for this function:

For config:

  • TF_CAN_V2_COMMUNICATION_LED_CONFIG_OFF = 0
  • TF_CAN_V2_COMMUNICATION_LED_CONFIG_ON = 1
  • TF_CAN_V2_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT = 2
  • TF_CAN_V2_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION = 3
int tf_can_v2_get_communication_led_config(TF_CANV2 *can_v2, uint8_t *ret_config)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_config – Type: uint8_t, Range: See constants, Default: 3
Returns:
  • e_code – Type: int

Returns the configuration as set by tf_can_v2_set_communication_led_config()

The following constants are available for this function:

For ret_config:

  • TF_CAN_V2_COMMUNICATION_LED_CONFIG_OFF = 0
  • TF_CAN_V2_COMMUNICATION_LED_CONFIG_ON = 1
  • TF_CAN_V2_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT = 2
  • TF_CAN_V2_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION = 3
int tf_can_v2_set_error_led_config(TF_CANV2 *can_v2, uint8_t config)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • config – Type: uint8_t, Range: See constants, Default: 3
Returns:
  • e_code – Type: int

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 tf_can_v2_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 constants are available for this function:

For config:

  • TF_CAN_V2_ERROR_LED_CONFIG_OFF = 0
  • TF_CAN_V2_ERROR_LED_CONFIG_ON = 1
  • TF_CAN_V2_ERROR_LED_CONFIG_SHOW_HEARTBEAT = 2
  • TF_CAN_V2_ERROR_LED_CONFIG_SHOW_TRANSCEIVER_STATE = 3
  • TF_CAN_V2_ERROR_LED_CONFIG_SHOW_ERROR = 4
int tf_can_v2_get_error_led_config(TF_CANV2 *can_v2, uint8_t *ret_config)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_config – Type: uint8_t, Range: See constants, Default: 3
Returns:
  • e_code – Type: int

Returns the configuration as set by tf_can_v2_set_error_led_config().

The following constants are available for this function:

For ret_config:

  • TF_CAN_V2_ERROR_LED_CONFIG_OFF = 0
  • TF_CAN_V2_ERROR_LED_CONFIG_ON = 1
  • TF_CAN_V2_ERROR_LED_CONFIG_SHOW_HEARTBEAT = 2
  • TF_CAN_V2_ERROR_LED_CONFIG_SHOW_TRANSCEIVER_STATE = 3
  • TF_CAN_V2_ERROR_LED_CONFIG_SHOW_ERROR = 4
int tf_can_v2_get_spitfp_error_count(TF_CANV2 *can_v2, uint32_t *ret_error_count_ack_checksum, uint32_t *ret_error_count_message_checksum, uint32_t *ret_error_count_frame, uint32_t *ret_error_count_overflow)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_error_count_ack_checksum – Type: uint32_t, Range: [0 to 232 - 1]
  • ret_error_count_message_checksum – Type: uint32_t, Range: [0 to 232 - 1]
  • ret_error_count_frame – Type: uint32_t, Range: [0 to 232 - 1]
  • ret_error_count_overflow – Type: uint32_t, Range: [0 to 232 - 1]
Returns:
  • e_code – Type: int

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.

int tf_can_v2_set_status_led_config(TF_CANV2 *can_v2, uint8_t config)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • config – Type: uint8_t, Range: See constants, Default: 3
Returns:
  • e_code – Type: int

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 constants are available for this function:

For config:

  • TF_CAN_V2_STATUS_LED_CONFIG_OFF = 0
  • TF_CAN_V2_STATUS_LED_CONFIG_ON = 1
  • TF_CAN_V2_STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2
  • TF_CAN_V2_STATUS_LED_CONFIG_SHOW_STATUS = 3
int tf_can_v2_get_status_led_config(TF_CANV2 *can_v2, uint8_t *ret_config)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_config – Type: uint8_t, Range: See constants, Default: 3
Returns:
  • e_code – Type: int

Returns the configuration as set by tf_can_v2_set_status_led_config()

The following constants are available for this function:

For ret_config:

  • TF_CAN_V2_STATUS_LED_CONFIG_OFF = 0
  • TF_CAN_V2_STATUS_LED_CONFIG_ON = 1
  • TF_CAN_V2_STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2
  • TF_CAN_V2_STATUS_LED_CONFIG_SHOW_STATUS = 3
int tf_can_v2_get_chip_temperature(TF_CANV2 *can_v2, int16_t *ret_temperature)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_temperature – Type: int16_t, Unit: 1 °C, Range: [-215 to 215 - 1]
Returns:
  • e_code – Type: int

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.

int tf_can_v2_reset(TF_CANV2 *can_v2)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Returns:
  • e_code – Type: int

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!

int tf_can_v2_get_identity(TF_CANV2 *can_v2, char ret_uid[8], char ret_connected_uid[8], char *ret_position, uint8_t ret_hardware_version[3], uint8_t ret_firmware_version[3], uint16_t *ret_device_identifier)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_uid – Type: char[8]
  • ret_connected_uid – Type: char[8]
  • ret_position – Type: char, Range: ['a' to 'h', 'z']
  • ret_hardware_version – Type: uint8_t[3]
    • 0: major – Type: uint8_t, Range: [0 to 255]
    • 1: minor – Type: uint8_t, Range: [0 to 255]
    • 2: revision – Type: uint8_t, Range: [0 to 255]
  • ret_firmware_version – Type: uint8_t[3]
    • 0: major – Type: uint8_t, Range: [0 to 255]
    • 1: minor – Type: uint8_t, Range: [0 to 255]
    • 2: revision – Type: uint8_t, Range: [0 to 255]
  • ret_device_identifier – Type: uint16_t, Range: [0 to 216 - 1]
Returns:
  • e_code – Type: int

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. There is also a constant for the device identifier of this Bricklet.

Callback Configuration Functions

int tf_can_v2_set_frame_read_callback_configuration(TF_CANV2 *can_v2, bool enabled)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • enabled – Type: bool, Default: false
Returns:
  • e_code – Type: int

Enables and disables the Frame Read Low Level callback.

By default the callback is disabled. Enabling this callback will disable the Frame Readable callback.

int tf_can_v2_get_frame_read_callback_configuration(TF_CANV2 *can_v2, bool *ret_enabled)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_enabled – Type: bool, Default: false
Returns:
  • e_code – Type: int

Returns true if the Frame Read Low Level callback is enabled, false otherwise.

int tf_can_v2_set_frame_readable_callback_configuration(TF_CANV2 *can_v2, bool enabled)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • enabled – Type: bool, Default: false
Returns:
  • e_code – Type: int

Enables and disables the Frame Readable callback.

By default the callback is disabled. Enabling this callback will disable the Frame Read Low Level callback.

New in version 2.0.3 (Plugin).

int tf_can_v2_get_frame_readable_callback_configuration(TF_CANV2 *can_v2, bool *ret_enabled)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_enabled – Type: bool, Default: false
Returns:
  • e_code – Type: int

Returns true if the Frame Readable callback is enabled, false otherwise.

New in version 2.0.3 (Plugin).

int tf_can_v2_set_error_occurred_callback_configuration(TF_CANV2 *can_v2, bool enabled)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • enabled – Type: bool, Default: false
Returns:
  • e_code – Type: int

Enables and disables the Error Occurred callback.

By default the callback is disabled.

New in version 2.0.3 (Plugin).

int tf_can_v2_get_error_occurred_callback_configuration(TF_CANV2 *can_v2, bool *ret_enabled)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_enabled – Type: bool, Default: false
Returns:
  • e_code – Type: int

Returns true if the Error Occurred callback is enabled, false otherwise.

New in version 2.0.3 (Plugin).

Callbacks

Callbacks can be registered to receive time critical or recurring data from the device. The registration is done with the corresponding tf_can_v2_register_*_callback function. The user_data passed to the registration function as well as the device that triggered the callback are passed to the registered callback handler.

Only one handler can be registered to a callback at the same time. To deregister a callback, call the tf_can_v2_register_*_callback function with NULL as handler.

Note

Using callbacks for recurring events is preferred compared to using getters. Polling for a callback requires writing one byte only. See here Optimizing Performance.

Warning

Calling bindings function from inside a callback handler is not allowed. See here Thread safety.

int tf_can_v2_register_frame_read_low_level_callback(TF_CANV2 *can_v2, TF_CANV2_FrameReadLowLevelHandler handler, void *user_data)
void handler(TF_CANV2 *can_v2, uint8_t frame_type, uint32_t identifier, uint8_t data_length, uint8_t data_data[15], void *user_data)
Callback Parameters:
  • can_v2 – Type: TF_CANV2 *
  • frame_type – Type: uint8_t, Range: See constants
  • identifier – Type: uint32_t, Range: [0 to 230 - 1]
  • data_length – Type: uint8_t, Range: [0 to 15]
  • data_data – Type: uint8_t[15], Range: [0 to 255]
  • user_data – Type: void *

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

For details on the data return value see tf_can_v2_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 tf_can_v2_set_read_filter_configuration()).

To enable this callback, use tf_can_v2_set_frame_read_callback_configuration().

The following constants are available for this function:

For frame_type:

  • TF_CAN_V2_FRAME_TYPE_STANDARD_DATA = 0
  • TF_CAN_V2_FRAME_TYPE_STANDARD_REMOTE = 1
  • TF_CAN_V2_FRAME_TYPE_EXTENDED_DATA = 2
  • TF_CAN_V2_FRAME_TYPE_EXTENDED_REMOTE = 3
int tf_can_v2_register_frame_readable_callback(TF_CANV2 *can_v2, TF_CANV2_FrameReadableHandler handler, void *user_data)
void handler(TF_CANV2 *can_v2, void *user_data)
Callback Parameters:
  • can_v2 – Type: TF_CANV2 *
  • user_data – Type: void *

This callback is triggered if a data or remote frame was received by the CAN transceiver. The received frame can be read with tf_can_v2_read_frame(). If additional frames are received, but tf_can_v2_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 tf_can_v2_set_read_filter_configuration()).

To enable this callback, use tf_can_v2_set_frame_readable_callback_configuration().

New in version 2.0.3 (Plugin).

int tf_can_v2_register_error_occurred_callback(TF_CANV2 *can_v2, TF_CANV2_ErrorOccurredHandler handler, void *user_data)
void handler(TF_CANV2 *can_v2, void *user_data)
Callback Parameters:
  • can_v2 – Type: TF_CANV2 *
  • user_data – Type: void *

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

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

To enable this callback, use tf_can_v2_set_error_occurred_callback_configuration().

New in version 2.0.3 (Plugin).

Virtual Functions

Virtual functions don't communicate with the device itself, but operate only on the API bindings device object.

int tf_can_v2_get_response_expected(TF_CANV2 *can_v2, uint8_t function_id, bool *ret_response_expected)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • function_id – Type: uint8_t, Range: See constants
Output Parameters:
  • ret_response_expected – Type: bool
Returns:
  • e_code – Type: int

Returns the response expected flag for the function specified by the function ID parameter. It is true if the function is expected to send a response, false otherwise.

For getter functions this is enabled by default and cannot be disabled, because those functions will always send a response. For callback configuration functions it is enabled by default too, but can be disabled by tf_can_v2_set_response_expected(). For setter functions it is disabled by default and can be enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

The following constants are available for this function:

For function_id:

  • TF_CAN_V2_FUNCTION_SET_FRAME_READ_CALLBACK_CONFIGURATION = 3
  • TF_CAN_V2_FUNCTION_SET_TRANSCEIVER_CONFIGURATION = 5
  • TF_CAN_V2_FUNCTION_SET_QUEUE_CONFIGURATION = 7
  • TF_CAN_V2_FUNCTION_SET_READ_FILTER_CONFIGURATION = 9
  • TF_CAN_V2_FUNCTION_SET_COMMUNICATION_LED_CONFIG = 12
  • TF_CAN_V2_FUNCTION_SET_ERROR_LED_CONFIG = 14
  • TF_CAN_V2_FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION = 17
  • TF_CAN_V2_FUNCTION_SET_ERROR_OCCURRED_CALLBACK_CONFIGURATION = 20
  • TF_CAN_V2_FUNCTION_SET_WRITE_FIRMWARE_POINTER = 237
  • TF_CAN_V2_FUNCTION_SET_STATUS_LED_CONFIG = 239
  • TF_CAN_V2_FUNCTION_RESET = 243
  • TF_CAN_V2_FUNCTION_WRITE_UID = 248
int tf_can_v2_set_response_expected(TF_CANV2 *can_v2, uint8_t function_id, bool response_expected)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • function_id – Type: uint8_t, Range: See constants
  • response_expected – Type: bool
Returns:
  • e_code – Type: int

Changes the response expected flag of the function specified by the function ID parameter. This flag can only be changed for setter (default value: false) and callback configuration functions (default value: true). For getter functions it is always enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

The following constants are available for this function:

For function_id:

  • TF_CAN_V2_FUNCTION_SET_FRAME_READ_CALLBACK_CONFIGURATION = 3
  • TF_CAN_V2_FUNCTION_SET_TRANSCEIVER_CONFIGURATION = 5
  • TF_CAN_V2_FUNCTION_SET_QUEUE_CONFIGURATION = 7
  • TF_CAN_V2_FUNCTION_SET_READ_FILTER_CONFIGURATION = 9
  • TF_CAN_V2_FUNCTION_SET_COMMUNICATION_LED_CONFIG = 12
  • TF_CAN_V2_FUNCTION_SET_ERROR_LED_CONFIG = 14
  • TF_CAN_V2_FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION = 17
  • TF_CAN_V2_FUNCTION_SET_ERROR_OCCURRED_CALLBACK_CONFIGURATION = 20
  • TF_CAN_V2_FUNCTION_SET_WRITE_FIRMWARE_POINTER = 237
  • TF_CAN_V2_FUNCTION_SET_STATUS_LED_CONFIG = 239
  • TF_CAN_V2_FUNCTION_RESET = 243
  • TF_CAN_V2_FUNCTION_WRITE_UID = 248
int tf_can_v2_set_response_expected_all(TF_CANV2 *can_v2, bool response_expected)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • response_expected – Type: bool
Returns:
  • e_code – Type: int

Changes the response expected flag for all setter and callback configuration functions of this device at once.

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.

int tf_can_v2_set_bootloader_mode(TF_CANV2 *can_v2, uint8_t mode, uint8_t *ret_status)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • mode – Type: uint8_t, Range: See constants
Output Parameters:
  • ret_status – Type: uint8_t, Range: See constants
Returns:
  • e_code – Type: int

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 constants are available for this function:

For mode:

  • TF_CAN_V2_BOOTLOADER_MODE_BOOTLOADER = 0
  • TF_CAN_V2_BOOTLOADER_MODE_FIRMWARE = 1
  • TF_CAN_V2_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT = 2
  • TF_CAN_V2_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT = 3
  • TF_CAN_V2_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT = 4

For ret_status:

  • TF_CAN_V2_BOOTLOADER_STATUS_OK = 0
  • TF_CAN_V2_BOOTLOADER_STATUS_INVALID_MODE = 1
  • TF_CAN_V2_BOOTLOADER_STATUS_NO_CHANGE = 2
  • TF_CAN_V2_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT = 3
  • TF_CAN_V2_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT = 4
  • TF_CAN_V2_BOOTLOADER_STATUS_CRC_MISMATCH = 5
int tf_can_v2_get_bootloader_mode(TF_CANV2 *can_v2, uint8_t *ret_mode)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_mode – Type: uint8_t, Range: See constants
Returns:
  • e_code – Type: int

Returns the current bootloader mode, see tf_can_v2_set_bootloader_mode().

The following constants are available for this function:

For ret_mode:

  • TF_CAN_V2_BOOTLOADER_MODE_BOOTLOADER = 0
  • TF_CAN_V2_BOOTLOADER_MODE_FIRMWARE = 1
  • TF_CAN_V2_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT = 2
  • TF_CAN_V2_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT = 3
  • TF_CAN_V2_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT = 4
int tf_can_v2_set_write_firmware_pointer(TF_CANV2 *can_v2, uint32_t pointer)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • pointer – Type: uint32_t, Unit: 1 B, Range: [0 to 232 - 1]
Returns:
  • e_code – Type: int

Sets the firmware pointer for tf_can_v2_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.

int tf_can_v2_write_firmware(TF_CANV2 *can_v2, const uint8_t data[64], uint8_t *ret_status)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • data – Type: const uint8_t[64], Range: [0 to 255]
Output Parameters:
  • ret_status – Type: uint8_t, Range: [0 to 255]
Returns:
  • e_code – Type: int

Writes 64 Bytes of firmware at the position as written by tf_can_v2_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.

int tf_can_v2_write_uid(TF_CANV2 *can_v2, uint32_t uid)
Parameters:
  • can_v2 – Type: TF_CANV2 *
  • uid – Type: uint32_t, Range: [0 to 232 - 1]
Returns:
  • e_code – Type: int

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.

int tf_can_v2_read_uid(TF_CANV2 *can_v2, uint32_t *ret_uid)
Parameters:
  • can_v2 – Type: TF_CANV2 *
Output Parameters:
  • ret_uid – Type: uint32_t, Range: [0 to 232 - 1]
Returns:
  • e_code – Type: int

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

Constants

TF_CAN_V2_DEVICE_IDENTIFIER

This constant is used to identify a CAN Bricklet 2.0.

The functions tf_can_v2_get_identity() and tf_hal_get_device_info() have a device_identifier output parameter to specify the Brick's or Bricklet's type.

TF_CAN_V2_DEVICE_DISPLAY_NAME

This constant represents the human readable name of a CAN Bricklet 2.0.