call dpigen for simulink model through a unix command line

1 次查看(过去 30 天)
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.

回答(1 个)

Bhanu Prakash
Bhanu Prakash 2023-12-29
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!

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by