Main Content

coder.asap2.Function

Create function object

    Description

    example

    userFunction = coder.asap2.Function() creates a function object. You can use the object to define new function description and export it to ASAP2 file.

    Examples

    collapse all

    This example shows how to add a custom function to the ASAP2 file.

    Create ECU Description Object

    Open a model, build, and create ECU description object.

    open_system("rtwdemo_asap2")
    rtwbuild("rtwdemo_asap2")
    ### Starting serial model reference code generation build.
    ### Successfully updated the model reference code generation target for: rtwdemo_asap2_mdlref
    ### Starting build procedure for: rtwdemo_asap2
    ### Successful completion of build procedure for: rtwdemo_asap2
    
    Build Summary
    
    Code generation targets built:
    
    Model                 Action                        Rebuild Reason                          
    ============================================================================================
    rtwdemo_asap2_mdlref  Code generated and compiled.  rtwdemo_asap2_mdlref.c does not exist.  
    
    Top model targets built:
    
    Model          Action                        Rebuild Reason                                    
    ===============================================================================================
    rtwdemo_asap2  Code generated and compiled.  Code generation information file does not exist.  
    
    2 of 2 models built (0 models already up to date)
    Build duration: 0h 0m 34.694s
    
    descObj=coder.asap2.getEcuDescriptions("rtwdemo_asap2")
    descObj = 
      Data with no properties.
    
    

    Create Custom Function

    Create a function object template and add the necessary fields.

    userFunction = coder.asap2.Function
    userFunction = 
      Function with properties:
    
                      Name: "undefined"
           FunctionVersion: [1x0 char]
            LongIdentifier: [1x0 char]
                Annotation: [1x0 char]
            InMeasurements: [1x0 string]
           OutMeasurements: [1x0 string]
           LocMeasurements: [1x0 string]
        DefCharacteristics: [1x0 string]
        RefCharacteristics: [1x0 string]
              SubFunctions: [1x0 string]
    
    
    userFunction.Name = 'Custom_Function1'
    userFunction = 
      Function with properties:
    
                      Name: 'Custom_Function1'
           FunctionVersion: [1x0 char]
            LongIdentifier: [1x0 char]
                Annotation: [1x0 char]
            InMeasurements: [1x0 string]
           OutMeasurements: [1x0 string]
           LocMeasurements: [1x0 string]
        DefCharacteristics: [1x0 string]
        RefCharacteristics: [1x0 string]
              SubFunctions: [1x0 string]
    
    
    userFunction.LongIdentifier = 'Custom Function by user'
    userFunction = 
      Function with properties:
    
                      Name: 'Custom_Function1'
           FunctionVersion: [1x0 char]
            LongIdentifier: 'Custom Function by user'
                Annotation: [1x0 char]
            InMeasurements: [1x0 string]
           OutMeasurements: [1x0 string]
           LocMeasurements: [1x0 string]
        DefCharacteristics: [1x0 string]
        RefCharacteristics: [1x0 string]
              SubFunctions: [1x0 string]
    
    

    Export the Function to ASAP2 File

    Add the function to ECU description object and generate ASAP2 file using the description object.

    add(descObj,userFunction)
    coder.asap2.export("rtwdemo_asap2",CustomEcuDescriptions=descObj)
    Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "rtwdemo_asap2_DW.rtwdemo_asap2_mdlref_InstanceDa"
    

    Output Arguments

    collapse all

    The function object that can be used to define a function and export it to ASAP2 file.

    Example: Custom_Function = coder.asap2.Function()

    Tips

    Table below shows the available fields in the Function object.

    ElementDescription
    NameName of the function
    LongIdentifierDescription or comment
    FunctionVersionVersion of the function
    AnnotationSet of notes represented as multi-line ASCII description texts
    InMeasurementsArray of input measurements
    OutMeasurementsArray of output measurements
    LocMeasurementsArray of local measurements
    DefCharacteristicsArray of defined characteristics
    RefCharacteristicsArray of referenced characteristics
    SubFunctionsArray of sub functions

    Version History

    Introduced in R2022b