Programmatic equivalent to C/C++ Code->Generate S Function

I am trying to compile library blocks into s-functions as a method of protecting IP in a library. If I right click and select C/C++ Code->Generate S Function, it produces exactly what I want, but there are many blocks to do, so I am trying to do the equivalent programatically.
I have found all of the subsystems to be converted, and passed those to slbuild, but it gives an error:
"Error using coder.build.internal.buildSubsystem. Each model must have 1 target block."
Is there an equivalent command to the Generate S Function gui command? Thanks!

답변 (1개)

Vandit
Vandit 2023년 6월 27일
Hi,
Once you have identified the subsystems you want to convert into S-Functions, you can iterate through each subsystem and use the 'slbuild' function to generate the S-Function for that subsystem. But before using 'slbuild', you have to check if the top-level model (the model you want to build) has multiple target blocks.
You can refer to the below code in order to implement above steps :
topModel = 'YourModel'; % Replace 'YourModel' with the name of your actual top-level model
targetBlocks = find_system(topModel, 'SearchDepth', 1, 'BlockType', 'Terminator');
if numel(targetBlocks) > 1
disp(['Model: ' topModel ' has multiple target blocks.']);
else
subsystems = find_system(topModel, 'SearchDepth', 1, 'BlockType', 'SubSystem');
for i = 1:numel(subsystems)
currentSubsystem = subsystems{i};
try
slbuild(currentSubsystem);
catch exception
disp(exception.message);
end
end
end
If your top-level model has multiple target blocks, you will need to handle it accordingly. You can either remove the extra target blocks or select one specific block to be the target block.
To know more about 'slbuild'you may refer to the below link:
Hope this helps.
Thankyou

카테고리

도움말 센터File Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

질문:

2023년 6월 13일

답변:

2023년 6월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by