MATLAB/Octave - CAN Bricklet

This is the description of the MATLAB/Octave API bindings for the CAN Bricklet. General information and technical specifications for the CAN Bricklet are summarized in its hardware description.

An installation guide for the MATLAB/Octave API bindings is part of their general description.

Examples

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

Loopback (MATLAB)

Download (matlab_example_loopback.m)

 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
function matlab_example_loopback()
    import com.tinkerforge.IPConnection;
    import com.tinkerforge.BrickletCAN;

    HOST = 'localhost';
    PORT = 4223;
    UID = 'XYZ'; % Change XYZ to the UID of your CAN Bricklet

    ipcon = IPConnection(); % Create IP connection
    can = handle(BrickletCAN(UID, ipcon), 'CallbackProperties'); % Create device object

    ipcon.connect(HOST, PORT); % Connect to brickd
    % Don't use device before ipcon is connected

    % Configure transceiver for loopback mode
    can.setConfiguration(BrickletCAN.BAUD_RATE_1000KBPS, ...
                         BrickletCAN.TRANSCEIVER_MODE_LOOPBACK, 0);

    % Register frame read callback to function cb_frame_read
    set(can, 'FrameReadCallback', @(h, e) cb_frame_read(e));

    % Enable frame read callback
    can.enableFrameReadCallback();

    % Write standard data frame with identifier 1742 and 3 bytes of data
    data = [42, 23, 17, 0, 0, 0, 0, 0];
    can.writeFrame(BrickletCAN.FRAME_TYPE_STANDARD_DATA, 1742, data, 3);

    input('Press key to exit\n', 's');

    can.disableFrameReadCallback();

    ipcon.disconnect();
end

% Callback function for frame read callback
function cb_frame_read(e)
    if e.frameType == com.tinkerforge.BrickletCAN.FRAME_TYPE_STANDARD_DATA
        fprintf('Frame Type: Standard Data\n');
    elseif e.frameType == com.tinkerforge.BrickletCAN.FRAME_TYPE_STANDARD_REMOTE
        fprintf('Frame Type: Standard Remote\n');
    elseif e.frameType == com.tinkerforge.BrickletCAN.FRAME_TYPE_EXTENDED_DATA
        fprintf('Frame Type: Extended Data\n');
    elseif e.frameType == com.tinkerforge.BrickletCAN.FRAME_TYPE_EXTENDED_REMOTE
        fprintf('Frame Type: Extended Remote\n');
    end

    fprintf('Identifier: %i\n', e.identifier);
    fprintf('Data (Length: %i):', e.length);

    for i = 1:min(e.length, 8)
        fprintf(' %i', e.data(i));
    end

    fprintf('\n');
    fprintf('\n');
end

Loopback (Octave)

Download (octave_example_loopback.m)

 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
function octave_example_loopback()
    more off;

    HOST = "localhost";
    PORT = 4223;
    UID = "XYZ"; % Change XYZ to the UID of your CAN Bricklet

    ipcon = javaObject("com.tinkerforge.IPConnection"); % Create IP connection
    can = javaObject("com.tinkerforge.BrickletCAN", UID, ipcon); % Create device object

    ipcon.connect(HOST, PORT); % Connect to brickd
    % Don't use device before ipcon is connected

    % Configure transceiver for loopback mode
    can.setConfiguration(can.BAUD_RATE_1000KBPS, can.TRANSCEIVER_MODE_LOOPBACK, 0);

    % Register frame read callback to function cb_frame_read
    can.addFrameReadCallback(@cb_frame_read);

    % Enable frame read callback
    can.enableFrameReadCallback();

    % Write standard data frame with identifier 1742 and 3 bytes of data
    data = [42, 23, 17, 0, 0, 0, 0, 0];
    can.writeFrame(can.FRAME_TYPE_STANDARD_DATA, 1742, data, 3);

    input("Press key to exit\n", "s");

    can.disableFrameReadCallback();

    ipcon.disconnect();
end

% Callback function for frame read callback
function cb_frame_read(e)
    data = e.data;
    len = java2int(e.length);

    if java2int(e.frameType) == 0
        fprintf("Frame Type: Standard Data\n");
    elseif java2int(e.frameType) == 1
        fprintf("Frame Type: Standard Remote\n");
    elseif java2int(e.frameType) == 2
        fprintf("Frame Type: Extended Data\n");
    elseif java2int(e.frameType) == 3
        fprintf("Frame Type: Extended Remote\n");
    end

    fprintf("Identifier: %d\n", java2int(e.identifier));
    fprintf("Data (Length: %d):", len);

    for i = 1:min(len, 8)
        fprintf(" %d", java2int(data(i)));
    end

    fprintf("\n");
    fprintf("\n");
end

function int = java2int(value)
    if compare_versions(version(), "3.8", "<=")
        int = value.intValue();
    else
        int = value;
    end
end

API

Generally, every method of the MATLAB bindings that returns a value can throw a TimeoutException. This exception gets thrown if the device did not respond. If a cable based connection is used, it is unlikely that this exception gets thrown (assuming nobody unplugs the device). However, if a wireless connection is used, timeouts will occur if the distance to the device gets too big.

Beside the TimeoutException there is also a NotConnectedException that is thrown if a method needs to communicate with the device while the IP Connection is not connected.

Since the MATLAB bindings are based on Java and Java does not support multiple return values and return by reference is not possible for primitive types, we use small classes that only consist of member variables. The member variables of the returned objects are described in the corresponding method descriptions.

The package for all Brick/Bricklet bindings and the IP Connection is com.tinkerforge.*

All methods listed below are thread-safe.

Basic Functions

class BrickletCAN(String uid, IPConnection ipcon)
Parameters:
  • uid – Type: String
  • ipcon – Type: IPConnection
Returns:
  • can – Type: BrickletCAN

Creates an object with the unique device ID uid.

In MATLAB:

import com.tinkerforge.BrickletCAN;

can = BrickletCAN('YOUR_DEVICE_UID', ipcon);

In Octave:

can = java_new("com.tinkerforge.BrickletCAN", "YOUR_DEVICE_UID", ipcon);

This object can then be used after the IP Connection is connected.

boolean BrickletCAN.writeFrame(short frameType, long identifier, short[] data, short length)
Parameters:
  • frameType – Type: short, Range: See constants
  • identifier – Type: long, Range: [0 to 230 - 1]
  • data – Type: short[], Length: 8, Range: [0 to 255]
  • length – Type: short, Range: [0 to 15]
Returns:
  • success – Type: boolean

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 setConfiguration()). 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 getErrorLog()).

The following constants are available for this function:

For frameType:

  • BrickletCAN.FRAME_TYPE_STANDARD_DATA = 0
  • BrickletCAN.FRAME_TYPE_STANDARD_REMOTE = 1
  • BrickletCAN.FRAME_TYPE_EXTENDED_DATA = 2
  • BrickletCAN.FRAME_TYPE_EXTENDED_REMOTE = 3
BrickletCAN.ReadFrame BrickletCAN.readFrame()
Return Object:
  • success – Type: boolean
  • frameType – Type: short, Range: See constants
  • identifier – Type: long, Range: [0 to 230 - 1]
  • data – Type: short[], Length: 8, Range: [0 to 255]
  • length – Type: short, Range: [0 to 15]

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

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

Instead of polling with this function, you can also use callbacks. See the enableFrameReadCallback() function and the FrameReadCallback callback.

The following constants are available for this function:

For frameType:

  • BrickletCAN.FRAME_TYPE_STANDARD_DATA = 0
  • BrickletCAN.FRAME_TYPE_STANDARD_REMOTE = 1
  • BrickletCAN.FRAME_TYPE_EXTENDED_DATA = 2
  • BrickletCAN.FRAME_TYPE_EXTENDED_REMOTE = 3
void BrickletCAN.setConfiguration(short baudRate, short transceiverMode, int writeTimeout)
Parameters:
  • baudRate – Type: short, Range: See constants, Default: 3
  • transceiverMode – Type: short, Range: See constants, Default: 0
  • writeTimeout – Type: int, Range: [-1 to 231 - 1], Default: 0

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:

  • 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 write timeout has three different modes that define how a failed frame transmission should be handled:

  • One-Shot (= -1): 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 following constants are available for this function:

For baudRate:

  • BrickletCAN.BAUD_RATE_10KBPS = 0
  • BrickletCAN.BAUD_RATE_20KBPS = 1
  • BrickletCAN.BAUD_RATE_50KBPS = 2
  • BrickletCAN.BAUD_RATE_125KBPS = 3
  • BrickletCAN.BAUD_RATE_250KBPS = 4
  • BrickletCAN.BAUD_RATE_500KBPS = 5
  • BrickletCAN.BAUD_RATE_800KBPS = 6
  • BrickletCAN.BAUD_RATE_1000KBPS = 7

For transceiverMode:

  • BrickletCAN.TRANSCEIVER_MODE_NORMAL = 0
  • BrickletCAN.TRANSCEIVER_MODE_LOOPBACK = 1
  • BrickletCAN.TRANSCEIVER_MODE_READ_ONLY = 2
BrickletCAN.Configuration BrickletCAN.getConfiguration()
Return Object:
  • baudRate – Type: short, Range: See constants, Default: 3
  • transceiverMode – Type: short, Range: See constants, Default: 0
  • writeTimeout – Type: int, Range: [-1 to 231 - 1], Default: 0

Returns the configuration as set by setConfiguration().

The following constants are available for this function:

For baudRate:

  • BrickletCAN.BAUD_RATE_10KBPS = 0
  • BrickletCAN.BAUD_RATE_20KBPS = 1
  • BrickletCAN.BAUD_RATE_50KBPS = 2
  • BrickletCAN.BAUD_RATE_125KBPS = 3
  • BrickletCAN.BAUD_RATE_250KBPS = 4
  • BrickletCAN.BAUD_RATE_500KBPS = 5
  • BrickletCAN.BAUD_RATE_800KBPS = 6
  • BrickletCAN.BAUD_RATE_1000KBPS = 7

For transceiverMode:

  • BrickletCAN.TRANSCEIVER_MODE_NORMAL = 0
  • BrickletCAN.TRANSCEIVER_MODE_LOOPBACK = 1
  • BrickletCAN.TRANSCEIVER_MODE_READ_ONLY = 2

Advanced Functions

void BrickletCAN.setReadFilter(short mode, long mask, long filter1, long filter2)
Parameters:
  • mode – Type: short, Range: See constants, Default: 1
  • mask – Type: long, Range: [0 to 230 - 1]
  • filter1 – Type: long, Range: [0 to 230 - 1]
  • filter2 – Type: long, Range: [0 to 230 - 1]

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:

  • Disabled: No filtering is applied at all. All frames are received even incomplete and defective frames. This mode should be used for debugging only.
  • Accept-All: All complete and error-free frames are received.
  • Match-Standard: Only standard frames with a matching identifier are received.
  • Match-Standard-and-Data: Only standard frames with matching identifier and data bytes are received.
  • Match-Extended: Only extended frames with a matching identifier are received.

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

  • Disabled: Mask and filters are ignored.
  • Accept-All: Mask and filters are ignored.
  • Match-Standard: Bit 0 to 10 (11 bits) of mask and filters are used to match the 11-bit identifier of standard frames.
  • Match-Standard-and-Data: Bit 0 to 10 (11 bits) of mask and filters are used to match the 11-bit identifier of standard frames. Bit 11 to 18 (8 bits) and bit 19 to 26 (8 bits) of mask and filters are used to match the first and second data byte (if present) of standard frames.
  • Match-Extended: Bit 0 to 10 (11 bits) of mask and filters are used to match the standard 11-bit identifier part of extended frames. Bit 11 to 28 (18 bits) of mask and filters are used to match the extended 18-bit identifier part of extended frames.

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

For mode:

  • BrickletCAN.FILTER_MODE_DISABLED = 0
  • BrickletCAN.FILTER_MODE_ACCEPT_ALL = 1
  • BrickletCAN.FILTER_MODE_MATCH_STANDARD = 2
  • BrickletCAN.FILTER_MODE_MATCH_STANDARD_AND_DATA = 3
  • BrickletCAN.FILTER_MODE_MATCH_EXTENDED = 4
BrickletCAN.ReadFilter BrickletCAN.getReadFilter()
Return Object:
  • mode – Type: short, Range: See constants, Default: 1
  • mask – Type: long, Range: [0 to 230 - 1]
  • filter1 – Type: long, Range: [0 to 230 - 1]
  • filter2 – Type: long, Range: [0 to 230 - 1]

Returns the read filter as set by setReadFilter().

The following constants are available for this function:

For mode:

  • BrickletCAN.FILTER_MODE_DISABLED = 0
  • BrickletCAN.FILTER_MODE_ACCEPT_ALL = 1
  • BrickletCAN.FILTER_MODE_MATCH_STANDARD = 2
  • BrickletCAN.FILTER_MODE_MATCH_STANDARD_AND_DATA = 3
  • BrickletCAN.FILTER_MODE_MATCH_EXTENDED = 4
BrickletCAN.ErrorLog BrickletCAN.getErrorLog()
Return Object:
  • writeErrorLevel – Type: short, Range: [0 to 255]
  • readErrorLevel – Type: short, Range: [0 to 255]
  • transceiverDisabled – Type: boolean
  • writeTimeoutCount – Type: long, Range: [0 to 232 - 1]
  • readRegisterOverflowCount – Type: long, Range: [0 to 232 - 1]
  • readBufferOverflowCount – Type: long, Range: [0 to 232 - 1]

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 setConfiguration()) 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:

  • A write timeout occurs if a frame could not be transmitted before the configured write timeout expired (see setConfiguration()).
  • A read register overflow occurs if the read register of the CAN transceiver still contains the last received frame when the next frame arrives. In this case the newly arrived frame is lost. This happens if the CAN transceiver receives more frames than the Bricklet can handle. Using the read filter (see setReadFilter()) 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 buffer overflow occurs if the read buffer of the Bricklet is already full when the next frame should be read from the read register of the CAN transceiver. In this case the frame in the read register is lost. This happens if the CAN transceiver receives more frames to be added to the read buffer than are removed from the read buffer using the readFrame() function. Using the FrameReadCallback callback ensures that the read buffer can not overflow.
BrickletCAN.Identity BrickletCAN.getIdentity()
Return Object:
  • uid – Type: String, Length: up to 8
  • connectedUid – Type: String, Length: up to 8
  • position – Type: char, Range: ['a' to 'h', 'z']
  • hardwareVersion – Type: short[], Length: 3
    • 1: major – Type: short, Range: [0 to 255]
    • 2: minor – Type: short, Range: [0 to 255]
    • 3: revision – Type: short, Range: [0 to 255]
  • firmwareVersion – Type: short[], Length: 3
    • 1: major – Type: short, Range: [0 to 255]
    • 2: minor – Type: short, Range: [0 to 255]
    • 3: revision – Type: short, Range: [0 to 255]
  • deviceIdentifier – Type: int, Range: [0 to 216 - 1]

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an Isolator Bricklet is always at position 'z'.

The device identifier numbers can be found here. There is also a constant for the device identifier of this Bricklet.

Callback Configuration Functions

void BrickletCAN.enableFrameReadCallback()

Enables the FrameReadCallback callback.

By default the callback is disabled. Enabling this callback will disable the FrameReadableCallback callback.

void BrickletCAN.disableFrameReadCallback()

Disables the FrameReadCallback callback.

By default the callback is disabled.

boolean BrickletCAN.isFrameReadCallbackEnabled()
Returns:
  • enabled – Type: boolean, Default: false

Returns true if the FrameReadCallback callback is enabled, false otherwise.

void BrickletCAN.setFrameReadableCallbackConfiguration(boolean enabled)
Parameters:
  • enabled – Type: boolean, Default: false

Enables/disables the FrameReadableCallback callback.

By default the callback is disabled. Enabling this callback will disable the FrameReadCallback callback.

New in version 2.0.1 (Plugin).

boolean BrickletCAN.getFrameReadableCallbackConfiguration()
Returns:
  • enabled – Type: boolean, Default: false

Returns true if the FrameReadableCallback callback is enabled, false otherwise.

New in version 2.0.1 (Plugin).

Callbacks

Callbacks can be registered to receive time critical or recurring data from the device. The registration is done with "set" function of MATLAB. The parameters consist of the IP Connection object, the callback name and the callback function. For example, it looks like this in MATLAB:

function my_callback(e)
    fprintf('Parameter: %s\n', e.param);
end

set(device, 'ExampleCallback', @(h, e) my_callback(e));

Due to a difference in the Octave Java support the "set" function cannot be used in Octave. The registration is done with "add*Callback" functions of the device object. It looks like this in Octave:

function my_callback(e)
    fprintf("Parameter: %s\n", e.param);
end

device.addExampleCallback(@my_callback);

It is possible to add several callbacks and to remove them with the corresponding "remove*Callback" function.

The parameters of the callback are passed to the callback function as fields of the structure e, which is derived from the java.util.EventObject class. The available callback names with corresponding structure fields are described below.

Note

Using callbacks for recurring events is always preferred compared to using getters. It will use less USB bandwidth and the latency will be a lot better, since there is no round trip time.

callback BrickletCAN.FrameReadCallback
Event Object:
  • frameType – Type: short, Range: See constants
  • identifier – Type: long, Range: [0 to 230 - 1]
  • data – Type: short[], Length: 8, Range: [0 to 255]
  • length – Type: short, Range: [0 to 15]

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

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

To enable this callback, use enableFrameReadCallback().

The following constants are available for this function:

For frameType:

  • BrickletCAN.FRAME_TYPE_STANDARD_DATA = 0
  • BrickletCAN.FRAME_TYPE_STANDARD_REMOTE = 1
  • BrickletCAN.FRAME_TYPE_EXTENDED_DATA = 2
  • BrickletCAN.FRAME_TYPE_EXTENDED_REMOTE = 3

In MATLAB the set() function can be used to register a callback function to this callback.

In Octave a callback function can be added to this callback using the addFrameReadCallback() function. An added callback function can be removed with the removeFrameReadCallback() function.

callback BrickletCAN.FrameReadableCallback
Event Object:
  • empty object

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

To enable this callback, use setFrameReadableCallbackConfiguration().

New in version 2.0.1 (Plugin).

In MATLAB the set() function can be used to register a callback function to this callback.

In Octave a callback function can be added to this callback using the addFrameReadableCallback() function. An added callback function can be removed with the removeFrameReadableCallback() function.

Virtual Functions

Virtual functions don't communicate with the device itself, but operate only on the API bindings device object. They can be called without the corresponding IP Connection object being connected.

short[] BrickletCAN.getAPIVersion()
Return Object:
  • apiVersion – Type: short[], Length: 3
    • 1: major – Type: short, Range: [0 to 255]
    • 2: minor – Type: short, Range: [0 to 255]
    • 3: revision – Type: short, Range: [0 to 255]

Returns the version of the API definition implemented by this API bindings. This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.

boolean BrickletCAN.getResponseExpected(byte functionId)
Parameters:
  • functionId – Type: byte, Range: See constants
Returns:
  • responseExpected – Type: boolean

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 setResponseExpected(). 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 functionId:

  • BrickletCAN.FUNCTION_ENABLE_FRAME_READ_CALLBACK = 3
  • BrickletCAN.FUNCTION_DISABLE_FRAME_READ_CALLBACK = 4
  • BrickletCAN.FUNCTION_SET_CONFIGURATION = 6
  • BrickletCAN.FUNCTION_SET_READ_FILTER = 8
  • BrickletCAN.FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION = 12
void BrickletCAN.setResponseExpected(byte functionId, boolean responseExpected)
Parameters:
  • functionId – Type: byte, Range: See constants
  • responseExpected – Type: boolean

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 functionId:

  • BrickletCAN.FUNCTION_ENABLE_FRAME_READ_CALLBACK = 3
  • BrickletCAN.FUNCTION_DISABLE_FRAME_READ_CALLBACK = 4
  • BrickletCAN.FUNCTION_SET_CONFIGURATION = 6
  • BrickletCAN.FUNCTION_SET_READ_FILTER = 8
  • BrickletCAN.FUNCTION_SET_FRAME_READABLE_CALLBACK_CONFIGURATION = 12
void BrickletCAN.setResponseExpectedAll(boolean responseExpected)
Parameters:
  • responseExpected – Type: boolean

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

Constants

int BrickletCAN.DEVICE_IDENTIFIER

This constant is used to identify a CAN Bricklet.

The getIdentity() function and the IPConnection.EnumerateCallback callback of the IP Connection have a deviceIdentifier parameter to specify the Brick's or Bricklet's type.

String BrickletCAN.DEVICE_DISPLAY_NAME

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