Main Content

Generate Reusable Code

Enable optimized reusable code generation for reusable subsystems

Model Configuration Pane: PLC Code Generation / Optimization

Description

Use the Generate reusable code parameter to generate better reusable code for reusable subsystems. For instance, if your model contains multiple instances of the same subsystem and some instances have constant inputs, by default, the generated code contains separate function blocks for each instance. If you select this option, the software does not consider whether the inputs to the subsystem are constant and generates one function block for the multiple instances.

Settings

off (default) | on
On

Generates better reusable code for reusable subsystems.

Off

Reverts to its default behavior. Instead of a single reusable function block, the software generates separate function blocks for individual instances of a reusable subsystem because of certain differences in their inputs.

Tips

  • If you find multiple function blocks in your generated code for multiple instances of the same subsystem, select this option. The software performs better identification of whether two instances of a subsystem are actually the same and whether it can combine the multiple blocks into one reusable function block.

  • If different instances of a subsystem have different values of a block parameter, you cannot generate reusable code. Clear this option or use the same block parameter for all instances.

  • Despite selecting this option, if you do not see reusable code for different instances of a subsystem, you can determine the reason. To determine if two reusable subsystems are identical, the code generator internally uses a checksum value. You can compare the checksum values for two instances of a subsystem and investigate why they are not identical.

    To get the checksum values for the two instances that you expect to be identical, use the function Simulink.SubSystem.getChecksum. If the checksum values are different, investigate the checksum details to see why the values are not identical.

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOn
Safety precautionNo impact

Programmatic Use

Parameter:PLC_GenerateReusableCode
Type: string
Value: 'on' | 'off'
Default: 'off'

Version History

Introduced in R2016b