Class: Tinkerforge::BrickletCANV2
- Defined in:
- lib/tinkerforge/bricklet_can_v2.rb
Overview
Communicates with CAN bus devices
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
2107
- DEVICE_DISPLAY_NAME =
:nodoc:
'CAN Bricklet 2.0'
- CALLBACK_FRAME_READ_LOW_LEVEL =
See CALLBACK_FRAME_READ
16
- CALLBACK_FRAME_READABLE =
This callback is triggered if a data or remote frame was received by the CAN transceiver. The received frame can be read with BrickletCANV2#read_frame. If additional frames are received, but BrickletCANV2#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 BrickletCANV2#set_read_filter_configuration).
To enable this callback, use BrickletCANV2#set_frame_readable_callback_configuration.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
19
- CALLBACK_ERROR_OCCURRED =
This callback is triggered if any error occurred while writing, reading or transmitting CAN frames.
The callback is only triggered once until BrickletCANV2#get_error_log is called. That function will return details abount the error(s) occurred.
To enable this callback, use BrickletCANV2#set_error_occurred_callback_configuration.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
22
- CALLBACK_FRAME_READ =
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 BrickletCANV2#write_frame.
For details on the “data“ return value see BrickletCANV2#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 BrickletCANV2#set_read_filter_configuration).
To enable this callback, use BrickletCANV2#set_frame_read_callback_configuration.
- .. note
-
If reconstructing the value fails, the callback is triggered with nil for data.
-16
- FUNCTION_WRITE_FRAME_LOW_LEVEL =
:nodoc:
1
- FUNCTION_READ_FRAME_LOW_LEVEL =
:nodoc:
2
- FUNCTION_SET_FRAME_READ_CALLBACK_CONFIGURATION =
:nodoc:
3
- FUNCTION_GET_FRAME_READ_CALLBACK_CONFIGURATION =
:nodoc:
4
- FUNCTION_SET_TRANSCEIVER_CONFIGURATION =
:nodoc:
5
- FUNCTION_GET_TRANSCEIVER_CONFIGURATION =
:nodoc:
6
- FUNCTION_SET_QUEUE_CONFIGURATION_LOW_LEVEL =
:nodoc:
7
- FUNCTION_GET_QUEUE_CONFIGURATION_LOW_LEVEL =
:nodoc:
8
- FUNCTION_SET_READ_FILTER_CONFIGURATION =
:nodoc:
9
- FUNCTION_GET_READ_FILTER_CONFIGURATION =
:nodoc:
10
- FUNCTION_GET_ERROR_LOG_LOW_LEVEL =
:nodoc:
11
- FUNCTION_SET_COMMUNICATION_LED_CONFIG =
:nodoc:
12
- FUNCTION_GET_COMMUNICATION_LED_CONFIG =
:nodoc:
13
- FUNCTION_SET_ERROR_LED_CONFIG =
:nodoc:
14
- FUNCTION_GET_ERROR_LED_CONFIG =
:nodoc:
15
- FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION =
:nodoc:
17
- FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION =
:nodoc:
18
- FUNCTION_SET_ERROR_OCCURRED_CALLBACK_CONFIGURATION =
:nodoc:
20
- FUNCTION_GET_ERROR_OCCURRED_CALLBACK_CONFIGURATION =
:nodoc:
21
- FUNCTION_GET_SPITFP_ERROR_COUNT =
:nodoc:
234
- FUNCTION_SET_BOOTLOADER_MODE =
:nodoc:
235
- FUNCTION_GET_BOOTLOADER_MODE =
:nodoc:
236
- FUNCTION_SET_WRITE_FIRMWARE_POINTER =
:nodoc:
237
- FUNCTION_WRITE_FIRMWARE =
:nodoc:
238
- FUNCTION_SET_STATUS_LED_CONFIG =
:nodoc:
239
- FUNCTION_GET_STATUS_LED_CONFIG =
:nodoc:
240
- FUNCTION_GET_CHIP_TEMPERATURE =
:nodoc:
242
- FUNCTION_RESET =
:nodoc:
243
- FUNCTION_WRITE_UID =
:nodoc:
248
- FUNCTION_READ_UID =
:nodoc:
249
- FUNCTION_GET_IDENTITY =
:nodoc:
255
- FRAME_TYPE_STANDARD_DATA =
:nodoc:
0
- FRAME_TYPE_STANDARD_REMOTE =
:nodoc:
1
- FRAME_TYPE_EXTENDED_DATA =
:nodoc:
2
- FRAME_TYPE_EXTENDED_REMOTE =
:nodoc:
3
- TRANSCEIVER_MODE_NORMAL =
:nodoc:
0
- TRANSCEIVER_MODE_LOOPBACK =
:nodoc:
1
- TRANSCEIVER_MODE_READ_ONLY =
:nodoc:
2
- FILTER_MODE_ACCEPT_ALL =
:nodoc:
0
- FILTER_MODE_MATCH_STANDARD_ONLY =
:nodoc:
1
- FILTER_MODE_MATCH_EXTENDED_ONLY =
:nodoc:
2
- FILTER_MODE_MATCH_STANDARD_AND_EXTENDED =
:nodoc:
3
- TRANSCEIVER_STATE_ACTIVE =
:nodoc:
0
- TRANSCEIVER_STATE_PASSIVE =
:nodoc:
1
- TRANSCEIVER_STATE_DISABLED =
:nodoc:
2
- COMMUNICATION_LED_CONFIG_OFF =
:nodoc:
0
- COMMUNICATION_LED_CONFIG_ON =
:nodoc:
1
- COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT =
:nodoc:
2
- COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION =
:nodoc:
3
- ERROR_LED_CONFIG_OFF =
:nodoc:
0
- ERROR_LED_CONFIG_ON =
:nodoc:
1
- ERROR_LED_CONFIG_SHOW_HEARTBEAT =
:nodoc:
2
- ERROR_LED_CONFIG_SHOW_TRANSCEIVER_STATE =
:nodoc:
3
- ERROR_LED_CONFIG_SHOW_ERROR =
:nodoc:
4
- BOOTLOADER_MODE_BOOTLOADER =
:nodoc:
0
- BOOTLOADER_MODE_FIRMWARE =
:nodoc:
1
- BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT =
:nodoc:
2
- BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT =
:nodoc:
3
- BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT =
:nodoc:
4
- BOOTLOADER_STATUS_OK =
:nodoc:
0
- BOOTLOADER_STATUS_INVALID_MODE =
:nodoc:
1
- BOOTLOADER_STATUS_NO_CHANGE =
:nodoc:
2
- BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT =
:nodoc:
3
- BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT =
:nodoc:
4
- BOOTLOADER_STATUS_CRC_MISMATCH =
:nodoc:
5
- STATUS_LED_CONFIG_OFF =
:nodoc:
0
- STATUS_LED_CONFIG_ON =
:nodoc:
1
- STATUS_LED_CONFIG_SHOW_HEARTBEAT =
:nodoc:
2
- STATUS_LED_CONFIG_SHOW_STATUS =
:nodoc:
3
Constants inherited from Device
Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE
Instance Attribute Summary
Attributes inherited from Device
#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #high_level_callbacks, #registered_callbacks, #replaced, #uid
Instance Method Summary collapse
-
#get_bootloader_mode ⇒ Object
Returns the current bootloader mode, see BrickletCANV2#set_bootloader_mode.
-
#get_chip_temperature ⇒ Object
Returns the temperature as measured inside the microcontroller.
-
#get_communication_led_config ⇒ Object
Returns the configuration as set by BrickletCANV2#set_communication_led_config.
-
#get_error_led_config ⇒ Object
Returns the configuration as set by BrickletCANV2#set_error_led_config.
-
#get_error_log ⇒ Object
Returns information about different kinds of errors.
-
#get_error_log_low_level ⇒ Object
Returns information about different kinds of errors.
-
#get_error_occurred_callback_configuration ⇒ Object
Returns true if the CALLBACK_ERROR_OCCURRED callback is enabled, false otherwise.
-
#get_frame_read_callback_configuration ⇒ Object
Returns true if the CALLBACK_FRAME_READ callback is enabled, false otherwise.
-
#get_frame_readable_callback_configuration ⇒ Object
Returns true if the CALLBACK_FRAME_READABLE callback is enabled, false otherwise.
-
#get_identity ⇒ Object
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
-
#get_queue_configuration ⇒ Object
Returns the queue configuration as set by BrickletCANV2#set_queue_configuration.
-
#get_queue_configuration_low_level ⇒ Object
Returns the queue configuration as set by BrickletCANV2#set_queue_configuration.
-
#get_read_filter_configuration(buffer_index) ⇒ Object
Returns the read filter configuration as set by BrickletCANV2#set_read_filter_configuration.
-
#get_spitfp_error_count ⇒ Object
Returns the error count for the communication between Brick and Bricklet.
-
#get_status_led_config ⇒ Object
Returns the configuration as set by BrickletCANV2#set_status_led_config.
-
#get_transceiver_configuration ⇒ Object
Returns the configuration as set by BrickletCANV2#set_transceiver_configuration.
-
#initialize(uid, ipcon) ⇒ BrickletCANV2
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#read_frame ⇒ Object
Tries to read the next data or remote frame from the read queue and returns it.
-
#read_frame_low_level ⇒ Object
Tries to read the next data or remote frame from the read queue and returns it.
-
#read_uid ⇒ Object
Returns the current UID as an integer.
-
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#reset ⇒ Object
Calling this function will reset the Bricklet.
-
#set_bootloader_mode(mode) ⇒ Object
Sets the bootloader mode and returns the status after the requested mode change was instigated.
-
#set_communication_led_config(config) ⇒ Object
Sets the communication LED configuration.
-
#set_error_led_config(config) ⇒ Object
Sets the error LED configuration.
-
#set_error_occurred_callback_configuration(enabled) ⇒ Object
Enables and disables the CALLBACK_ERROR_OCCURRED callback.
-
#set_frame_read_callback_configuration(enabled) ⇒ Object
Enables and disables the CALLBACK_FRAME_READ callback.
-
#set_frame_readable_callback_configuration(enabled) ⇒ Object
Enables and disables the CALLBACK_FRAME_READABLE callback.
-
#set_queue_configuration(write_buffer_size, write_buffer_timeout, write_backlog_size, read_buffer_sizes, read_backlog_size) ⇒ Object
Sets the write and read queue configuration.
-
#set_queue_configuration_low_level(write_buffer_size, write_buffer_timeout, write_backlog_size, read_buffer_sizes_length, read_buffer_sizes_data, read_backlog_size) ⇒ Object
Sets the write and read queue configuration.
-
#set_read_filter_configuration(buffer_index, filter_mode, filter_mask, filter_identifier) ⇒ Object
Set the read filter configuration for the given read buffer index.
-
#set_status_led_config(config) ⇒ Object
Sets the status LED configuration.
-
#set_transceiver_configuration(baud_rate, sample_point, transceiver_mode) ⇒ Object
Sets the transceiver configuration for the CAN bus communication.
-
#set_write_firmware_pointer(pointer) ⇒ Object
Sets the firmware pointer for BrickletCANV2#write_firmware.
-
#write_firmware(data) ⇒ Object
Writes 64 Bytes of firmware at the position as written by BrickletCANV2#set_write_firmware_pointer before.
-
#write_frame(frame_type, identifier, data) ⇒ Object
Writes a data or remote frame to the write queue to be transmitted over the CAN transceiver.
-
#write_frame_low_level(frame_type, identifier, data_length, data_data) ⇒ Object
Writes a data or remote frame to the write queue to be transmitted over the CAN transceiver.
-
#write_uid(uid) ⇒ Object
Writes a new UID into flash.
Methods inherited from Device
#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all
Constructor Details
#initialize(uid, ipcon) ⇒ BrickletCANV2
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 138 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 1] @response_expected[FUNCTION_WRITE_FRAME_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_READ_FRAME_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_FRAME_READ_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_FRAME_READ_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_TRANSCEIVER_CONFIGURATION] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_TRANSCEIVER_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_QUEUE_CONFIGURATION_LOW_LEVEL] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_QUEUE_CONFIGURATION_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_READ_FILTER_CONFIGURATION] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_READ_FILTER_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_ERROR_LOG_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_COMMUNICATION_LED_CONFIG] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_COMMUNICATION_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_ERROR_LED_CONFIG] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_ERROR_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_ERROR_OCCURRED_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_ERROR_OCCURRED_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_WRITE_FIRMWARE_POINTER] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_WRITE_FIRMWARE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_WRITE_UID] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_FRAME_READ_LOW_LEVEL] = [29, 'C L C C15'] @callback_formats[CALLBACK_FRAME_READABLE] = [8, ''] @callback_formats[CALLBACK_ERROR_OCCURRED] = [8, ''] @high_level_callbacks[CALLBACK_FRAME_READ] = [[nil, nil, 'stream_length', 'stream_chunk_data'], {'fixed_length' => nil, 'single_chunk' => true}, nil] @ipcon.add_device self end |
Instance Method Details
#get_bootloader_mode ⇒ Object
Returns the current bootloader mode, see BrickletCANV2#set_bootloader_mode.
573 574 575 576 577 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 573 def get_bootloader_mode check_validity send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C' end |
#get_chip_temperature ⇒ Object
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.
631 632 633 634 635 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 631 def get_chip_temperature check_validity send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's' end |
#get_communication_led_config ⇒ Object
Returns the configuration as set by BrickletCANV2#set_communication_led_config
468 469 470 471 472 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 468 def get_communication_led_config check_validity send_request FUNCTION_GET_COMMUNICATION_LED_CONFIG, [], '', 9, 'C' end |
#get_error_led_config ⇒ Object
Returns the configuration as set by BrickletCANV2#set_error_led_config.
494 495 496 497 498 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 494 def get_error_led_config check_validity send_request FUNCTION_GET_ERROR_LED_CONFIG, [], '', 9, 'C' end |
#get_error_log ⇒ Object
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 BrickletCANV2#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 BrickletCANV2#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 BrickletCANV2#read_frame function. Using the CALLBACK_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.
859 860 861 862 863 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 859 def get_error_log ret = get_error_log_low_level [ret[0], ret[1], ret[2], ret[3], ret[4], ret[5], ret[6], ret[7], ret[8], ret[9], ret[10], ret[12][0, ret[11]], ret[13]] end |
#get_error_log_low_level ⇒ Object
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 BrickletCANV2#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 BrickletCANV2#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 BrickletCANV2#read_frame function. Using the CALLBACK_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.
449 450 451 452 453 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 449 def get_error_log_low_level check_validity send_request FUNCTION_GET_ERROR_LOG_LOW_LEVEL, [], '', 52, 'C C C L L L L L L L L C ?32 L' end |
#get_error_occurred_callback_configuration ⇒ Object
Returns true if the CALLBACK_ERROR_OCCURRED callback is enabled, false otherwise.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
534 535 536 537 538 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 534 def get_error_occurred_callback_configuration check_validity send_request FUNCTION_GET_ERROR_OCCURRED_CALLBACK_CONFIGURATION, [], '', 9, '?' end |
#get_frame_read_callback_configuration ⇒ Object
Returns true if the CALLBACK_FRAME_READ callback is enabled, false otherwise.
255 256 257 258 259 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 255 def get_frame_read_callback_configuration check_validity send_request FUNCTION_GET_FRAME_READ_CALLBACK_CONFIGURATION, [], '', 9, '?' end |
#get_frame_readable_callback_configuration ⇒ Object
Returns true if the CALLBACK_FRAME_READABLE callback is enabled, false otherwise.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
514 515 516 517 518 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 514 def get_frame_readable_callback_configuration check_validity send_request FUNCTION_GET_FRAME_READABLE_CALLBACK_CONFIGURATION, [], '', 9, '?' end |
#get_identity ⇒ Object
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 :ref:‘Isolator Bricklet <isolator_bricklet>` is always at position ’z’.
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
678 679 680 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 678 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_queue_configuration ⇒ Object
Returns the queue configuration as set by BrickletCANV2#set_queue_configuration.
818 819 820 821 822 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 818 def get_queue_configuration ret = get_queue_configuration_low_level [ret[0], ret[1], ret[2], ret[4][0, ret[3]], ret[5]] end |
#get_queue_configuration_low_level ⇒ Object
Returns the queue configuration as set by BrickletCANV2#set_queue_configuration.
339 340 341 342 343 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 339 def get_queue_configuration_low_level check_validity send_request FUNCTION_GET_QUEUE_CONFIGURATION_LOW_LEVEL, [], '', 50, 'C l S C c32 S' end |
#get_read_filter_configuration(buffer_index) ⇒ Object
Returns the read filter configuration as set by BrickletCANV2#set_read_filter_configuration.
408 409 410 411 412 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 408 def get_read_filter_configuration(buffer_index) check_validity send_request FUNCTION_GET_READ_FILTER_CONFIGURATION, [buffer_index], 'C', 17, 'C L L' end |
#get_spitfp_error_count ⇒ Object
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.
551 552 553 554 555 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 551 def get_spitfp_error_count check_validity send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L' end |
#get_status_led_config ⇒ Object
Returns the configuration as set by BrickletCANV2#set_status_led_config
619 620 621 622 623 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 619 def get_status_led_config check_validity send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C' end |
#get_transceiver_configuration ⇒ Object
Returns the configuration as set by BrickletCANV2#set_transceiver_configuration.
279 280 281 282 283 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 279 def get_transceiver_configuration check_validity send_request FUNCTION_GET_TRANSCEIVER_CONFIGURATION, [], '', 15, 'L S C' end |
#read_frame ⇒ Object
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 BrickletCANV2#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 BrickletCANV2#set_read_filter_configuration).
Instead of polling with this function, you can also use callbacks. See the BrickletCANV2#set_frame_read_callback_configuration function and the CALLBACK_FRAME_READ callback.
748 749 750 751 752 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 748 def read_frame ret = read_frame_low_level [ret[0], ret[1], ret[2], ret[4][0, ret[3]]] end |
#read_frame_low_level ⇒ Object
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 BrickletCANV2#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 BrickletCANV2#set_read_filter_configuration).
Instead of polling with this function, you can also use callbacks. See the BrickletCANV2#set_frame_read_callback_configuration function and the CALLBACK_FRAME_READ callback.
239 240 241 242 243 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 239 def read_frame_low_level check_validity send_request FUNCTION_READ_FRAME_LOW_LEVEL, [], '', 30, '? C L C C15' end |
#read_uid ⇒ Object
Returns the current UID as an integer. Encode as Base58 to get the usual string version.
662 663 664 665 666 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 662 def read_uid check_validity send_request FUNCTION_READ_UID, [], '', 12, 'L' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
866 867 868 869 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 866 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#reset ⇒ Object
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!
643 644 645 646 647 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 643 def reset check_validity send_request FUNCTION_RESET, [], '', 8, '' end |
#set_bootloader_mode(mode) ⇒ Object
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.
566 567 568 569 570 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 566 def set_bootloader_mode(mode) check_validity send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C' end |
#set_communication_led_config(config) ⇒ Object
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.
461 462 463 464 465 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 461 def set_communication_led_config(config) check_validity send_request FUNCTION_SET_COMMUNICATION_LED_CONFIG, [config], 'C', 8, '' end |
#set_error_led_config(config) ⇒ Object
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 BrickletCANV2#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.
487 488 489 490 491 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 487 def set_error_led_config(config) check_validity send_request FUNCTION_SET_ERROR_LED_CONFIG, [config], 'C', 8, '' end |
#set_error_occurred_callback_configuration(enabled) ⇒ Object
Enables and disables the CALLBACK_ERROR_OCCURRED callback.
By default the callback is disabled.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
525 526 527 528 529 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 525 def set_error_occurred_callback_configuration(enabled) check_validity send_request FUNCTION_SET_ERROR_OCCURRED_CALLBACK_CONFIGURATION, [enabled], '?', 8, '' end |
#set_frame_read_callback_configuration(enabled) ⇒ Object
Enables and disables the CALLBACK_FRAME_READ callback.
By default the callback is disabled. Enabling this callback will disable the CALLBACK_FRAME_READABLE callback.
248 249 250 251 252 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 248 def set_frame_read_callback_configuration(enabled) check_validity send_request FUNCTION_SET_FRAME_READ_CALLBACK_CONFIGURATION, [enabled], '?', 8, '' end |
#set_frame_readable_callback_configuration(enabled) ⇒ Object
Enables and disables the CALLBACK_FRAME_READABLE callback.
By default the callback is disabled. Enabling this callback will disable the CALLBACK_FRAME_READ callback.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
505 506 507 508 509 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 505 def set_frame_readable_callback_configuration(enabled) check_validity send_request FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION, [enabled], '?', 8, '' end |
#set_queue_configuration(write_buffer_size, write_buffer_timeout, write_backlog_size, read_buffer_sizes, read_backlog_size) ⇒ Object
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.
BrickletCANV2#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 BrickletCANV2#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. BrickletCANV2#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 BrickletCANV2#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 BrickletCANV2#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.
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 801 def set_queue_configuration(write_buffer_size, write_buffer_timeout, write_backlog_size, read_buffer_sizes, read_backlog_size) read_buffer_sizes = read_buffer_sizes.clone # clone so we can potentially extend it read_buffer_sizes_length = read_buffer_sizes.length read_buffer_sizes_data = read_buffer_sizes if read_buffer_sizes_length > 32 raise ArgumentError, 'Read Buffer Sizes can be at most 32 items long' end if read_buffer_sizes_length < 32 read_buffer_sizes_data += [0] * (32 - read_buffer_sizes_length) end set_queue_configuration_low_level write_buffer_size, write_buffer_timeout, write_backlog_size, read_buffer_sizes_length, read_buffer_sizes_data, read_backlog_size end |
#set_queue_configuration_low_level(write_buffer_size, write_buffer_timeout, write_backlog_size, read_buffer_sizes_length, read_buffer_sizes_data, read_backlog_size) ⇒ Object
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.
BrickletCANV2#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 BrickletCANV2#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. BrickletCANV2#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 BrickletCANV2#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 BrickletCANV2#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.
332 333 334 335 336 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 332 def set_queue_configuration_low_level(write_buffer_size, write_buffer_timeout, write_backlog_size, read_buffer_sizes_length, read_buffer_sizes_data, read_backlog_size) check_validity send_request FUNCTION_SET_QUEUE_CONFIGURATION_LOW_LEVEL, [write_buffer_size, write_buffer_timeout, write_backlog_size, read_buffer_sizes_length, read_buffer_sizes_data, read_backlog_size], 'C l S C c32 S', 8, '' end |
#set_read_filter_configuration(buffer_index, filter_mode, filter_mask, filter_identifier) ⇒ Object
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 BrickletCANV2#set_queue_configuration).
The default mode is accept-all for all read buffers.
401 402 403 404 405 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 401 def set_read_filter_configuration(buffer_index, filter_mode, filter_mask, filter_identifier) check_validity send_request FUNCTION_SET_READ_FILTER_CONFIGURATION, [buffer_index, filter_mode, filter_mask, filter_identifier], 'C C L L', 8, '' end |
#set_status_led_config(config) ⇒ Object
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.
612 613 614 615 616 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 612 def set_status_led_config(config) check_validity send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, '' end |
#set_transceiver_configuration(baud_rate, sample_point, transceiver_mode) ⇒ Object
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.
272 273 274 275 276 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 272 def set_transceiver_configuration(baud_rate, sample_point, transceiver_mode) check_validity send_request FUNCTION_SET_TRANSCEIVER_CONFIGURATION, [baud_rate, sample_point, transceiver_mode], 'L S C', 8, '' end |
#set_write_firmware_pointer(pointer) ⇒ Object
Sets the firmware pointer for BrickletCANV2#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.
585 586 587 588 589 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 585 def set_write_firmware_pointer(pointer) check_validity send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, '' end |
#write_firmware(data) ⇒ Object
Writes 64 Bytes of firmware at the position as written by BrickletCANV2#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.
599 600 601 602 603 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 599 def write_firmware(data) check_validity send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C' end |
#write_frame(frame_type, identifier, data) ⇒ Object
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 BrickletCANV2#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 BrickletCANV2#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 BrickletCANV2#get_error_log).
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 710 def write_frame(frame_type, identifier, data) data = data.clone # clone so we can potentially extend it data_length = data.length data_data = data if data_length > 15 raise ArgumentError, 'Data can be at most 15 items long' end if data_length < 15 data_data += [0] * (15 - data_length) end write_frame_low_level frame_type, identifier, data_length, data_data end |
#write_frame_low_level(frame_type, identifier, data_length, data_data) ⇒ Object
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 BrickletCANV2#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 BrickletCANV2#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 BrickletCANV2#get_error_log).
211 212 213 214 215 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 211 def write_frame_low_level(frame_type, identifier, data_length, data_data) check_validity send_request FUNCTION_WRITE_FRAME_LOW_LEVEL, [frame_type, identifier, data_length, data_data], 'C L C C15', 9, '?' end |
#write_uid(uid) ⇒ Object
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.
654 655 656 657 658 |
# File 'lib/tinkerforge/bricklet_can_v2.rb', line 654 def write_uid(uid) check_validity send_request FUNCTION_WRITE_UID, [uid], 'L', 8, '' end |