Main Content

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:

  1. Create or open a data dictionary.

  2. Design interfaces, data types, and constants with the Simulink.dictionary.ArchitecturalData programmatic interfaces.

  3. Link the data dictionary containing architectural data to a Simulink or architecture model.

  4. Apply architectural data to a model programmatically.

Create or Open Simulink Data Dictionary Programmatically

These functions return Architectural Data objects that you can edit using the Simulink.dictionary.ArchitecturalData programmatic interfaces.

Design Data Types, Interfaces, and Constants Programmatically

  1. 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);
  2. 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"; 
  3. 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;
  4. Use the addNumericType function to add numeric types to the data dictionary.

    myNumericType1Obj = addNumericType(archDataObj,"myNumericType1");
    myNumericType1Obj.DataTypeMode = "Single";
  5. 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";
  6. 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");
  7. 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";
  8. You can add constants using the addConstant function.

    myConstantObj = addConstant(archDataObj, "myConst", Value=4);
  9. 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.

  1. 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);

  2. Create a System Composer model and extract its architecture.

    model = systemcomposer.createModel("myTopComposition_archdata"); 
    archModel = Model.Architecture;

  3. 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");
  4. 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.

  1. 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);

  2. Create a System Composer model and extract its architecture.

    model = systemcomposer.createModel("myTopComposition_archdata"); 
    archModel = Model.Architecture;

  3. 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)
    
  4. You can also add a data interface and port.

    srInterface2 = addDataInterface(archDataObj,'SR1');
    pport = archModel.addPort("Sender", 'PPort');
    setInterface(pport,srInterface2);

See Also

| (AUTOSAR Blockset) | (AUTOSAR Blockset) | (AUTOSAR Blockset) | (AUTOSAR Blockset) | (AUTOSAR Blockset) | |

Related Topics