Effacer les filtres
Effacer les filtres

Level-2 S-Function in Simulink subsystem

3 vues (au cours des 30 derniers jours)
David Gallarta
David Gallarta le 15 Jan 2021
I'm working with a Level-2 S-Function in a Simulink subsystem and I would like to configure some parameters (IP, sample time) from the subsystem mask so that I don't have to edit the Matlab code on every change, defining them into the S-Function as a variable. How can these parameters be passed to the S-Function?
The error I get is: "Cannot access data in 'simulink_pr/Subsystem/ '. The probable cause of this error is accessing data that is available only when simulation is running"
Thank you very much

Réponses (1)

Anshuman
Anshuman le 20 Juin 2024
Hello,
To configure parameters such as IP address and sample time from a Simulink subsystem mask into a Level-2 MATLAB S-Function, you need to use mask parameters. These mask parameters allow you to change the S-Function's behavior without modifying the MATLAB code directly for each change.
  1. Open your Simulink model and navigate to the subsystem that contains your S-Function.
  2. Right-click on the subsystem block and select Mask -> Create Mask.
  3. In the Mask Editor, go to the Parameters & Dialog tab.
  4. Add parameters that you want to pass to the S-Function, such as IP address and sample time. Set the Name, Type, and Prompt for each parameter. The 'Name' is used in the MATLAB code to access the parameter value.
In your Level-2 MATLAB S-Function, you can access these parameters using the 'Simulink.Parameter' object or directly within the S-Function code.
blockIP = get_param(block.BlockHandle, 'ip_parameter_name');
blockSampleTime = str2double(get_param(block.BlockHandle, 'sample_time_parameter_name'));
After retrieving the parameters, you can use these values throughout your S-Function.

Catégories

En savoir plus sur Block and Blockset Authoring dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by