Generate XML data file for custom check for block constraints


Advisor.authoring.generateBlockConstraintsDataFile(dataFile, 'constraints',constraintslist) generates an XML data file named dataFile. This data file specifies the constraints that a custom check contains. The data file uses tagging to specify the constraint information. When you create a custom check, you use the data file.

Define constraint objects in the base workspace and then pass these objects as inputs to this function. These constraints may be root constraints and prerequisites to root constraints. You can also define a composite constraint. If you specify multiple root constraints and no composite constraint, Simulink implements a composite constraint with a CompositeOperator of and.


collapse all

Create a custom check for this MAB check Check settings for data ports in Multiport Switch blocks. For Multiport Switch blocks, the check contains a constraint that checks that the Data port order parameter setting is Specify indices. If the parameter has this setting, there are constraints that check that the Data port for default case parameter setting is Additional data port and the Diagnostic for default case setting is None.

Create three PositiveBlockParameter constraint objects.

c1 = Advisor.authoring.PositiveBlockParameterConstraint(); 
c1.ID = 'ID_A2'; 
c1.BlockType = 'MultiPortSwitch'; 
c1.ParameterName = 'DataPortOrder'; 
c1.SupportedParameterValues = {'Specify indices'}; 
c1.ValueOperator = 'eq'; 

c2 = Advisor.authoring.PositiveBlockParameterConstraint(); 
c2.ID = 'ID_A3'; 
c2.BlockType = 'MultiPortSwitch'; 
c2.ParameterName = 'DataPortForDefault'; 
c2.SupportedParameterValues = {'Additional data port'}; 
c2.ValueOperator = 'eq'; 

c3 = Advisor.authoring.PositiveBlockParameterConstraint(); 
c3.ID = 'ID_A4'; 
c3.BlockType = 'MultiPortSwitch'; 
c3.ParameterName = 'DiagnosticForDefault'; 
c3.SupportedParameterValues = {'None'}; 
c3.ValueOperator = 'eq'; 

Use the addPreRequisiteConstraintID method to make c1 a prerequisite to checking constraints c2 and c3.


Create a composite constraint that specifies that if a Multiport Switch block does not meet constraints c2 and c3, the block is in violation of this check.

cc = Advisor.authoring.CompositeConstraint(); 
cc.addConstraintID ('ID_A4');
cc.CompositeOperator = 'and'; 

Create a data file that contains the constraints.

dataFile = 'myDataFile.xml';
Advisor.authoring.generateBlockConstraintsDataFile( ...

Data file myDataFile.xml has tagging specifying the constraint information for the custom check.

<?xml version="1.0" encoding="utf-8"?>
      <PositiveBlockParameterConstraint BlockType="MultiPortSwitch" id="ID_A2">
         <parameter type="string">DataPortOrder</parameter>
         <value>Specify indices</value>
      <PositiveBlockParameterConstraint BlockType="MultiPortSwitch" id="ID_A3">
         <parameter type="string">DataPortForDefault</parameter>
         <value>Additional data port</value>
      <PositiveBlockParameterConstraint BlockType="MultiPortSwitch" id="ID_A4">
         <parameter type="string">DiagnosticForDefault</parameter>


For model configuration parameter constraints, use the Advisor.authoring.generateBlockConstraintsDataFile method only when specifying model configuration parameter constraints as prerequisites to block constraints or as part of a composite constraint consisting of both block and model configuration parameter constraints. For other cases, use the Advisor_authoring.generateConfigurationParameterDatafile method.

Input Arguments

collapse all

Name of XML data file to create, specified as a character vector.

Example: 'myDataFile.xml'

Use these classes to create constraint objects:

  • Advisor.authoring.PositiveBlockParameterConstraint

  • Advisor.authoring.NegativeBlockParameterConstraint

  • Advisor.authoring.PositiveModelParameterConstraint

  • Advisor.authoring.NegativeModelParameterConstraint

  • Advisor.authoring.PositiveBlockTypeConstraint

  • Advisor.authoring.NegativeBlockTypeConstraint

  • Advisor.authoring.CompositeConstraint

Example: {c1,c2,c3}

Introduced in R2018a