Store Data in Architectural Data Section Programmatically
The Architectural Data section of a Simulink® data dictionary enables interfaces, data types, and constants to be authored, managed, and shared between components and compositions modeled in Simulink. The Architectural Data section provides scalability for system-level and multicomponent designs by containing these shared elements in a central location.
You can programmatically configure architectural data and apply your changes to your model using this basic workflow:
Create or open a data dictionary.
Design interfaces, data types, and constants with the
Simulink.dictionary.ArchitecturalData
programmatic interfaces.Link the data dictionary containing architectural data to a Simulink or architecture model.
Apply architectural data to a model programmatically.
Create or Open Simulink Data Dictionary Programmatically
To create a new data dictionary, use the
Simulink.dictionary.archdata.create
function.dictName = "MyInterfaces.sldd"; archDataObj = Simulink.dictionary.archdata.create(dictName);
To open an existing data dictionary use the
Simulink.dictionary.archdata.open
function.archDataObj2 = Simulink.dictionary.archdata.open("OtherDictionary.sldd");
These functions return Architectural Data objects that you can edit using the Simulink.dictionary.ArchitecturalData
programmatic interfaces.
Design Data Types, Interfaces, and Constants Programmatically
To programmatically create, configure, and manage architectural data in your data dictionary, use the programmatic interfaces for the
Simulink.dictionary.ArchitecturalData
object.dictName = "myDataDictionary.sldd"; archDataObj = Simulink.dictionary.archdata.create(dictName);
Use type-specific functions to add alias types and enumerations to the data dictionary.
myAliasType1Obj = addAliasType(archDataObj,... "aliasType",BaseType="single"); myAliasType1Obj.Name = "myAliasType1"; myAliasType1Obj.BaseType = "fixdt(1,32,16)"; myAliasType2Obj = addAliasType(archDataObj,"myAliasType2"); myAliasType2Obj.BaseType = myAliasType1Obj; myEnumType1Obj = addEnumType(archDataObj,"myColor"); myEnumType1Obj.DefaultValue = "BLUE"; myEnumType1Obj.Description = "I am a Simulink Enumeration"; myEnumType1Obj.StorageType = "int16";
You can set the base type of the created alias type to be the created enumeration data type
myColor
.myAliasType3Obj = addAliasType(archDataObj,"myAliasType3"); myAliasType3Obj.BaseType = myEnumType1Obj;
Use the
addNumericType
function to add numeric types to the data dictionary.myNumericType1Obj = addNumericType(archDataObj,"myNumericType1"); myNumericType1Obj.DataTypeMode = "Single";
Use the
addValueType
to add value types to the data dictionary. You can also set the data type of the value types to be pre-existing data types or created enumeration data types.myValueType1Obj = addValueType(archDataObj,"myValueType1"); myValueType1Obj.DataType = 'int32'; myValueType1Obj.Dimensions = '[2 3]'; myValueType1Obj.Description = "I am a Simulink ValueType";
Use the
addStructType
function to add struct types to the data dictionary.myStructType1Obj = addStructType(archDataObj,"myStructType1"); structElement1 = myStructType1Obj.addElement("Element1"); structElement1.Type.DataType = 'single'; structElement1.Type.Dimensions = '3'; structElement2 = addElement(myStructType1Obj,"Element2"); structElement3 = addElement(myStructType1Obj,"Element3");
You can set the data type of a struct element by using the data type object or by using the name of the data type, specified as a string scalar or character vector.
structElement2.Type = myValueType1Obj; % or structElement3.Type = "ValueType: myValueType1";
You can add constants using the
addConstant
function.myConstantObj = addConstant(archDataObj, "myConst", Value=4);
You can add communication interfaces and their data elements using the functions of the
Simulink.dictionary.archdata.DataInterface
object.nvInterface1 = addDataInterface(archDataObj,"NV1"); dataElm1 = addElement(nvInterface1,"DE1"); dataElm1.Type = myValueType1Obj; dataElm2 = addElement(nvInterface1,"DE3"); dataElm2.Type.DataType = 'single'; dataElm2.Type.Dimensions = '10'; dataElm2.Type.Minimum = '-5'; srInterface2 = addDataInterface(archDataObj,"SR1");
Link a Data Dictionary Programmatically
To link a dictionary to a model programmatically use the linkDictionary
(System Composer) function.
Create or open a Simulink data dictionary. In this example you create a new data dictionary
MyInterfaces.sldd
.dictName = "MyInterfaces.sldd"; archDataObj = Simulink.dictionary.archdata.create(dictName);
Create a System Composer model and extract its architecture.
model = systemcomposer.createModel("myTopComposition_archdata"); archModel = Model.Architecture;
Add a physical interface and a physical element to the Architectural Data section of the data dictionary.
physicalInterface = addPhysicalInterface(archDataObj,... "PhysicalInterface"); physicalElement = addElement(physicalInterface,"ElectricalElement",... Type="electrical.electrical");
Link the data dictionary to the model.
linkDictionary(model,dictName);
For more information regarding System Composer architecture models, see Build Architecture Models Programmatically (System Composer).
Apply Data Changes Programmatically
Once your data dictionary is linked to an architecture model, you can apply the
changes to your modeled application programmatically by using the Simulink.dictionary.ArchitecturalData
object.
Here, you can add components, ports, and connections to your architecture model. Set the interface of the added component using the physical interface added to the data dictionary in section Link a Data Dictionary Programmatically.
Create or open a Simulink data dictionary. In this example you create a new data dictionary
MyInterfaces.sldd
.dictName = "MyInterfaces.sldd"; archDataObj = Simulink.dictionary.archdata.create(dictName);
Create a System Composer model and extract its architecture.
model = systemcomposer.createModel("myTopComposition_archdata"); archModel = Model.Architecture;
Add a component and a port to the architecture model. You can set the interface type using the physical interface object created a previous section.
componentSensor = addComponent(ArchModel,"Sensor"); sensorPorts = addPort(componentSensor.Architecture,... {'MotionData','SensorPower'},{'in','physical'}); sensorPorts(2).setInterface(physicalInterface)
You can also add a data interface and port.
srInterface2 = addDataInterface(archDataObj,'SR1'); pport = archModel.addPort("Sender", 'PPort'); setInterface(pport,srInterface2);
See Also
Simulink.dictionary.ArchitecturalData
| autosar.dictionary.ARClassicPlatformMapping
(AUTOSAR Blockset) | exportDictionary
(AUTOSAR Blockset) | getPlatformProperties
(AUTOSAR Blockset) | getPlatformProperty
(AUTOSAR Blockset) | setPlatformProperty
(AUTOSAR Blockset) | Simulink.dictionary.archdata.create
| Simulink.dictionary.archdata.open
Related Topics
- Store Shared Data in Architectural Data Section
- Build Architecture Models Programmatically (System Composer)
- Programmatically Manage AUTOSAR Architectural Data (AUTOSAR Blockset)