Main Content

Validate Port Signals and Parameter Values Using Cross Port Parameter Constraints

A mask constraint is a set of rules or conditions applied to the parameters, port signals, or both parameters and port signals of a masked block. These constraints are designed to ensure that the parameters and signals adhere to specific requirements, which helps in maintain model consistency and prevent errors. Use cross port parameter constraints to establish constraint among ports and parameters within the same masked block. For example, you can constrain an input port signal, an output port signal, and a mask edit parameter so that they all have the same data type. The available rules for cross port parameter constraint are Same Data Type, Same Dimension, and Same Complexity. Additionally, you can also set parameter conditions to validate the cross port parameter constraints.

Explore the Model

In the model slexMaskConstraints.slx Refer to the block Calculate Torque that implements the equation Torque = force * radius * sin(angle). The model contains two Constant blocks for force and radius with values 9 and 7. Force and radius are the inputs to the input port signals of the masked Subsystem block CalculateTorque. The Subsystem block contains a mask edit parameter Angle to calculate sin(theta) and a cross port parameter constraint checkDataType to validate that the input port signals force and radius, and the mask parameter Angle are of same data type.

open_system("slexMaskConstraints.slx")

Create Cross Port Parameter Constraint

To create a similar model that has this cross-port-parameter constraint:

Create a model with two Constant blocks force and radius that are inputs to a subsystem CalculateTorque that calculates the torque.

1. In the Mask Editor, from Parameters & Dialog tab, create an edit parameter Angle.

2. In the Constraints tab, click Port Identifiers in the toolstrip. In the Port Identifiers pane, click Add to create port identifiers for the input and output ports:

3. In the Add Constraints section, click Cross Port Parameter to create a cross port parameter constraint.

4. Specify the Constraint Name as checkDatType. From the Rule list, select Same Data Type.

5. In the Association section, under Port Identifiers, add ports Input_1 and Input_2. Under Parameters add Angle. This ensures that the associated ports and parameters are validated against the selected rule.

6. From the Diagnostic Level list, select error as Diagnostic Level. Enter a custom error message in the Error Message box. Message*.

Validate Cross Port Parameter Constraint

To validate the associated cross port parameter constraint among the input ports and mask parameter:

Double-click the Constant block force and then in the Signal Attributes tab, change the Output data type of the Constant block to single.

Simulate the model. The Diagnostic Viewer displays this message.

See Also