How to Define Custom Edit-Time Checks - MATLAB & Simulink
Video Player is loading.
Current Time 0:00
Duration 3:58
Loaded: 4.16%
Stream Type LIVE
Remaining Time 3:58
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 3:58

    How to Define Custom Edit-Time Checks

    Edit-time checks can catch issues as you are designing to avoid rework later. Watch an overview of the steps needed to author your own custom Model Advisor checks that run during edit-time with Simulink Check™. This enables you to address violations of your own company standards and guidelines as you are designing.

    Published: 17 Feb 2022

    Edit-time checking notifies you of issues as you're editing, allowing you to address them as you go. Starting with the 22a release, you can define your own custom edit-time checks. The steps and code presented here are available in this documentation topic.

    We're going to create three checks. The first check verifies that in-port and out-port blocks have certain colors, based on their output data types. The second check verifies whether a trigger block is higher than other blocks in a subsystem. And then the third check verifies whether signals that connect to out-port blocks have labels.

    First, create an sl customization function, and use the AddModelAdvisorCheckFcn to register the checks. In this example, defineCheck is a check definition function. Next, in defineCheck, create three ModelAdvisor.Check objects. Specify the checkIds as input arguments, the check title, and the callback handle property, which is the name of the class that defines the edit-time check. For this example, MyEditTimeCheck is the package name.

    Next, publish the checks to a new folder in the Model Advisor. Create the first check, PortColor, by creating a class that derives from the ModelAdvisor.EditTimeCheck abstract base class. Save this file into a folder, named the same name as a package name. The PortColor method checks the checkId and TraversalType properties. This traversal type checks newly added and edited blocks, but it does not have to check for other affected blocks in the same subsystem or model.

    The blockDiscovered method checks the color of in-port and out-port blocks. Then it highlights the violating block, by creating a result detail violation object for the block. The fix method provides a way to update the block with the correct colors. For the check for TriggerBlockPosition, the traversal type is set to ACTIVEGRAPH, because it must check other blocks in the same subsystem as a trigger block.

    The blockDiscovered method checks the position of trigger blocks within subsystems. And the finishTraversal method checks whether the position of these trigger blocks are higher than other blocks in a subsystem. Then a result detail violation object is created for the block. The last check verifies for signal labels on signals to out-ports. This check also checks newly added and edited blocks.

    The blockDiscovered method uses a parameters on the line handles of the blocks to find signals that connect to out-port blocks, and then checks whether they have names. Then because the violation is on a signal, a violation object with the type property value set to Signal is created. Now we refresh customizations, and open up the Model Advisor Configuration Editor. A custom configuration is created with just the three edit-time checks.

    Now let's open up the model. I'll turn on Edit-Time Checks and specify the configuration file. The two in-port blocks are highlighted, because they're int32, and they should be cyan. I'll click on the warning, and since we added a fix method, I can correct the issue right here.

    I can also add a justification, which I'll do for the signal label error. Errors are flagged as you go. So when I move the trigger block below the other blocks, my check flags it, and I can correct the issue immediately.

    In summary, this example shows you how to create three custom edit-time checks to find issues earlier. You can try the example for yourself, using the doc example, and start building your own checks.

    Related Products

    View more related videos