CAN message in simulink

1 view (last 30 days)
shiyad A
shiyad A on 20 Mar 2020
Answered: Harimurali on 7 Feb 2024
hi,
I am facing a problem that How i can load base workbase message to my simulink vehicle network toolbox block CAN -transmit

Answers (1)

Harimurali
Harimurali on 7 Feb 2024
Hi Shiyad,
The "From Workspace" block and the "CAN Pack" blocks can be used to load base workspace message to be used by the "CAN Transmit" block. Follow the below steps to do the same:
  • Store the data to be transmitted as part of the CAN message in a variable in the base workspace. The data should be in a format that the "From Workspace" block supports.
%For example
Data = [1 2 3 4 5 6 7 8];
% Create a time-structured data for the 'From Workspace' block
message_ts = struct('time', 0, 'signals', struct('values', Data));
  • Add "From Workspace" and specify the "message_ts" variable that is to be read from the workspace.
  • Connect the "From Workspace" block to the "CAN pack".
  • Specify the message name, CAN identifier, length etc. of the message in the block parameters dialog box of the "CAN Pack" block. The length specified should be equal to the number of data elements.
In this way you can transmit data from the base workspace as a CAN message in Simulink.
Refer the following documentations for information about:
  1. "From Workspace" block: https://www.mathworks.com/help/releases/R2023b/simulink/slref/fromworkspace.html
  2. "CAN Pack" block: https://www.mathworks.com/help/releases/R2023b/vnt/ug/canpack.html
  3. "can.Message" object properties: https://www.mathworks.com/help/releases/R2023b/vnt/ug/can.message-properties.html

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!