Main Content

Customize Generated ASAP2 File

You can customize the fields of an ASAP2 file by using the code generator in any of these ways:

Customize ASAP2 Fields by Using Base Class

  1. Create an object from the base class.

    obj = coder.asap2.UserCustomizeBase;

  2. Modify the object fields.

    obj.HeaderComment = 'Header comment';
    obj.ModParComment = 'Mod Par comment';
    obj.ModCommonComment = 'Mod Common comment';
    obj.ASAP2FileName = 'File name';
    obj.ByteOrder = 'BYTEORDER MSB_LAST';

  3. Pass the object to the function that generates the ASAP2 file.


Customize ASAP2 Sections by Deriving from Base Class

  1. Derive from the base class coder.asap2.UserCustomizeBase. You can place the derived file anywhere on the MATLAB path.

  2. To edit the Header section, use the writeHeader function.

  3. Use the writeHardwareInterface function to edit the hardware interface section consisting of MOD_PAR and MOD_COMMON fields of the ASAP2 file.

  4. To add text at the beginning of the ASAP2 file, use the writeFileHead function.

  5. To add text at the end of the ASAP2 file, use the writeFileTail function.

    For example, the code for generating a derived class TestASAP2Customization might look like this code:

    classdef TestASAP2Customization < coder.asap2.UserCustomizeBase
        %   Customization class for asap2 file
            function header = writeHeader(obj)
                header = sprintf(['  /begin HEADER ' 'test Header text'  '\n',...
                    'header test comments from user\n',...
                    '  /end HEADER']);
            function hardwareInterface = writeHardwareInterface(obj)
                hardwareInterface = sprintf(['    /begin MOD_PAR "' 'UserDefined' '"\n',...
                    '      test comments from user\n',...
                    '    /end MOD_PAR\n\n',...
                    '    /begin MOD_COMMON "'  'UserDefined MOD_COMMON' '"\n',...
                    '      user defined values for MOD_COMMON\n',...
                    '     ' obj.ByteOrder '\n',...
                    '     /end MOD_COMMON']);
            function fileTail = writeFileTail(obj)
                fileTail = sprintf(['/* This File can be used for ' ,...
                    'calibration .*/\n'...
                    '/* EOF ',obj.ASAP2FileName, '*/']);
            function fileHeader = writeFileHead(obj)
                fileHeader = sprintf(['/******************************************************************************\n',...
                    ' This is a a2l file which can be used for calibration with INCA or CANAPE\n',...
                    ' ******************************************************************************/'

  6. Create an object from the derived class. For example, this command creates an object from TestASAP2Customization.

    obj = TestASAP2Customization;

  7. Pass the object to the function that generates the ASAP2 file.


Customize Computation Method Names

In generated ASAP2 files, computation methods translate the electronic control unit (ECU) internal representation of measurement and calibration quantities into a physical model oriented representation. Using Simulink® Coder™ software, you can customize the names of computation methods. You can provide names that are more intuitive, enhancing ASAP2 file readability, or names that meet organizational requirements.

To customize computation method names, use the MATLAB® function getCompuMethodName, which is defined in matlabroot/toolbox/rtw/targets/asap2/asap2/user/getCompuMethodName.m.

The getCompuMethodName function constructs a computation method name. The function prototype is

cmName = getCompuMethodName(dataTypeName, cmUnits)

where dataTypeName is the name of the data type associated with the computation method, cmUnits is the units as specified in the Unit property of a Simulink.Parameter or Simulink.Signal object (for example, rpm or m/s), and cmName returns the constructed computation method name.

The default constructed name returned by the function has the format



  • <local_Prefix> is a local prefix, CM_, defined in matlabroot/toolbox/rtw/targets/asap2/asap2/user/getCompuMethodName.m.

  • <datatype> and <cmUnits> are the arguments that you specified to the getCompuMethodName function.

Special characters used in cmUnits are not supported in the computation method name in ASAP2 file. The special characters are converted as shown in this table

Special CharacterConversion

For example, if you call the getCompuMethodName function with the dataTypeName argument 'int16' and the cmUnits argument 'm/s', and then generate an ASAP2 file for a model named myModel, the computation method name appears in the generated file as follows:

   /* Name of CompuMethod */ myModel_CM_int16_m_per_s
   /* Units */ "m/s"

Export Characteristics and Measurement Objects in Groups

Starting in release R2021b, you can group the characteristic and measurement objects in the ASAP2 file based on their properties. By default, the generated ASAP2 file contains GROUPS and SUB_GROUPS based on the subsystems present in the model.

  1. Open the sldemo_fuelsys model.


  2. Build the model.

  3. Generate the ASAP2 file by using Generate Calibration Files tool or


  4. You can find the data elements grouped based on the model architecture. The top model is referred as GROUP and subsystems in the model are referred as SUB_GROUPS. The generated file contains these lines.

     /begin GROUP
        /* Name                   */      sldemo_fuelsys
        /* Long identifier        */      "sldemo_fuelsys"
        /* Root                   */      ROOT
        /begin SUB_GROUP
        /end SUB_GROUP
      /end GROUP

  5. The following command groups the scalar objects to a group named GROUP_TYPE_SCALAR in the ASAP2 file.


In this way, you can also group the objects of type array. And lookup tables into MAP, CURVE, CUBOID, CUBE_4, and CUBE_5 based on dimensions of the table.

Generate Record Layouts

  1. Open the sldemo_fuelsys model.


  2. Build the model.

  3. Generate the ASAP2 file.


  4. You can find RecordLayouts.a2l file generated with the ASAP2 file. Verify the following line in the ASAP2 file that includes the record layouts file.

    /include "RecordLayouts.a2l"

  5. The generated RecordLayouts.a2l file contains the record layouts of all the data types present in the model.


    The ASAP2 file requires that the RecordLayouts.a2l file is in the same folder.

  6. coder.asap2.export("sldemo_fuelsys","IncludeAllRecordLayouts",false) does not generate separate record layouts file, but includes the record layouts of the data types of exported data objects in the ASAP2 file.

    /begin  RECORD_LAYOUT Scalar_FLOAT32_IEEE
      /end  RECORD_LAYOUT 
      /begin  RECORD_LAYOUT Scalar_FLOAT64_IEEE
      /end  RECORD_LAYOUT


In the ASA2P file, to preserve the shape of a lookup table that is used as a model argument, it is recommend to have the LookUp Table block in the referenced model and pass the Lookup table object from the top model as an instance parameter value.

See Also

Related Topics