Create Variant object based on Configuration Reference

2 visualizaciones (últimos 30 días)
Jonas
Jonas el 26 de Mayo de 2021
Editada: Jonas el 1 de Jun. de 2021
Hi all
I have a structure of models and model references, which all use the very same Configuration Reference object as their Configuration Parameters set. By changing the Configuration Reference, I can change the Configuration Parameters for all models at once. This Configuration Reference object and those Configuration Parameter sets are located inside a Data Dictionary, to which all models have access to.
I am using Variant Subsystems inside my models, and I want to make those variants based on which selection I make in the Configuration Reference object. (To which Configuration Parameter set I am pointing it to basically.) So I wanted to create a Simulink.Variant object, and as a condition I want to make a check of the Configuration Reference. For example, I want to see if the 'SystemTargetFile' is equal to 'ert.tlc'.
The problem I am having is how to write an expression for the Simulink.Variant object to get info from the Configuration Reference object?
I have used the following expression succesfully before:
strcmp('ert.tlc',get_param('mymodel','SystemTargetFile'))
but it requires to provide the model name as an argument. Since I need to use this Simulink.Variant object for all my models, I cannot provide the model name since it will be different many times.
I have tried the following expression:
strcmp('ert.tlc',get_param(Configuration_set,'SystemTargetFile'))
but it cannot find the Configuration Reference object called 'Configuration_set', although the Variant object and the Configuration Reference object are inside the same Data Dictionary.

Respuesta aceptada

Donn Shull
Donn Shull el 31 de Mayo de 2021
Your variant expression cannot find your configuration object because variant object and the configuration object are in different Dictionary sections.
You could trysomething messy like storing a string with the name of your data dictionary in the 'Design Data' section:
thisDataDictionary = 'MyDataDictionary.sldd'
Then use an expression like
strcmp('grt.tlc', get_param(Simulink.data.dictionary.open(thidDataDictionary).getSection('Configurations').getEntry('Configuration_set').getValue, 'SystemTargetFile'))
  2 comentarios
Jonas
Jonas el 1 de Jun. de 2021
Editada: Jonas el 1 de Jun. de 2021
Thank you for your suggestion, Donn. I hard-coded the name of the Data Dictionary where the Configurations are located, since it will not change. I then executed the following:
strcmp('ert.tlc',get_param(Simulink.data.dictionary.open('global.sldd').getSection('Configurations').getEntry('Configuration').getValue,'SystemTargetFile'))
where 'global.sldd' is my Data Dictionary with all Configuration sets and also the Configuration Reference object.
It throws the following error:
Unable to get parameter "SystemTargetFile".
Caused by:
Unable to find configuration: 'Embedded' referenced by 'Configuration'.
This error surprises me, since 'Embedded' is the name of the Configuration the Configuration Reference is pointing to. So it knows the name of where it points to, but cannot seem to find it. But the Configuration sets are all located right next to the Configuration Reference object:
I was thinking to instead of grabbing the 'SystemTargetFile' value, I could also just grab the name of the Configuration set the Configuration Reference is pointing to. It contains the same information. Because from the error above, it knows it points to 'Embedded', it just cannot find the Configuration set itself. I could change my Variant Subsystems based on if the Reference points to 'Embedded' or to 'Simulation' for example.
I will try to see if I can find a command which returns this. Up till now the documentation on 'Simulink.ConfigSetRef' doesn't teach me more.
Jonas
Jonas el 1 de Jun. de 2021
Editada: Jonas el 1 de Jun. de 2021
Hi Donn, I found a command which can return the name of the Configuration set the Configuration Reference points to:
get_param(Simulink.data.dictionary.open('global.sldd').getSection('Configurations').getEntry('Configuration').getValue,'SourceName')
It returns 'Embedded'.
So I can use the following expression as a Variant expression:
strcmp('Embedded',get_param(Simulink.data.dictionary.open('global.sldd').getSection('Configurations').getEntry('Configuration').getValue,'SourceName'))
to activate the variant for Embedded Code Generation.
Thank you very much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Manage Variant Modeling Components en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by