Contenuto principale

Author Parameter and Port Constraints Using Standalone Constraint Manager

You can use constraints to validate parameter values and port signals. Reuse these constraints by creating and saving them in an XML file and sharing them across masks of different blocks in the same model or different models.

When multiple shared constraint files are linked to different blocks, opening the Mask Editor for each block to author or modify shared constraints can be inefficient. Instead, use the standalone Constraint Manager to author or modify shared constraints independently of a block context. For more information, see Share Parameter Constraints Across Multiple Block Masks and Share Port Constraints Across Multiple Masked Blocks.

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:

  1. Open the standalone Constraint Manager. In the MATLAB® Command Window, enter Simulink.ConstraintManager.open.

  2. Create a new shared constraint file by clicking New. Enter the name of the file as automotiveValidation. Click OK.

  3. To create a parameter constraint, click Parameter in the Constraint Gallery. In the Constraint Editor, specify the Constraint Name as speed and select the necessary rules for the constraint.

  4. To create a port constraint, click Port. Specify 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.

  5. To save the constraints to the XML file, click Save Constraints.

standalone constraint manager showing parameter and port constraint

Associate Shared Constraints to Parameters and Ports of Block Mask

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

  1. 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.

  2. In the Mask Editor, navigate to the Constraints tab, and in the toolstrip, click Load. Navigate to the XML file automotiveValidation. Click Open.

  3. To associate a parameter constraint, in the Associations pane, select the corresponding parameter from the dropdown. You can also associate a parameter to a parameter constraint from the Parameters & Dialog tab by selecting automotiveValidation:speed from the Constraints list.

  4. To associate a port constraint:

    1. In the Associations pane, click Define Ports. This action opens the Port Identifiers pane at the bottom.

    2. Create a port identifier. Click Add Add button in Port Identifiers to add a new row.

    3. Enter the name for the port. Set Type as either Input or Output.

    4. Specify the Identifier Type as name or index.

    5. If you specify Identifier Type as name, enter the name of the port in Identifier(s).

    6. To associate the port constraint, select the port identifier pi_1 in the Associations pane.

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

See Also

| | |

Topics