This example shows how to use MathWorks virtual CAN channels to set up transmission and reception of CAN messages in Simulink. The virtual channels are connected in a loopback configuration.
Vehicle Network Toolbox provides Simulink blocks for transmitting and receiving live messages via Simulink models over networks using the Controller Area Network (CAN) format. This example uses the CAN Configuration, CAN Pack, CAN Transmit, CAN Receive, and CAN Unpack blocks to perform data transfer over a CAN bus.
Create a model to transmit and receive a CAN message carrying a sine wave data signal. The model transmits a single message per timestep. A DBC-file defines the message and signal used in the model.
The CAN Receive block generates a function-call trigger if it receives a new message at any particular timestep. This indicates to other blocks in the model that a message is available for decoding activities. Signal decoding and processing is performed inside the Function-Call Subsystem (Simulink).
Plot the sine wave values before and after transmission. The X-axis corresponds to the simulation timestep and the Y-axis corresponds to the value of the signal. The phase shift between the two plots represents the propagation delay as the signal travels across the network.
This example uses MathWorks virtual CAN channels. You can connect your models to other supported hardware. You can also modify the model to transmit at periodic rates.