Create and Add Custom Data Elements
Generate an ASAP2 file by adding custom characteristics, measurements, axis-points, functions, groups, record layouts, and CompuMethods. By default, an ASAP2 file contains the data elements present in model that were configured to export.
Using the Simulink® Coder™ you can:
Create and add custom data elements such as characteristics, measurements, axis-points, functions, groups, record layouts, and CompuMethods.
Remove data elements from the ASAP2 file.
Filter and filter data elements based on their properties.
Get or update the properties of data elements.
Video - Customization of ASAP2 File
This video walks you through how to build a model and add, update, find, delete custom data elements in an ASAP2 file.

This video will walk you through how the A2L file can be customized. An q file is a special description file that defines the implementation of an ECU. The information in an A2L file allows XCP client to communicate with a server module via an XCP connection. The formatted text file contains event and measurement definitions and other configuration information used for acquiring and stimulating data, and to perform other functions. This video will focus on how to customize the sections of the A2L file such as characteristics, measurements, copy methods, et cetera.
Open a Simulink model and use the Simulink Coder app to go to Code Perspective. Build a model to generate the code. Once the build is done, we can now customize the different fields for the A2L file. To do this, first create an object from coder.asap2.getEcuDescriptions. The object created has the methods add, delete, find, get, and set. So now let me walk you through each of these methods.
The find method can be used to find the elements of a given category. For example, if you want to find all the characteristics that are to be populated, use find (descObj, "Characteristic"). The find method will also enable you to filter the set by an attribute. For example, to find all characteristics of type CURVE, you would use find (descObj,) and type as CURVE.
So now let's see how you could view all the properties of a specific element. This could be done using the get method. For example, let's take the example of the characteristic external temperature. To view the properties, use get (descObj, "Characteristic" , 'ExternalTemp'). This will give you all the exact properties for the element. As you can see here, the element is defined in degrees Celsius. The ASAP2 file when loaded into a calibration tool would give the element, the temperature, in degrees Celsius.
Wondering if it's possible to change the view on the calibration tool to have it in Kelvin instead of in Celsius? Yes, it is. On the A2L file, the interpretation is controlled by the Compu method. So now let's define a new Compu method to convert Celsius to Kelvin. To do this, create an object out of coder.asap2.CompuMethod, provide the name, conversion type, coefficients, and the unit.
Now the add method can be used to add this newly created Compu method to the ASAP2 file. This Compu method created now has to be associated with the element. Use set (descObj) category element name and the property to be set and its value. Now let's generate the A2L file. Use CustomEcuDescription and pass in the description object.
In the A2L file, we can now see that the element is associated with the newly created Compu method, and you also have the new Compu method definition. The ASAP2 file, when loaded into a calibration tool, would give the temperature in Kelvin.
Now, if you would like to delete an element from the A2L file you could use the Delete method. For example, let's say we would like to remove the characteristic external temperature. We would use delete (descObj, "Characteristic" , 'ExternalTemp'). Now regenerate the A2L file, and the A2L file would not have the element. You could also customize the other sections of the A2L file, and for more information you could refer to the documentation.
Customize an ASAP2 File
Add, update, filter, find, and remove ECU descriptions in an ASAP2 file.
Open and Build Example Model
Open the example model ASAP2Demo
open_system("ASAP2Demo");
Build the model.
slbuild("ASAP2Demo");
### Searching for referenced models in model 'ASAP2Demo'. ### Total of 2 models to build. ### Starting serial code generation build. ### Successfully updated the model reference code generation target for: ASAP2DemoModelRef ### Starting build procedure for: ASAP2Demo ### Successful completion of build procedure for: ASAP2Demo Build Summary Model reference code generation targets: Model Build Reason Status Build Duration ============================================================================================================ ASAP2DemoModelRef Target (ASAP2DemoModelRef.c) did not exist. Code generated and compiled. 0h 0m 5.8839s Top model targets: Model Build Reason Status Build Duration ============================================================================================================ ASAP2Demo Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 12.037s 2 of 2 models built (0 models already up to date) Build duration: 0h 0m 18.852s
Create the ECU description object for the model.
descObj = coder.asap2.getEcuDescriptions("ASAP2Demo");
Get the list of available computation methods in the description object.
find(descObj,"CompuMethod")
ans = 1×10 string
"ASAP2DemoModelRef_CM_double" "ASAP2DemoModelRef_CM_int16_rpm" "ASAP2Demo_CM_double" "ASAP2Demo_CM_double_m_per__s_2_" "ASAP2Demo_CM_double_rpm" "ASAP2Demo_CM_int32" "ASAP2Demo_CM_single" "ASAP2Demo_CM_single_m_per__s_2_" "ASAP2Demo_CM_single_rpm" "ASAP2Demo_CM_uint8"
Filter the computation methods and get a list of computation methods that use rpm as the unit.
find(descObj,"CompuMethod",Units='rpm')
ans = 1×3 string
"ASAP2DemoModelRef_CM_int16_rpm" "ASAP2Demo_CM_double_rpm" "ASAP2Demo_CM_single_rpm"
Create and Add Custom Computation Method
To add a new computation method to the ASAP2 file, create a custom computation method.
CompuMethod_1 = coder.asap2.CompuMethod; CompuMethod_1.Name = 'CompuMethod_1'; CompuMethod_1.ConversionType = 'LINEAR'; CompuMethod_1.Coefficients = [2 3]; CompuMethod_1.LongIdentifier = 'longIdentifierTest'; CompuMethod_1.Format = '%2.3'; CompuMethod_1.Units = 's';
Add the custom computation method to the ECU description object.
add(descObj,CompuMethod_1);
Get the properties of the newly added computation method.
get(descObj,"CompuMethod","CompuMethod_1")
ans = CompuMethod with properties: Name: 'CompuMethod_1' LongIdentifier: 'longIdentifierTest' Format: '%2.3' Units: 's' Coefficients: [2 3] ConversionType: 'LINEAR' CompuVTabValues: [1×1 struct] CustomData: ""
To modify a property of the computation method, use set function. Update the ConversionType field of the computation method to TAB_VERB and define the CompuVTabValues.
set(descObj,"CompuMethod","CompuMethod_1",ConversionType="TAB_VERB"); set(descObj,"CompuMethod","CompuMethod_1",CompuVTabValues = struct('Literals',["false" "true"],'Values',[0 1]));
Get the properties to see the modified fields.
modifiedprop = get(descObj,"CompuMethod","CompuMethod_1")
modifiedprop = CompuMethod with properties: Name: 'CompuMethod_1' LongIdentifier: 'longIdentifierTest' Format: '%2.3' Units: 's' Coefficients: [2 3] ConversionType: "TAB_VERB" CompuVTabValues: [1×1 struct] CustomData: ""
modifiedprop.CompuVTabValues
ans = struct with fields:
Literals: ["false" "true"]
Values: [0 1]
Generate the ASAP2 file using the updated ECU description object and verify that the ASAP2 file contains the computation method CompuMethod_1.
coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"
Delete Computation Method
Remove the newly added computation method from the description object.
delete(descObj,"CompuMethod","CompuMethod_1");
Create and Add Custom Characteristic
To add a new characteristic to the ASAP2 file, create a custom characteristic.
Parameter_1 = coder.asap2.Characteristic; Parameter_1.Name = 'Custom_parameter1'; Parameter_1.LongIdentifier = 'longIdentifierParam'; Parameter_1.UpperLimit = 255; Parameter_1.LowerLimit = 0;
Add the custom characteristic to the ECU description object.
add(descObj,Parameter_1);
Get the properties of the newly added characteristic.
get(descObj,"Characteristic","Custom_parameter1")
ans = Characteristic with properties: Name: 'Custom_parameter1' LongIdentifier: 'longIdentifierParam' Type: 'VALUE' EcuAddress: '0x0000' CompuMethodName: 'NO_COMPU_METHOD' LowerLimit: 0 UpperLimit: 255 EcuAddressComment: "" EcuAddressExtension: [] CalibrationAccess: 'Calibration' DisplayIdentifier: "" Format: "" BitMask: [] AxisInfo: [] RecordLayout: "" Dimensions: [] Export: 1 MaxRefresh: [1×1 struct] SymbolLink: [1×1 struct] CustomData: ""
To modify a property of the characteristic, use set function. Update the UpperLimit field of the characteristic.
set(descObj,"Characteristic","Custom_parameter1",UpperLimit=128)
Generate the ASAP2 file using the updated ECU description object and verify that the ASAP2 file contains the characteristic Custom_parameter1.
coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"
Remove the newly added characteristic from the description object.
delete(descObj,"Characteristic","Custom_parameter1");
Create and Add Custom Measurement
To add a new measurement to the ASAP2 file, create a custom measurement.
Signal_1 = coder.asap2.Measurement; Signal_1.Name = 'Custom_signal1'; Signal_1.LongIdentifier = 'longIdentifierSignal'; Signal_1.UpperLimit = 255; Signal_1.LowerLimit = 0;
Add the custom measurement to the ECU description object.
add(descObj,Signal_1);
Get the properties of the newly added measurement.
get(descObj,"Measurement","Custom_signal1")
ans = Measurement with properties: Name: 'Custom_signal1' LongIdentifier: 'longIdentifierSignal' DataType: 'UBYTE' EcuAddress: '0x0000' CompuMethodName: "" LowerLimit: 0 UpperLimit: 255 Raster: [1×1 struct] EcuAddressComment: "" EcuAddressExtension: [] CalibrationAccess: 'NoCalibration' DisplayIdentifier: "" Format: "" BitMask: [] Dimensions: [] Export: 1 MaskData: [1×1 struct] MaxRefresh: [1×1 struct] SymbolLink: [1×1 struct] CustomData: ""
To modify a property of the measurement, use set function. Update the CalibrationAccess field of the measurement.
set(descObj,"Measurement","Custom_signal1",CalibrationAccess='Calibration')
Generate the ASAP2 file using the updated ECU description object and verify that the ASAP2 file contains the measurement with name Custom_signal1.
coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"
Remove the newly added measurement from the description object.
delete(descObj,"Measurement","Custom_signal1");
Create and Add Lookup Table Parameter
Add a lookup table parameter.
LUT_Parameter = coder.asap2.Characteristic; LUT_Parameter.Name = "custom_lookup_table"; LUT_Parameter.Type = "MAP";
Create and add axis information to the parameter.
axis_data = coder.asap2.AxisInfo; axis_data(1).Name = 'BP3'; axis_data(2).Name = 'Bp4'; axis_data(1).CompuMethodName = 'ASAP2Demo_CM_double'; axis_data(2).CompuMethodName = 'ASAP2Demo_CM_double'; axis_data(1).MaxAxisPoints = '3'; axis_data(2).MaxAxisPoints = '3'; axis_data(1).AxisType = 'STD_AXIS'; axis_data(2).AxisType = 'STD_AXIS'; LUT_Parameter.AxisInfo = axis_data;
Add the lookup table parameter to the description object.
add(descObj,LUT_Parameter)
Generate the ASAP2 file using the updated ECU description object and verify that the ASAP2 file contains the lookup table parameter custom_lookup_table.
coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"
Create and Add Custom Group
Add, update, filter, find, and remove ECU descriptions for groups in an ASAP2 file.
Open and Build Example Model
Open the example model ASAP2Demo
open_system("ASAP2Demo");
Build the model.
slbuild("ASAP2Demo");
### Searching for referenced models in model 'ASAP2Demo'. ### Total of 2 models to build. ### Starting serial code generation build. ### Successfully updated the model reference code generation target for: ASAP2DemoModelRef ### Starting build procedure for: ASAP2Demo ### Successful completion of build procedure for: ASAP2Demo Build Summary Model reference code generation targets: Model Build Reason Status Build Duration ============================================================================================================ ASAP2DemoModelRef Target (ASAP2DemoModelRef.c) did not exist. Code generated and compiled. 0h 0m 7.3874s Top model targets: Model Build Reason Status Build Duration ============================================================================================================ ASAP2Demo Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 13.761s 2 of 2 models built (0 models already up to date) Build duration: 0h 0m 22.418s
Create the ECU description object for the model.
descObj = coder.asap2.getEcuDescriptions("ASAP2Demo");
Get the list of available groups in the description object.
find(descObj,"Group")
ans = 1×2 string
"ASAP2Demo" "ASAP2Demo.ASAP2DemoModelRef.ASAP2DemoModelRef"
Filter the groups and get a list of groups that has Root
set to true
.
find(descObj,"Group",Root=true)
ans = "ASAP2Demo"
Create and Add Custom Group
To add a new group to the ASAP2 file, create a custom group.
GroupObj_GR1 = coder.asap2.Group; GroupObj_GR1.Name = 'CustomGroup_1'; GroupObj_GR1.LongIdentifier = 'New test group'; GroupObj_GR1.RefCharacteristic = ["ydata3", "ydata4"]; GroupObj_GR1.RefMeasurement = ["ASAP2Demo_Y.Out3", "ASAP2Demo_Y.Out3"]; GroupObj_GR1.Root = true;
Add the custom group to the ECU description object.
add(descObj,GroupObj_GR1);
Get Group Properties
Get the properties of newly added group by using this command.
get(descObj,"Group","CustomGroup_1")
ans = Group with properties: Name: 'CustomGroup_1' LongIdentifier: 'New test group' RefCharacteristic: ["ydata3" "ydata4"] RefMeasurement: ["ASAP2Demo_Y.Out3" "ASAP2Demo_Y.Out3"] Root: 1 SubGroup: [1×0 string] CustomData: [1×0 string]
Update Group Properties
To modify a property of the group, use set function. Update the LongIdentifier field of the group.
set(descObj,"Group","CustomGroup_1",LongIdentifier="Group 1 new long identifier")
Generate the ASAP2 file using the updated ECU description object and verify that the ASAP2 file contains the group CustomGroup_1.
coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"
Delete Group
Remove the newly added group from the description object.
delete(descObj,"Group","CustomGroup_1");
See Also
coder.asap2.AxisInfo
| coder.asap2.Characteristic
| coder.asap2.CompuMethod
| coder.asap2.Function
| coder.asap2.Group
| coder.asap2.Measurement
| coder.asap2.RecordLayout
| coder.asap2.export
| coder.asap2.getEcuDescriptions
| coder.asap2.Group