Main Content

Author Parameter and Port Constraints Using Standalone Constraint Manager

When creating masks for Simulink® blocks, there are specific constraints and considerations related to parameters and ports. These constraints enables the masked block to function correctly and integrate well within the model.

Mask parameter constraints help you to create validations on a mask parameter without having to write your own validation code. Constraints restrict the input for the mask parameter to a specified range.

You can also validate compile-time signal attributes on the input and output ports of a masked block by using port constraints. Compile-time signal attributes include data type, complexity, and dimensions. You can define the rules to validate the data types, the complexity (real or complex), and dimensions (scalar, vector, or 2-D matrix) of port signals. You can also add parameter conditions to the port constraint.

You can define parameter and port constraints in an XML file and associate the constraint across multiple block masks using Mask Editor. For more information, see Share Parameter Constraints Across Multiple Block Masks and Share Port Constraints Across Multiple Masked Blocks. Use shared constraints to maintain consistency, integrity, and proper functionality across multiple parameters or ports masked blocks. For example, changes to constraint logic can be made in one block and propagated to the rest of the block masks.

To manage multiple shared constraint files independently of a block context, open a standalone Constraint Manager by using the Simulink.ConstraintManager.open method. Because you author constraints without a block context, you must make the associations at the individual block level through Mask Editor.

Author Constraints Without Block Context

To author parameter and port constraints without associating them to a block mask:

  • In the MATLAB® command window, enter Simulink.ConstraintManager.open to open a standalone Constraint Manager.

  • In the toolstrip, click New to create a new shared constraint file. Enter the name of the file as automotiveValidation. Click OK.

  • In the toolstrip, click Parameter to create a parameter constraint. In the Constraint Editor, enter the Constraint Name as speed and select the necessary rules for the constraint.

  • Click Port to create a port constraint. Specify the Constraint Name as portDatatype and select rules for the port constraint. For parameter conditions, the parameters are not autopopulated because there is no associated block mask. You can manually specify Parameter Name and Parameter Values.

  • Click Save Constraints to save the constraints to the XML file.

standalone constraint manager showing parameter and port constraint

Associate Shared Constraints to Parameters and Ports of a Block Mask

To associate shared constraints to parameters and ports of a masked block:

  • Create a Subsystem block in a model and add a mask to the block. Create the required parameters and dialog controls on the block mask.

  • In the Mask Editor, navigate to the Constraints tab and in the toolstrip, click Load. Navigate to the parameter and port constraints from the XML file automotiveValidation. Click Open.

  • To associate a parameter constraint, in the Parameters & Dialog tab, select the parameter. In the Property Editor pane, under Attributes section, select automotiveValidation:speed as Constraint from the constraints list.

  • To associate a port constraint:

    • Create a port identifier. Click Port Identifiers from the toolstrip.

    • Enter the name for the port. Select the type of the port as either Input or Output.

    • Select the type of identifier as name or index

    • Enter the name of the port in case Identifier Type is name.

Constraints tab of the Mask Editor, showing constraints associated to parameters and ports

See Also

| | |

Related Topics