Clear Filters
Clear Filters

call dpigen for simulink model through a unix command line

2 views (last 30 days)
Is there some way to generate the C++/DPI code of a simulink model without using the graphical interface ? I need this in order to run the whole generation in batch mode.

Answers (1)

Bhanu Prakash
Bhanu Prakash on 29 Dec 2023
Hi Krishnan,
I understand that you want to generate C++/DPI code of a Simulink model from the UNIX command line.
Please note that the function ‘dpigen’ is used to generate SystemVerilog DPI component from a MATLAB function/code but not from a Simulink model.
In order to generate the C++ code of a Simulink model, kindly follow the workflow mentioned below:
  • Create a MATLAB script to open the Simulink model and generate the C++ code. Consider the code below:
modelName = 'Model_Name'; % Replace with your actual model name
load_system(modelName);
% Set up the model configuration for C++ code generation
% Add any necessary configuration settings here
set_param(modelName, 'TargetLang', 'C++');
set_param(modelName, 'GenCodeOnly', 'on');
% Generate C++ code
slbuild(modelName);
For more information on the ‘slbuild’ function, kindly refer to the following documentation:
  • To run any MATLAB function from the UNIX command line, MATLAB must be present in the system’s PATH. You can add MATLAB to the system PATH by entering the following command in the UNIX command line:
export PATH=$PATH:<path_to_MATLAB_bin>
  • Verify the addition of MATLAB to the system PATH by entering the following command in the UNIX command line:
matlab
  • Run the MATLAB script, from step-1, using the following command:
matlab -batch "run('path_to_MATLAB_script’)"
You can observe that a new folder (containing the C++ code) is created in the directory, where the MATLAB script is present.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!