This is the description of the TCP/IP protocol for the CAN Bricklet 2.0. General information and technical specifications for the CAN Bricklet 2.0 are summarized in its hardware description.
A general description of the TCP/IP protocol structure can be found here.
BrickletCANV2.
write_frame_low_level
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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_low_level
).
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_low_level
).
The following meanings are defined for the elements of this function:
For frame_type:
BrickletCANV2.
read_frame_low_level
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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_low_level
.
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 CALLBACK_FRAME_READ_LOW_LEVEL
callback.
The following meanings are defined for the elements of this function:
For frame_type:
BrickletCANV2.
set_transceiver_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Sets the transceiver configuration for the CAN bus communication.
The CAN transceiver has three different modes:
The following meanings are defined for the elements of this function:
For transceiver_mode:
BrickletCANV2.
get_transceiver_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns the configuration as set by set_transceiver_configuration
.
The following meanings are defined for the elements of this function:
For transceiver_mode:
BrickletCANV2.
set_queue_configuration_low_level
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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_low_level
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_low_level
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_low_level
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_low_level
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:
The current content of the queues is lost when this function is called.
BrickletCANV2.
get_queue_configuration_low_level
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns the queue configuration as set by set_queue_configuration_low_level
.
BrickletCANV2.
set_read_filter_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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:
The filter mask and filter identifier are used as bit masks. Their usage depends on the mode:
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_low_level
).
The default mode is accept-all for all read buffers.
The following meanings are defined for the elements of this function:
For filter_mode:
BrickletCANV2.
get_read_filter_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns the read filter configuration as set by set_read_filter_configuration
.
The following meanings are defined for the elements of this function:
For filter_mode:
BrickletCANV2.
get_error_log_low_level
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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:
set_queue_configuration_low_level
).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.read_frame_low_level
function. Using the CALLBACK_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 meanings are defined for the elements of this function:
For transceiver_state:
BrickletCANV2.
set_communication_led_config
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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 meanings are defined for the elements of this function:
For config:
BrickletCANV2.
get_communication_led_config
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns the configuration as set by set_communication_led_config
The following meanings are defined for the elements of this function:
For config:
BrickletCANV2.
set_error_led_config
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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_low_level
). 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 meanings are defined for the elements of this function:
For config:
BrickletCANV2.
get_error_led_config
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns the configuration as set by set_error_led_config
.
The following meanings are defined for the elements of this function:
For config:
BrickletCANV2.
get_spitfp_error_count
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns the error count for the communication between Brick and Bricklet.
The errors are divided into
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.
BrickletCANV2.
set_status_led_config
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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 meanings are defined for the elements of this function:
For config:
BrickletCANV2.
get_status_led_config
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns the configuration as set by set_status_led_config
The following meanings are defined for the elements of this function:
For config:
BrickletCANV2.
get_chip_temperature
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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.
BrickletCANV2.
reset
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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!
BrickletCANV2.
get_identity
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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.
BrickletCANV2.
set_frame_read_callback_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Enables and disables the CALLBACK_FRAME_READ_LOW_LEVEL
callback.
By default the callback is disabled. Enabling this callback will disable the CALLBACK_FRAME_READABLE
callback.
BrickletCANV2.
get_frame_read_callback_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns true if the CALLBACK_FRAME_READ_LOW_LEVEL
callback is enabled, false otherwise.
BrickletCANV2.
set_frame_readable_callback_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Enables and disables the CALLBACK_FRAME_READABLE
callback.
By default the callback is disabled. Enabling this callback will disable the CALLBACK_FRAME_READ_LOW_LEVEL
callback.
New in version 2.0.3 (Plugin).
BrickletCANV2.
get_frame_readable_callback_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns true if the CALLBACK_FRAME_READABLE
callback is enabled, false otherwise.
New in version 2.0.3 (Plugin).
BrickletCANV2.
set_error_occurred_callback_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Enables and disables the CALLBACK_ERROR_OCCURRED
callback.
By default the callback is disabled.
New in version 2.0.3 (Plugin).
BrickletCANV2.
get_error_occurred_callback_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns true if the CALLBACK_ERROR_OCCURRED
callback is enabled, false otherwise.
New in version 2.0.3 (Plugin).
BrickletCANV2.
CALLBACK_FRAME_READ_LOW_LEVEL
¶Function ID: |
|
---|---|
Response: |
|
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_low_level
.
For details on the data
return value see read_frame_low_level
.
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
.
The following meanings are defined for the elements of this function:
For frame_type:
BrickletCANV2.
CALLBACK_FRAME_READABLE
¶Function ID: |
|
---|---|
Response: |
|
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_low_level
.
If additional frames are received, but read_frame_low_level
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).
BrickletCANV2.
CALLBACK_ERROR_OCCURRED
¶Function ID: |
|
---|---|
Response: |
|
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_low_level
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 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.
BrickletCANV2.
set_bootloader_mode
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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 meanings are defined for the elements of this function:
For mode:
For status:
BrickletCANV2.
get_bootloader_mode
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns the current bootloader mode, see set_bootloader_mode
.
The following meanings are defined for the elements of this function:
For mode:
BrickletCANV2.
set_write_firmware_pointer
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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.
BrickletCANV2.
write_firmware
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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.
BrickletCANV2.
write_uid
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
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.
BrickletCANV2.
read_uid
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns the current UID as an integer. Encode as Base58 to get the usual string version.