How do I programmatically view properties of custom storage classes for Embedded Coder?

I want to read out attributes from Embedded Coder custom storage classes (i.e., the header file, definition file, structure name, etc.) in MATLAB R2022a. I am currently using the 'cscdesigner' GUI to do this. Is there an API to get the attributes programmatically?

 Accepted Answer

To programmatically view custom storage class attributes, you can use dot indexing to access ‘Simulink.CoderInfo’ properties. For example, for a Simulink signal ‘mysignal’, you can access information such as ‘mysignal.CoderInfo.StorageClass’ or ‘mysignal.CoderInfo.CustomAttributes.HeaderFile’. For more information on this, you can refer to the documentation below:
Alternatively, you can use the Embedded Coder Dictionary API. You can use ‘coder.Dictionary.Section’ objects to access information about dictionary sections such as storage classes. To access information from a 'coder.Dictionary' object, you can use the command ‘getSection()’ to retrieve the storage classes contained in the coder dictionary, for example:
storageClasses = getSection(codeDictionary,'StorageClasses');
entries = find(storageClasses);
entries.Name
Executing the above will display a list of the available storage class names. Say that one of these was 'ExportToPrivateHeader'. You can subsequently pull information about the storage class by using the ‘getEntry()’ command, as shown below:
exportToPrivateH = getEntry(storageClasses,'ExportToPrivateHeader')
Executing the command:
getAvailableProperties(exportToPrivateH)
will display the available properties that can be retrieved. Say, for example, one of these properties was 'HeaderFile'. You could then retrieve the header file by executing the following command:
hf = get(exportToPrivateH,'HeaderFile')
For more information on using the Embedded Coder Dictionary API to access code generation and storage class information, you can review the documentation and example below:

More Answers (0)

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!