Main Content

Get Metadata About Test Points and Logged Signals in Generated Code

This example shows how to retrieve metadata for signals of interest in the generated code using the getSignalsOfInterest method for the CodeDescriptor class. This method retrieves the code representation of test points and logged signals in a model or model hierarchy, enabling you to monitor these signals without the need to configure storage classes, write custom scripts, or perform manual searches.

Examine Test Points and Logged Signals in Model Hierarchy

Open the example model.

model = "TopModelCode";
open_system(model);

This model contains three instances of the model reference ReferenceModelCode.

The output of the model reference CounterB in the top model is configured as a logged signal.

topmodel.png

Each model reference contains the test point output as the output of a Switch block. In total, the model hierarchy has four signals of interest, one for each of the three model reference instances, plus the logged signal appearing in the top model.

refmodel.png

Get Information About Signals in Generated Code

1. Unlike test points, logged signals are included in model optimizations, such as signal storage reuse (see Configure Signals as Test Points). Disabling signal storage reuse can sometimes prevent the code generator from optimizing out logged signals, such as the one found in this model.

To disable signal storage reuse, open the Configuration Parameters dialog box. On the Code Generation > Optimization pane, clear Signal storage reuse. Alternatively, run the following command:

set_param(model,OptimizeBlockIOStorage="off");

2. Build the top model.

slbuild(model);
### Searching for referenced models in model 'TopModelCode'.
### Total of 2 models to build.
### Starting serial code generation build.
### Successfully updated the model reference code generation target for: ReferenceModelCode
### Starting build procedure for: TopModelCode
### Successful completion of build procedure for: TopModelCode

Build Summary

Model reference code generation targets:

Model               Build Reason                                  Status                        Build Duration
==============================================================================================================
ReferenceModelCode  Target (ReferenceModelCode.c) did not exist.  Code generated and compiled.  0h 0m 5.4021s 

Top model targets:

Model         Build Reason                                         Status                        Build Duration
===============================================================================================================
TopModelCode  Information cache folder or artifacts were missing.  Code generated and compiled.  0h 0m 8.8026s 

2 of 2 models built (0 models already up to date)
Build duration: 0h 0m 15.215s

3. Create a coder.codedescriptor.CodeDescriptor object for the model.

codeDescObj = coder.getCodeDescriptor(model);

4. Get information about the code representation of both logged signals and test points in the model hierarchy.

signals = codeDescObj.getSignalsOfInterest("DataLogging","TestPoint")
signals = 
  1×4 SignalOfInterest array with properties:

    DataInterface

signals is a 1-by-4 array of SignalOfInterest objects, representing the four signals of interest in the model hierarchy.

5. Get the DataInterface object representing the first signal of interest in the generated code.

testpt1 = signals(1).DataInterface
testpt1 = 
  DataInterface with properties:
              Type: [1×1 coder.descriptor.types.Type]
               SID: 'TopModelCode:6'
     GraphicalName: 'output'
       VariantInfo: [1×0 coder.descriptor.VariantInfo]
    Implementation: [1×1 coder.descriptor.DataImplementation]
            Timing: [1×1 coder.descriptor.TimingInterface]
              Unit: ''
             Range: [1×0 coder.descriptor.Range]

6. Get the Implementation object representing this signal.

impl1 = testpt1.Implementation
impl1 = 
  StructExpression with properties:
                 Type: [1×1 coder.descriptor.types.Type]
           BaseRegion: [1×1 coder.descriptor.TypedRegion]
    ElementIdentifier: 'output_o'
              Variant: ''

7. Get code expressions for accessing this signal and its address relative to the topmost structure that contains it in the generated code. You can use these expressions to access and log data from the corresponding signals.

getExpression(impl1)
ans = 
'TopModelCode_B.output_o'
getAddress(impl1)
ans = 
'&(TopModelCode_B.output_o)'

These expressions show that signal output_o is directly contained inside the TopModelCode_B structure of the top model. This data element represents the logged signal output of the CounterB block.

8. Repeat Steps 5–7 for the three test points in the model hierarchy.

testpt2 = signals(2).DataInterface;
impl2 = testpt2.Implementation;
getExpression(impl2)
ans = 
'TopModelCode_DW.CounterA_InstanceData.rtb.output'
getAddress(impl2)
ans = 
'&(TopModelCode_DW.CounterA_InstanceData.rtb.output)'
testpt3 = signals(3).DataInterface;
impl3 = testpt3.Implementation;
getExpression(impl3)
ans = 
'TopModelCode_DW.CounterB_InstanceData.rtb.output'
getAddress(impl3)
ans = 
'&(TopModelCode_DW.CounterB_InstanceData.rtb.output)'
testpt4 = signals(4).DataInterface;
impl4 = testpt4.Implementation;
getExpression(impl4)
ans = 
'TopModelCode_DW.CounterC_InstanceData.rtb.output'
getAddress(impl4)
ans = 
'&(TopModelCode_DW.CounterC_InstanceData.rtb.output)'

Each DataInterface object represents the test point output in one of the three model references. The code expressions of their Implementation members show that each test point is contained inside the CounterX_InstanceData structure of its respective model reference. This structure is then contained inside the TopModelCode_DW structure of the top model.

Limitations

The getSignalsOfInterest API does not return information for signals inside:

  • Protected models

  • Stateflow® charts

The API throws an error if called on a model with the following targets:

  • AUTOSAR or AUTOSAR Adaptive

  • Simulation targets such as model reference simulation targets

See Also

Topics