Access Data from Model Outputs in Fault Behaviors
If you want to inject faults into your Simulink® or System Composer™ models, you must model the behavior that each fault introduces. By default, the fault behavior assigned to a fault retrieves data only from the signal that has the fault. If you want to use model data from other signals in your fault behavior, use Fault Data Inport blocks. Fault Data Inport blocks map to data from output ports and feed the data to the Fault Subsystem block that models the fault behavior. You can configure Fault Data Inport blocks interactively or programmatically.
For more information on creating faults and fault behaviors, see Define and Model Faults and Create Predefined and Custom Fault Behaviors.
Add Fault Data Inport Blocks to Fault Behaviors
You can add a Fault Data Inport block when you create a fault behavior or manually add a Fault Data Inport block to an existing fault behavior. You can only add Fault Data Inport blocks to the top level of the Fault Subsystem block.
Create New Faults that have Behavior that Contain a Fault Data Inport block
To create a new fault that contains a Fault Data Inport block in its fault behavior:
Open the Fault Analyzer app. In the Apps tab, click Fault Analyzer.
Select a Simulink model signal.
In the Fault Analyzer tab, click Add Fault.
In the Add Fault window, enable the Add fault behavior property.
Set the Fault library property to
mwfaultlib
, set the Fault behavior property toCustom fault behavior
, and enable the Add Fault Data Inport block to behavior property.Click OK.
The Fault Subsystem block that models the fault behavior contains a Fault Data Inport, Fault Inport, and Fault Outport block.
Add Fault Behavior that Contains a Fault Data Inport Block to Existing Faults
To add fault behavior that contains a Fault Data Inport block to an existing fault:
In the model, click the fault badge of a fault that does not have behavior.
Click the Add fault behavior icon in the preview window. The Add Fault Behavior window opens.
Set the Fault library property to
mwfaultlib
, set the Fault behavior property toCustom fault behavior
, and enable the Add Fault Data Inport block to behavior property.Click OK.
The Fault Subsystem block that models the fault behavior contains a Fault Data Inport block, a Fault Inport block, and a Fault Outport block.
Add Fault Data Inport Blocks to Existing Fault Behavior
To add a Fault Data Inport block to existing fault behaviors:
Open the fault behavior. In the model with the fault, click the fault badge of a fault that has behavior.
Click the fault behavior preview window. When the fault model is not loaded, the preview window displays the Open fault behavior icon for each fault behavior.
In the Fault Subsystem block that models the behavior, add the Fault Data Inport block. Open the Library Browser, expand Simulink Fault Analyzer > Fault Port Blocks, and add the block to the model.
You can add more than one Fault Data Inport block to each Fault Subsystem block.
You can add Fault Data Inport blocks to fault behaviors in custom libraries. For more information, see Customize Fault Behaviors by Using Libraries. You must assign the behavior to a fault before you map the block to a signal.
You can also add Fault Data Inport blocks to fault behaviors of faults in referenced models. For more information, Manage Faults in Referenced Models. If you add a fault to a referenced model that is open as a standalone model, you cannot map the Fault Data Inport block to the model that contains the referenced model.
Retrieve Model Data
After adding the Fault Data Inport block to a fault behavior, you must map the block to an output port in the model. To map data to an output port:
Double-click the Fault Data Inport block. The Property Inspector opens and lists the Fault Data Inport blocks in the subsystem.
In the Fault Data Inport Blocks section, click Map to Model Elements. The model that contains the fault opens in bind mode.
Select an output port to map to the block. Click a signal and select an output port.
Exit bind mode.
You can also map the block to output ports by using the action bar. Point to the Fault Data Inport block, then point to the ellipsis above the block to open the action bar. Click the connect icon to open the model in bind mode.
The Fault Data Inport Blocks section lists the output port mapped to each Fault Data Import block. Click the data source to highlight the location in the model.
Programmatically Configure Fault Data Inport Blocks
To programmatically create and connect the block to data:
Add the Fault Data Inport block to the fault behavior by using the
add_block
function.Map the block to the signal by using the
Simulink.fault.dataInportSource
function.
Example Fault Behavior with a Fault Data Inport Block
This example shows how to use model data in a fault behavior by using a Fault Data Inport block. The Fault Data Inport block retrieves data from an output port from a block in the model and sends it to the fault behavior.
Inspect the Model
Open the model. The model contains three signal sources: a Pulse Generator block, a Sine Wave block, and a Constant block. The model has one fault on the output port of the Sine Wave block.
View the Fault Behavior
Open the fault behavior. In the model, click the fault badge, then click the fault behavior preview window. When the fault triggers, the behavior adds the data from the Fault Data Inport block to the signal.
Double-click the Fault Data Inport block to open the Property Inspector. The Property Inspector lists the Fault Data Inport block name and the path of the model element in the Fault Data Inport Blocks section. In this example, the Fault Data Inport block retrieves the data from the output of the Pulse Generator block. The Property Inspector also lists other properties, including the trigger time. The fault triggers when the simulation time is 5
.
In the Fault Data Inport Blocks section, click the model element to highlight the data source location in the model.
Simulate the Model
Run the model to view the results. The Scope block indicates that the data from the Pulse Generator block applies to the fault behavior after 5 seconds.
See Also
Fault Data Inport | Fault Subsystem