Skip to main content

CAN example

Any SocketCAN-compatible USB dongle can be added when physical interfaces are required. Amongst others, PEAK-System does provide such devices.

It is possible to configure the baud rate of the CAN interfaces. For type can, use the optional parameter baud_rate to control CAN data rate, and for type canfd, there is also dbaud_rate to control the flexible data rate. Notice that for canfd, either none or both parameters must be specified.

DBC

The following is a typical and very simple configuration using a DBC file, where baud rate is configured for the CAN interfaces.

{
"chains": [
{
"namespace": "mycan",
"type": "can",
"database": "can/MyCAN.dbc",
"device_name": "can0",
"baud_rate": 50000
},
{
"namespace": "myothercan",
"type": "canfd",
"database": "can/MyOtherCAN.dbc",
"device_name": "can1",
"baud_rate": 50000,
"dbaud_rate": 500000
}
]
}
note

In this example the namespaces are named after the DBC files and not the device names.

ARXML

The following is a typical and very simple configuration using a ARXML file. When configuring an interface with an ARXML file you also need to specify the path to the physical channel from which you want to parse the CAN frames and signals. Here is the schema reference for can_physical_channel_name.

{
"chains": [
{
"namespace": "mycan",
"type": "can",
"database": "can/MyCAN.arxml",
"device_name": "can0",
"can_physical_channel_name": "/ExamplePackage/ExampleCanCluster/ExampleCANChannel"
}
]
}

Here is an example of what can/MyCAN.arxml might look like. Note that this is a mockup database and is invalid.

...
<AR-PACKAGES>
...
<AR-PACKAGE>
<SHORT-NAME>ExamplePackage</SHORT-NAME>
<ELEMENTS>
<CAN-CLUSTER>
<SHORT-NAME>ExampleCanCluster</SHORT-NAME>
<CAN-CLUSTER-VARIANTS>
<CAN-CLUSTER-CONDITIONAL>
<PHYSICAL-CHANNELS>
<CAN-PHYSICAL-CHANNEL>
<SHORT-NAME>ExampleCANChannel</SHORT-NAME>
<FRAME-TRIGGERINGS>
<CAN-FRAME-TRIGGERING>
...
</CAN-FRAME-TRIGGERING>
</FRAME-TRIGGERINGS>
</CAN-PHYSICAL-CHANNEL>
</PHYSICAL-CHANNELS>
</CAN-CLUSTER-CONDITIONAL>
</CAN-CLUSTER-VARIANTS>
</CAN-CLUSTER>
</ELEMENTS>
</AR-PACKAGE>
...
</AR-PACKAGES>
...