Replay logged CAN messages
Vehicle Network Toolbox / CAN Communication
The CAN Replay block replays logged messages from a
.mat file to a CAN
network or to Simulink®. You need a CAN Configuration block to replay to the network.
To replay messages logged in the MATLAB® Command window in your Simulink model, convert them into a compatible format using
canMessageReplayBlockStruct and save the result to a separate file. For more
information, see Log and Replay CAN Messages.
You need a license for both Vehicle Network Toolbox™ and Simulink software to use this block.
When you replay logged messages, Simulink uses the original timestamps on the messages. When you replay to a network,
the timestamps correlate to real time, and when you replay to the Simulink input port it correlates to simulation time. If the timestamps in the messages
0, all messages are replayed as soon as the simulation starts,
because simulation time and real time will be ahead of the timestamps in the replayed
Other Supported Features
The CAN Replay block supports the use of Simulink Accelerator™ Rapid Accelerator mode. Using this feature, you can speed up the execution of Simulink models.
For more information on this feature, see the Simulink documentation.
The CAN Replay block supports the use of code generation along with the packNGo function to group required source code and dependent shared libraries. For more information, see Code Generation.
Vehicle Network Toolbox Simulink blocks allow you to generate code, enabling models containing these blocks to run in Accelerator, Rapid Accelerator, External, and Deployed modes.
You can use Vehicle Network Toolbox, Simulink Coder™, and Embedded Coder® software together to generate code on the host end that you can use to implement your model. For more information on code generation, see Build Process (Simulink Coder).
The block generates code with limited portability. The block uses
precompiled shared libraries, such as DLLs, to support I/O for
specific types of devices. With this block, you can use the
packNGo function supported by Simulink
Coder to set up and manage the build information for your
packNGo (Simulink Coder) function
allows you to package model code and dependent shared libraries into
a zip file for deployment. You do not need MATLAB installed on the target system, but the target system
needs to be supported by MATLAB.
To set up
In this example,
gcs is the current model that you
want to build. Building the model creates a zip file with the same
name as model name. You can move this zip file to another machine
and there build the source code in the zip file to create an
executable which can run independent of MATLAB and Simulink. The generated code compiles with both C and C++
compilers. For more information, see Build Process Customization (Simulink Coder).
On Linux® platforms, you need to add the folder where
you unzip the libraries to the environment variable
CAN Msg — Replayed CAN messages
This output port contains a packed CAN message logged at that particular timestep,
output as a
CAN_MESSAGE or signal bus of type
f() — Function-call event output
This port provides a trigger to a Function-Call subsystem when the block receives a new message. You can connect it to a Function-Call Subsystem (Simulink) to unpack and process the message.
Configure your CAN Configuration block before you configure the CAN Receive block parameters.
File name — Path and name of MAT-file with messages
untitled.mat (default) | file name
Specify the name and path of the file that contains logged CAN messages that you can replay. You can click Browse to browse to a file location and select the file.
Variable name — Variable in MAT-file holding messages
ans (default) | variable
Specify the variable saved in the MAT-file that holds the CAN message information.
Number of times to replay messages — Repeat value
Inf (default) | integer
Specify the number of times you want the message replayed in your model. You can
specify any positive integer, including
Inf continuously replays messages until simulation stops.
Replay messages to — Specify output location
CAN Bus (default) |
Specify if the model is replaying messages to the CAN network or an output port. When replaying to the CAN network, you must also select a Device.
Device — CAN device and channel
device list option
Select the device on the CAN network to replay messages to. This field is
unavailable if you select
Output port for the Replay
message to parameter.
Sample time — Block execution rate
0.01 (default) | numeric
Specify the sampling time of the block during simulation. This value defines the
frequency at which the CAN Replay block runs during simulation. If the
block is inside a triggered subsystem or to inherit sample time, you can specify
–1 as the sample time. You can also specify a MATLAB variable for sample time. The default value is
simulation seconds. For more information, see Timing in Hardware Interface Models.
Output as bus — Enable signal bus output
off (default) | on
Select this option for the block to output CAN messages as a Simulink bus signal. For more information on Simulink bus objects, see Composite Interfaces (Simulink).
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
This block generates code with limited portability that runs only on the host computer. See Code Generation.
Introduced in R2011b