Get Started Accessing ARXML Files in Simulink for CAN Communication
This example shows how to use ARXML files with the CAN Pack and CAN Unpack blocks. These files should contain a valid CAN network description.
Create and Configure the Model
Create a model such as represented in the figure. In this model, MathWorks virtual channels are used, and connected in a loopback configuration.
Use the CAN Pack block to encode and pack before transmission two signals that represent the speed and the applied braking force of a vehicle. To that end, use the definitions in the simple ARXML file which is provided with the example. Open the mask of the CAN Pack block, select the option 'ARXML specified signals' for the 'Data is input as' parameter. Then, to update the 'Database file' field, select the file 'small_file.arxml' via the Browse button, and click 'Apply'. The 'Signals' table is updated, as well as the input ports of the block, based on the content of the only frame (Frame_A) defined in the file. In case multiple CAN frames are defined in an ARXML file, their names would appear in the drop-down menu 'Name' within the 'Message' pane.
Proceed in a similar way to configure the CAN Unpack block. This block should then be placed in a function-call subsystem, and function calls are provided by the CAN Receive block connected to it; this way, all the frames received will be unpacked. (Note that, without controlling the execution of CAN Unpack with a function call, at each simulation timestep the block would unpack only the most recent frame received by the CAN Receive block.)
Connect source blocks to the inputs of CAN Pack, and scope or display blocks to the output of CAN Unpack, as shown in the figure.
Run the Simulation
Run the simulation to verify the propagation of the signal values through the loopback connection. Experiment with input values, whose range and precision are limited according to the definitions contained in the ARXML file, and summarized in the 'Signals' table. For instance, Vehicle_Speed is non-negative, has an upper bound of 255, and since it is represented over 8 bits the smallest possible increment is 1.