Main Content

Log and Replay CAN FD Messages

This example shows you how to log and replay CAN FD messages using MathWorks virtual CAN FD channels in Simulink. You can update this model to connect to supported hardware on your system.

Load the saved CAN FD message fromsourceFDMsgs.matfile from the examples folder. The file contains CAN FD messages representing a 90 second drive cycle around a test track.

Convert these messages to a format compatible with the CAN FD Replay block and save it to a separate file.

Name Size Bytes Class Attributes canFDMsgTimetable 100000x12 45411725 timetable canFDMsgs 1x1 8401848 struct

CAN FD Replay Model

This model contains:

  • A CAN FD Replay block that transmits toMathWorks Virtual Channel 1.

  • A CAN FD Receive block that receives the messages on a CAN FD network, throughMathWorks Virtual Channel 2.

The CAN FD Receive block is configured to block all extended IDs and allow only theWheelSpeedmessage with the standard ID1200to pass.

The Wheel Speeds subsystem unpacks the wheel speed information from the received CAN FD messages and plots them to a scope. The subsystem also logs the messages to a file.

Visualize Wheel Speed Information

The plot shows the wheel speed for all wheels for the duration of the test drive.

Load the Logged Message File

The CAN FD Log block creates a unique file each time you run the model. Usedirin the MATLAB Command Window to find the latest log file.

WheelSpeeds_2018-Apr-30_132033.mat Name Size Bytes Class Attributes canFDMsgTimetable 100000x12 45411725 timetable canFDMsgs 1x1 8401848 struct outFDMsgs 1x1 841848 struct

Convert Logged Messages

UsecanFDMessageTimetableto convert messages logged during the simulation to a timetable that you can use in the command window.

To access message signals directly, use the appropriate database file in the conversion along withcanSignalTimetable.

ans = 15x12 timetable Time ID Extended Name ProtocolMode Data Length DLC Signals Error Remote BRS ESI __________ ____ ________ _______________ ____________ __________________________________ ______ ___ ____________ _____ ______ _____ _____ 75.393 sec 576 false {0x0 char } {'CAN FD'} {[ 79 136 166 71]} 4 4 {0x0 struct} false false true false 75.397 sec 1200 false {'WheelSpeeds'} {'CAN FD'} {[ 54 171 55 39 54 180 55 39]} 8 8 {1x1 struct} false false true false 75.398 sec 128 false {0x0 char } {'CAN FD'} {[ 41 89 117 48 1 83 218]} 7 7 {0x0 struct} false false true false 75.398 sec 133 false {0x0 char } {'CAN FD'} {[ 0 102 0 0 0 0 0 0]} 8 8 {0x0 struct} false false true false 75.398 sec 144 false {0x0 char } {'CAN FD'} {[ 167 129 247 8 200 145 24 93]} 8 8 {0x0 struct} false false true false 75.398 sec 528 false {0x0 char } {'CAN FD'} {[ 255 254 60 4 64 0 0]} 7 7 {0x0 struct} false false true false 75.399 sec 529 false {0x0 char } {'CAN FD'} {[255 255 255 255 255 255 255 60]} 8 8 {0x0 struct} false false true false 75.399 sec 1201 false {0x0 char } {'CAN FD'} {[ 15 155 16 23 15 164 16 23]} 8 8 {0x0 struct} false false true false 75.399 sec 512 false {0x0 char } {'CAN FD'} {[ 2 125 1 213 2 129 128 255]} 8 8 {0x0 struct} false false true false 75.399 sec 513 false {0x0 char } {'CAN FD'} {[ 31 179 255 255 54 222 38 255]} 8 8 {0x0 struct} false false true false 75.399 sec 533 false {0x0 char } {'CAN FD'} {[ 2 168 2 168 2 42 35 0]} 8 8 {0x0 struct} false false true false 75.4 sec 1312 false {0x0 char } {'CAN FD'} {[ 250 0 200 50 0]} 5 5 {0x0 struct} false false true false 75.405 sec 1200 false {'WheelSpeeds'} {'CAN FD'} {[ 54 173 55 41 54 180 55 40]} 8 8 {1x1 struct} false false true false 75.406 sec 1201 false {0x0 char } {'CAN FD'} {[ 15 157 16 25 15 164 16 24]} 8 8 {0x0 struct} false false true false 75.408 sec 1296 false {0x0 char } {'CAN FD'} {[ 39 0 1]} 3 3 {0x0 struct} false false true false ans = 15x4 timetable Time RR_WSpeed RF_WSpeed LR_WSpeed LF_WSpeed __________ _________ _________ _________ _________ 75.397 sec 41.19 40.04 41.19 39.95 75.405 sec 41.2 40.04 41.21 39.97 75.414 sec 41.22 40.05 41.26 40.03 75.424 sec 41.25 40.13 41.3 40.05 75.433 sec 41.19 40.14 41.28 40.08 75.441 sec 41.17 40.18 41.31 40.14 75.45 sec 41.31 40.27 41.31 40.17 75.458 sec 41.37 40.25 41.31 40.19 75.466 sec 41.39 40.22 41.3 40.19 75.475 sec 41.39 40.25 41.3 40.2 75.483 sec 41.37 40.26 41.33 40.21 75.492 sec 41.44 40.35 41.33 40.19 75.501 sec 41.51 40.44 41.36 40.22 75.509 sec 41.58 40.47 41.44 40.29 75.517 sec 41.63 40.45 41.44 40.31

MathWorks CAN FD virtual channels were used for this example. You can however connect your models to other supported hardware.