Main Content

getFunction

Get code configuration from code mappings for model function

    Description

    propertyValue = getFunction(myCPPMappingObj,methodID,property) returns the value of a property for the specified model function.

    example

    Examples

    collapse all

    Open the model. To access the CodeMappingCPP object associated with the model, use the coder.mapping.api.get function.

    open_system('CppClassRateBased');
    cm = coder.mapping.api.get('CppClassRateBased');

    To access the method name of the initialize function for the model, use the getFunction function. If you did not specify a method name for the initialize function, getFunction returns an empty character vector, and the method name in the generated code uses the default method name.

    value = getFunction(cm, 'Initialize', 'MethodName')
    value = 
    'initIntegrator'
    

    Specify a method name for the initialize function by using the setFunction function.

    setFunction(cm, 'Initialize', 'MethodName', 'my_$N')

    The getFunction function now returns the specified method name.

    value = getFunction(cm, 'Initialize', 'MethodName')
    value = 
    'my_$N'
    

    Input Arguments

    collapse all

    C++ code mapping object, returned by a call to either the coder.mapping.utils.create function or the coder.mapping.api.get function.

    The identifier of the model method to get the code mappings property value of, specified as one of the values in the table.

    Type of Model MethodMethod Identifier
    Initialize method

    "Initialize"

    Terminate method

    "Terminate"

    Reset method

    "Reset:slIdentifier", where slIdentifier is the name of the reset method in the model

    Periodic method

    "Periodic:slIdentifier", where slIdentifier is an annotation that corresponds to the sample time period for a periodic or continuous rate

    Example: "Periodic:D1"

    Tip

    For a single-tasking periodic method, you can use "Periodic" without :slIdentifier.

    Periodic update method

    "PeriodicUpdate:slIdentifier", where slIdentifier is an annotation that corresponds to the sample time period for a periodic or continuous rate

    Example: "PeriodicUpdate:D1".

    Tip

    For a single-tasking periodic update method, you can use "PeriodicUpdate" without :slIdentifier.

    Partition method

    "Partition:slIdentifier", where slIdentifier is a partition that was created explicitly from a block in the model and shown in the Simulink® Schedule Editor

    Example: "Partition:P1"

    Partition update method

    "PartitionUpdate:slIdentifier", where slIdentifier is a partition created explicitly from a block in the model and shown in the Simulink Schedule Editor

    Example: "PartitionUpdate:P1"

    Simulink function

    "SimulinkFunction:slIdentifier", where slIdentifier is the name of the Simulink function in the model

    Exported method

    "ExportedFunction:slIdentifier", where slIdentifier is the name of the Inport block that drives the control port of the function-call subsystem, or the name of the port if it is driven by an In Bus Element block

    Tip

    When the configuration parameter Single output/update function is cleared, you can specify the update method that corresponds to a partition, periodic multitasking, or periodic single-tasking method. For more information about generating code with a single method for both update and output, see Single output/update function.

    For information about model partitioning, see Create Partitions. To learn more about annotations and sample time information, see Specify Sample Time. To learn how to programmatically obtain sample time information, see simulink.schedule.OrderedSchedule.

    Code mapping property value to return. Specify one of the property names listed in this table.

    Information to ReturnProperty Name
    Name to use for the method in the generated codeMethodName
    For periodic, single-tasking functions and Simulink functions, a string that shows the block names, argument names, type qualifiers, and order of arguments as they will appear in the generated code Arguments

    Example: 'MethodName'

    Output Arguments

    collapse all

    Name of the function or argument specification returned as a character vector or string scalar.

    Data Types: char | string

    Version History

    Introduced in R2021a