Main Content

Author and Extend Functions for Software Architectures

A function is an entry point that can be defined in a software component. For inline components, you can author functions in the architecture level using the Functions Editor or by using the addFunction function. You can then implement Simulink® behaviors for your authored functions.

For reference components, the functions are automatically created from the referenced behavior Simulink models. For information, see Simulate and Deploy Software Architectures.

In this topic, we explain the workflow to create functions in the architecture level and describe how to:

  • Author and visualize functions.

  • Implement behaviors for the functions.

  • Import and export functions.

  • Add custom properties to functions using stereotypes.

Author and Visualize Functions Using Functions Editor

You can apply stereotypes to functions in software architectures, edit sample times, and specify the function period using the Functions Editor.

The Functions Editor is visible only when you model software architectures. To open the Functions Editor, in the toolstrip, navigate to Modeling > Functions Editor. The model automatically updates, and the table displays the functions of components in your model.

This example shows a software architecture with two components and the Functions Editor with an empty table.

Software architecture with two components named Component1 and Component2. The Functions Editor is at the bottom of the canvas

To author functions and sort them based on the order of execution:

  1. Add a function. Select Component1 as the parent. Use the same steps to add a function for Component2.

    The Add a function to a software component button is highlighted in the Functions Editor. A function named Component1_Function displays for Component1. A function named Component2_Function displays for Component2.

  2. Arrange the execution order of the functions by using the up and down arrows or clicking and dragging functions to sort them.

    The up and down arrows in the Functions Editor are highlighted in a red box.

  3. You can change the name of these functions by modifying the name in the table. Change the name of the first function to myFunction.

    The Function Name column in the Functions Editor shows that the first function name has been changed to myFunction.

  4. You can edit sample times of these functions by specifying their period in the table. Change the period of the first function to 1.

    A software architecture with three components: Component1, Component2, and Component3. Component3 is linked to a Simulink behavior. The Functions Editor shows the difference between three functions

  5. You can order functions automatically based on their data dependencies. This functionality is available for functions from behavior models. To enable automatic sorting, select the Order functions by dependency check box or enable OrderFunctionsByDependency on the architecture model.


    The default value for the parameter is off.

The Functions Editor visualizes the functions created at the architecture level and the functions implemented in a Simulink model that is referenced by a component.

In this example, a third function is created in a Simulink behavior model, and the model is referenced by a third component, Component3. The Software Component column of the table shows the difference between functions created at the architecture level and functions created in a Simulink behavior and referenced by a component.

A software architecture with three components: Component1, Component2, and Component3. Component3 is linked to a Simulink behavior. The Functions Editor shows the difference between three functions.

Author Functions Programmatically

You can also author functions for your components using the addFunction function.

Use the addFunction function to add a set of functions to the software architecture component, architecture with specified names functionNames.


For more information, see addFunction.

Implement Behaviors for Functions in the Architecture Level

You can create functions in the architecture level, and then implement behaviors for your functions.

  • To implement functions using the toolstrip:

    1. Under the Modeling tab, select Component, and select Create Simulink Behavior.

    2. Select the Type of the Simulink behavior as rate-based or export-function.

      Create Simulink Behavior dialog box that displays the type of the behavior.

      Alternatively, you can right-click a component and select Create Simulink Behavior.

  • You can also use the createSimulinkBehavior function to implement functions programmatically. The function creates a new rate-based or export-function behavior and links the software component to the new model. You can create rate-based or export-function behaviors only for software architectures.


Apply Stereotypes to Functions of Software Architectures

You can extend software architecture functions by adding stereotypes containing custom properties. These steps describe how to add stereotypes to your functions and are very similar to the steps to add stereotypes to other architectural elements. For more information, see Apply Stereotypes to Extend Model Elements.

  1. Define your function stereotypes using the Profile Editor.

    The Profile Editor shows a list of stereotype properties

  2. Use the Functions Editor to select functions in your software component, apply stereotypes, view the stereotypes applied to your functions, and edit the stereotype property values.

    In this example, you can specify the value for the FunctionValue property of the stereotype called FunctionStereotype using the Property Inspector.

    A Component is highlighted. The Functions Editor displays the selected function. The Property Inspector displays the value to be modified

Import and Export Functions of Software Architectures

You can import and export functions of your software architectures.

  • Use the systemcomposer.exportModel function to output a functions field that contains a table with information such as the name, execution order, parent component ID, period, and stereotypes of a function.

    This example shows how to export a software architecture model mySoftwareArchitecture. The exportedSet output has the functions field that contains the table with function information.

    exportedSet = systemcomposer.exportModel('MySoftwareArchitecture')
    exportedSet = 
      struct with fields:
              components: [4×5 table]
                   ports: [6×4 table]
             connections: [3×5 table]
          portInterfaces: [0×9 table]
        requirementLinks: [0×15 table]
                  domain: 'Software'
               functions: [3×4 table]
    >> exportedSet.functions
    ans =
      3×4 table
                Name             ExecutionOrder    CompID    Period
        _____________________    ______________    ______    ______
        "myFunction"                  "1"           "1"      "1"   
        "Component2_Function"         "2"           "2"      "-1"  
        "Component3_D1"               "3"           "3"      "0.2" 
  • Use the systemcomposer.importModel function to import a model with functions where the importStruct argument can have a functions field that contains function information.

See Also




Related Topics