Programmatically read the definitions of a custom storage class in a custom package

6 次查看(过去 30 天)
Hello,
I've been trying to programatically read the custom storage class definitions of a custom package.
My first issue is that I could not find any way to directly load my package CustomDataClass but I need to create a Simulink data dictionary and then an Embedded Coder dictionary where I can load my package.
dataDictionary = Simulink.data.dictionary.create('DataDictionary.sldd');
coderDictionary = coder.dictionary.create(dataDictionary);
coderDictionary.loadPackage('CustomDataClass');
Afterwards I found all my custom storage classes and loaded one of them CustomParameter
storageClasses = getSection(coderDictionary,'StorageClasses');
entry = getEntry(storageClasses, 'CustomParameter');
I wanted to get a specific property like the HeaderFile but
entry.get('HeaderFile')
returns 'HeaderFile' is not a valid property. and
entry.getAvailableProperties
only returns {'Name'} {'Description'} {'DataSource'} even if I open Custom Storage Class Designer I can see more available properties with values.
Is it even possible what I'm trying to achieve? Am I missing something?

采纳的回答

Abhas
Abhas 2024-5-24
Hi Andrei,
The get method and getAvailableProperties method limitations you're experiencing is beacuse all properties of a custom storage class are directly not accessible through the high-level API provided by coder.Dictionary objects. The getAvailableProperties method returns only {'Name'}, {'Description'}, and {'DataSource'}.
You can refer to the following documentation link to know more about the accessible properties: https://www.mathworks.com/help/ecoder/ref/coder.dictionary.entry-class.html
A viable workaround for accessing specific custom storage class properties that are not directly exposed through the coder dictionary API is:
Q = Simulink.Parameter;
Q.Value = int32(5);
Q.CoderInfo.StorageClass = 'Custom';
Q.CoderInfo.CustomStorageClass = 'Define';
Q.CoderInfo.CustomAttributes.HeaderFile=" " % You can specify the HeaderFile here
This method involves creating a Simulink.Parameter object (or similar), setting its storage class to your custom storage class, and then accessing the CustomAttributes field. This is more of a manual approach but can be effective for accessing or modifying properties not directly accessible through the coder dictionary entries.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by