This is the description of the TCP/IP protocol for the CAN Bricklet. General information and technical specifications for the CAN Bricklet are summarized in its hardware description.
A general description of the TCP/IP protocol structure can be found here.
BrickletCAN.
write_frame
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Writes a data or remote frame to the write buffer to be transmitted over the CAN transceiver.
The Bricklet supports the standard 11-bit (CAN 2.0A) and the additional extended
18-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 additionally uses bit 11 to 28 from the identifier
parameter as extended 18-bit identifier.
For remote frames the data
parameter is ignored.
Returns true if the frame was successfully added to the write buffer. Returns false if the frame could not be added because write buffer is already full.
The write buffer 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_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 meanings are defined for the elements of this function:
For frame_type:
BrickletCAN.
read_frame
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Tries to read the next data or remote frame from the read buffer and return 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 buffer 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
.
For remote frames the data
return value always contains invalid data.
A configurable read filter can be used to define which frames should be
received by the CAN transceiver and put into the read buffer (see
set_read_filter
).
Instead of polling with this function, you can also use callbacks. See the
enable_frame_read_callback
function and the CALLBACK_FRAME_READ
callback.
The following meanings are defined for the elements of this function:
For frame_type:
BrickletCAN.
set_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Sets the configuration for the CAN bus communication.
The baud rate can be configured in steps between 10 and 1000 kbit/s.
The CAN transceiver has three different modes:
The write timeout has three different modes that define how a failed frame transmission should be handled:
The following meanings are defined for the elements of this function:
For baud_rate:
For transceiver_mode:
BrickletCAN.
get_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns the configuration as set by set_configuration
.
The following meanings are defined for the elements of this function:
For baud_rate:
For transceiver_mode:
BrickletCAN.
set_read_filter
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Set the read filter configuration. 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 five different modes that define if and how the mask and the two filters are applied:
The mask and filters are used as bit masks. Their usage depends on the mode:
The mask and filters are applied in this way: The mask is used to select the identifier and data bits that should be compared to the corresponding filter bits. All unselected bits are automatically accepted. All selected bits have to match one of the filters to be accepted. If all bits for the selected mode are accepted then the frame is accepted and is added to the read buffer.
Mask Bit | Filter Bit | Identifier/Data 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 with 0x7FF as mask and 0x123 as filter 1 and filter 2. 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.
The following meanings are defined for the elements of this function:
For mode:
BrickletCAN.
get_read_filter
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns the read filter as set by set_read_filter
.
The following meanings are defined for the elements of this function:
For mode:
BrickletCAN.
get_error_log
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns information about different kinds of errors.
The write and read error levels indicate the current level of checksum, acknowledgement, form, bit and stuffing errors during CAN bus write and read operations.
When the write error level exceeds 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 and read error levels are not available in read-only transceiver mode
(see set_configuration
) and are reset to 0 as a side effect of changing
the configuration or the read filter.
The write timeout, read register and buffer overflow counts represents the number of these errors:
set_configuration
).set_read_filter
) 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
function. Using the CALLBACK_FRAME_READ
callback ensures that the read buffer
can not overflow.BrickletCAN.
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.
BrickletCAN.
enable_frame_read_callback
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Enables the CALLBACK_FRAME_READ
callback.
By default the callback is disabled. Enabling this callback will disable the CALLBACK_FRAME_READABLE
callback.
BrickletCAN.
disable_frame_read_callback
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Disables the CALLBACK_FRAME_READ
callback.
By default the callback is disabled.
BrickletCAN.
is_frame_read_callback_enabled
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Returns true if the CALLBACK_FRAME_READ
callback is enabled, false otherwise.
BrickletCAN.
set_frame_readable_callback_configuration
¶Function ID: |
|
---|---|
Request: |
|
Response: |
|
Enables/disables the CALLBACK_FRAME_READABLE
callback.
By default the callback is disabled. Enabling this callback will disable the CALLBACK_FRAME_READ
callback.
New in version 2.0.1 (Plugin).
BrickletCAN.
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.1 (Plugin).
BrickletCAN.
CALLBACK_FRAME_READ
¶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
.
For remote frames the data
return value always contains invalid values.
A configurable read filter can be used to define which frames should be
received by the CAN transceiver at all (see set_read_filter
).
To enable this callback, use enable_frame_read_callback
.
The following meanings are defined for the elements of this function:
For frame_type:
BrickletCAN.
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
.
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
).
To enable this callback, use set_frame_readable_callback_configuration
.
New in version 2.0.1 (Plugin).