Main Content

Manage Interface Connector with Mask Initialization and Block Callbacks

This example shows how to manage Interface Connector with mask initialization and block callbacks. This example illustrates

  • How to do edit time operations outside of the masked subsystem using mask initialization.

  • How to check for structural errors at update diagram time using mask initialization code

  • How to invoke the mask initialization code of another block from a callback

Explore the Model

This example consists of the following blocks

Interface In: Accepts a signal name identifying the name of a root Inport, which the Interface In reads.

Interface Out: Accepts a signal name identifying the name of root Outport block to write to, multiple Interface Out blocks can write to the same root Outport and will be automatically merged.

Interface Connector: Manages the connections from the Interface In and Interface Out blocks to the root Inports.

Interface In blocks can be placed within virtual subsystems in your model and the signal name specified within the Interface In block will come from a root Inport block with the same name. Similarly, Interface Out blocks can be placed within virtual subsystems in your model and the signal name specified within the Interface Out block will write to a root Outport block with the same name. Multiple Interface Out blocks with the same signal name will write to the same root Outport via a Merge block.

The Interface Connector block which must reside in the root window of your block diagram. The Interface Connector dynamically manages connections for the Interface In and Interface Out blocks. As the Interface In and Interface Out blocks are edited, the Interface Connector automatically updates.

open_system("slexMaskSelfModifiableInterfaceBlocks.slx")

Limitations

As a general rule, mask blocks which have "[x] Allow library block to modify its contents" selected (mask self-modifiable blocks) are allowed to edit their contents via the mask initialization action. When they modify the contents, the interface of the masked block should not change during update diagram. Furthermore, the mask initialization code must not modify structure outside of the mask block. The mask initialization action is always invoked during update diagram. Mask initialization action of mask self-modifiable can change the masked block interface or make modifications outside of the contents of the masked block during edit only. This example illustrates this. This model contains Variant blocks. During model compile the variant conditions are analyzed before Simulink runs the mask initialization action code, thus the structure of the model cannot change when the mask initialization action is run by model compile. This example illustrates how to do all mask initialization actions at edit time. During compile the mask initialization code of the Interface Connector validates that the connections are valid and if not, an error is produced aborting the model compile.