Azzera filtri
Azzera filtri

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

10 visualizzazioni (ultimi 30 giorni)
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!

Risposte (1)

Vandit
Vandit il 27 Giu 2023
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

Categorie

Scopri di più su Simulink Coder in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by