Bemerkung
Die openHAB-Dokumentation ist nur auf Englisch verfügbar.
Warnung
The openHAB bindings are still in beta, but the development was stopped.
This is the description of the openHAB API bindings for the CAN Bricklet 2.0. General information and technical specifications for the CAN Bricklet 2.0 are summarized in its hardware description.
An installation guide for the openHAB API bindings is part of their general description.
The example code below is Public Domain (CC0 1.0).
Download (ExampleLoopback.rules)
1// For this example configure your CAN Bricklet 2.0 to loopback mode in Paper UI.
2
3import java.util.Arrays
4
5val FRAME_TYPE_STANDARD_DATA = 0
6val FRAME_TYPE_STANDARD_REMOTE = 1
7val FRAME_TYPE_EXTENDED_DATA = 2
8val FRAME_TYPE_EXTENDED_REMOTE = 3
9
10rule "send"
11when
12 System started // Replace with trigger of your choice
13then
14 // Change XYZ to the UID of your CAN Bricklet
15 val canActions = getActions("tinkerforge", "tinkerforge:brickletcanv2:XYZ")
16
17 // Write standard data frame with identifier 1742 and 3 bytes of data
18 canActions.brickletCANV2WriteFrame(FRAME_TYPE_STANDARD_DATA, 1742, newArrayList(42, 23, 17))
19end
20
21rule "receive"
22when
23 // Change XYZ to the UID of your CAN Bricklet
24 Channel "tinkerforge:brickletcanv2:XYZ:BrickletCANV2FrameReadable" triggered
25then
26 // Change XYZ to the UID of your CAN Bricklet
27 val canActions = getActions("tinkerforge", "tinkerforge:brickletcanv2:XYZ")
28 val frame = canActions.brickletCANV2ReadFrame()
29
30 val success = frame.get("success") as boolean
31 if (success) {
32 val frameType = frame.get("frameType") as int
33
34 if(frameType == FRAME_TYPE_STANDARD_DATA) {
35 logInfo("Example", "Frame Type: Standard Data")
36 } else if(frameType == FRAME_TYPE_STANDARD_REMOTE) {
37 logInfo("Example", "Frame Type: Standard Remote")
38 } else if(frameType == FRAME_TYPE_EXTENDED_DATA) {
39 logInfo("Example", "Frame Type: Extended Data")
40 } else if(frameType == FRAME_TYPE_EXTENDED_REMOTE) {
41 logInfo("Example", "Frame Type: Extended Remote")
42 }
43
44 logInfo("Example", "Identifier: " + frame.get("identifier"))
45 var data = frame.get("data") as int[]
46
47 logInfo("Example", "Data: " + Arrays.toString(data))
48 } else {
49 logInfo("Example", "Failed to read frame")
50 }
51end
UID:
- tinkerforge:brickletcanv2:[UID]
Required firmware version:
- 2.0.3
Firmware update supported:
- yes
Channels: Actions: Parameters:
- Baud Rate – Type: integer, Default: 125000, Min: 10000, Max: 1000000
- The baud rate to send/receive with.
- Sample Point – Type: decimal, Default: 62.5, Min: 50, Max: 90, Step: 0.1
- Configures when to sample a bit during each bit period.
- Transceiver Mode – Type: Choice, Default: Normal
- 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.
- Options: Normal, Loopback, Read Only
- Communication LED Configuration – Type: Choice, Default: Show Communication
- 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.
- Options: Off, On, Show Heartbeat, Show Communication
- Error LED Configuration – Type: Choice, Default: Show Transceiver State
- By default (show-transceiver-state) the error LED turns on if the CAN transceiver is passive or disabled state (see the getErrorLog action). 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.
- Options: Off, On, Show Heartbeat, Show Transceiver State, Show Error
- Status LED Configuration – Type: Choice, Default: Show Status
- 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.
- Options: Off, On, Show Heartbeat, Show Status
This channel is triggered when a new frame was received and can be read out. The channel will only trigger again if the frame was read.
Type:
- Trigger (system.trigger)
UID:
- tinkerforge:brickletcanv2:[UID]:BrickletCANV2FrameReadable
Read only:
- No
This channel is triggered if any error occurred while writing, reading or transmitting CAN frames. The channel will trigger only once until the getErrorLog action is called.
Type:
- Trigger (system.trigger)
UID:
- tinkerforge:brickletcanv2:[UID]:BrickletCANV2ErrorOccurred
Read only:
- No
Clears the error LED.
Type:
- Commands (String)
UID:
- tinkerforge:brickletcanv2:[UID]:BrickletCANV2ClearErrorLED
Read only:
- No
Predicate:
- This channel will only be available if Error LED Configuration is Show Error.
Commands:
- Accepts any string
Actions can be used in rules by creating an action object. All actions return a Map<String, Object>. Returned values can be accessed by name, sometimes the type deduction needs some hints, as shown below:
val actions = getActions("tinkerforge", "tinkerforge:brickletcanv2:[UID]")
val hwVersion = actions.brickletCANV2GetIdentity().get("hardwareVersion") as short[]
logInfo("Example", "Hardware version: " + hwVersion.get(0) + "." + hwVersion.get(1) + "." + hwVersion.get(2))
| Parameters: |
|
|---|---|
| Return Map: |
|
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 SetQueueConfiguration()).
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 the thing 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 GetErrorLog()).
The following constants are available for this function:
For frameType:
val FRAME_TYPE_STANDARD_DATA = 0
val FRAME_TYPE_STANDARD_REMOTE = 1
val FRAME_TYPE_EXTENDED_DATA = 2
val FRAME_TYPE_EXTENDED_REMOTE = 3
| Return Map: |
|
|---|
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
WriteFrame().
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
SetReadFilterConfiguration()).
The following constants are available for this function:
For frameType:
val FRAME_TYPE_STANDARD_DATA = 0
val FRAME_TYPE_STANDARD_REMOTE = 1
val FRAME_TYPE_EXTENDED_DATA = 2
val FRAME_TYPE_EXTENDED_REMOTE = 3
| Return Map: |
|
|---|
Returns the configuration as set by the thing configuration.
The following constants are available for this function:
For transceiverMode:
val TRANSCEIVER_MODE_NORMAL = 0
val TRANSCEIVER_MODE_LOOPBACK = 1
val TRANSCEIVER_MODE_READ_ONLY = 2
| Parameters: |
|
|---|
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.
WriteFrame() 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
WriteFrame() 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. ReadFrame() 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 ReadFrame() 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 SetReadFilterConfiguration()).
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.
| Return Map: |
|
|---|
Returns the queue configuration as set by SetQueueConfiguration().
| Parameters: |
|
|---|
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 SetQueueConfiguration()).
The default mode is accept-all for all read buffers.
The following constants are available for this function:
For filterMode:
val FILTER_MODE_ACCEPT_ALL = 0
val FILTER_MODE_MATCH_STANDARD_ONLY = 1
val FILTER_MODE_MATCH_EXTENDED_ONLY = 2
val FILTER_MODE_MATCH_STANDARD_AND_EXTENDED = 3
| Parameters: |
|
|---|---|
| Return Map: |
|
Returns the read filter configuration as set by SetReadFilterConfiguration().
The following constants are available for this function:
For filterMode:
val FILTER_MODE_ACCEPT_ALL = 0
val FILTER_MODE_MATCH_STANDARD_ONLY = 1
val FILTER_MODE_MATCH_EXTENDED_ONLY = 2
val FILTER_MODE_MATCH_STANDARD_AND_EXTENDED = 3
| Return Map: |
|
|---|
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 SetQueueConfiguration()).
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 SetReadFilterConfiguration()) 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 ReadFrame()
function.
The read buffer overflow counter counts the overflows of all configured read
buffers. Which read buffer exactly suffered from an overflow can be figured
out from the read buffer overflow occurrence list
(read_buffer_overflow_error_occurred). Reading the error log clears the
occurence list.
The following constants are available for this function:
For transceiverState:
val TRANSCEIVER_STATE_ACTIVE = 0
val TRANSCEIVER_STATE_PASSIVE = 1
val TRANSCEIVER_STATE_DISABLED = 2
| Return Map: |
|
|---|
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.
| Return Map: |
|
|---|
Returns the configuration as set by the thing configuration
The following constants are available for this function:
For config:
val STATUS_LED_CONFIG_OFF = 0
val STATUS_LED_CONFIG_ON = 1
val STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2
val STATUS_LED_CONFIG_SHOW_STATUS = 3
| Return Map: |
|
|---|
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.
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!
| Return Map: |
|
|---|
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.
| Return Map: |
|
|---|
Returns the current UID as an integer. Encode as Base58 to get the usual string version.