Main Content

Configure Measurement Service Interfaces for Signals, States, and Data Stores

Since R2022b

By configuring the measurement service interface for signals, states, and data stores, you can preserve the data in the generated code for measurement. To configure measurement service interfaces, configure how the variable is stored in memory during program execution by defining a storage class in the shared coder dictionary. The dictionary specifies the default measurement service interface. Use the Code Mappings editor to configure the measurement service interfaces when you do not want to use the default value specified in a shared coder dictionary.

If data from a signal, state, or data store does not need to be preserved in the generated code, in the Code Mappings editor, you can set the measurement service interface to Not measured. This setting can be useful for debugging.

In the dialog box that appears if you click the pencil icon or in the Property Inspector, you can specify the identifier that the code generator uses to represent a signal or state in the generated code.

Configure Measurement Service Interfaces for States by Using the Code Mappings Editor

In this example, the component model references a shared coder dictionary that defines the default measurement service interfaces for states. To configure the model to use something other than the default service interface, use the Code Mappings editor.

Open the component model, ComponentDeploymentFcn.

openExample('ComponentDeploymentFcn');

Screenshot of component model

In this model, the Unit Delay block within the Accumulator Function-Call Subsystem, and the Discrete-Time Integrator block within the Integrator Function-Call Subsystem each have a state.

Verify that the component model references the shared coder dictionary, ComponentDeploymentCoderDictionary.sldd.

In the Model Configuration Parameters dialog box, verify that the Shared coder dictionary parameter is set to ComponentDeploymentCoderDictionary.sldd. This dictionary defines default service interfaces, including the measurement service interface, of the component model.

Open the Embedded Coder app.

To configure the block states to use a measurement service interface other than the default defined by the shared coder dictionary, use the Code Mappings editor.

To open the Code Mappings editor, in the C Code tab, click Code Interface > Component Interface.

On the Signals/States tab, notice that the Measurement Service of the two block states, is set to Dictionary default: MeasurementService.

Default configuration of the code mappings by using dictionary default values

To specify that a signal, state, or data store does not require a measurement service interface, set the Measurement Service to Not measured.

Measurement service for Discrete-Time Integrator block state configured to 'Not measured' in Code Mappings editor

To configure the block states to use a measurement service interface other than the default defined by the dictionary, you must create a new storage class in the dictionary, and reference the new storage class in a new measurement service interface definition in the dictionary.

For more information, see Define Service Interfaces, Storage Classes, Memory Sections, and Function Templates for Software Architecture.

Configure Measurement Service Interfaces for Signals by Using the Code Mappings Editor

In this example, the component model references a shared coder dictionary that defines the default measurement service interface for signals. To configure the model to use something other than the default service interface, use the Code Mappings editor.

Open the component model, ComponentDeploymentFcn.

openExample('ComponentDeploymentFcn');

Screenshot of component model

The component model references the shared coder dictionary, ComponentDeploymentCoderDictionary.sldd, which defines default service interfaces, including the measurement services, of the component model.

Open the Embedded Coder app.

To configure signals to use a measurement service interface other than the default defined by the shared coder dictionary, use the Code Mappings editor.

To open the Code Mappings editor, in the C Code tab, click Code Interface > Component Interface.

Open the Signals/States tab. Currently there are no signals in the mapping. To add a signal to the mapping, click on the signal and select Add selected Signals to code mappings. In this example, add the signal at the output of the Sum block in the Accumulator subsystem to the code mappings of the model.

The signal now appears in the Code Mappings editor. The Measurement Service property of the signal is set to Not measured.

Signal in the code mappings with measurement service set to 'Not measured'

To specify that the signal use the default measurement service interface as defined in the dictionary, set the Measurement Service to Dictionary default: MeasurementService.

Signal in the code mappings with measurement service set to 'Not measured'

Configure Measurement Service Interfaces for States and Signals Programmatically

To configure the measurement service interface of a signal, state, or data store programmatically, access the code mapping properties of the component model.

Open the model.

openExample('ComponentDeploymentFcn');

Get the code mappings for the model by using the coder.mapping.api.get function.

cm = coder.mapping.api.get('ComponentDeploymentFcn');

In this model, the Unit Delay block within the Accumulator Function-Call Subsystem, and the Discrete-Time Integrator block within the Integrator Function-Call Subsystem each have an associated state. Get the current measurement service interface configuration by using the getState function.

getState(cm, ...
'ComponentDeploymentFcn/Integrator/Discrete-Time Integrator',...
 'MeasurementService')
ans =

    'Dictionary default'
The block state is configured to use the default measurement service interface defined in the shared coder dictionary.

To specify that a signal, state, or data store does not require a measurement service interface, set the measurement service interface to 'Not measured'.

setState(cm,...
 'ComponentDeploymentFcn/Integrator/Discrete-Time Integrator',...
 'MeasurementService', 'Not measured')

To configure the block state to use a different measurement service interface, create a new measurement service interface definition in the dictionary. Then, use the setState function and specify the MeasurementService property to the new service interface you defined in the dictionary.

To configure the measurement service of the signal at the output of the Sum block, add the signal to the code mappings by using the addSignal function and specify the measurement service interface property.

portHandle = get_param('ComponentDeploymentFcn/Accumulator/Sum',...
 'PortHandles');
addSignal(cm, portHandle.Outport, ...
'MeasurementService', 'Dictionary default')

See Also

| | | | |

Related Topics