This example shows how to create and manage System Composer™ allocations. Use allocations to establish a directed relationship from architecture elements (components, ports, and connectors) in one model to architecture elements in another model. One common use case for allocations is to establish relationships from software components to hardware components to indicate a deployment strategy.
This example uses the Tire Pressure Monitoring System (TPMS) project. To open the project, use this command:
You can create an allocation set using the Allocation Editor. An allocation set is a collection of allocation relationships between two models: a source model, and a target model. The allocation set is stored as an
In this example,
TPMS_FunctionalArchitecture.slx is the source model and the
TPMS_LogicalArchitecture.slx is the target model.
To create an allocation set for these models, use this command.
allocSet = systemcomposer.allocation.createAllocationSet(... 'Functional2Logical', ...% Name of the allocation set 'TPMS_FunctionalArchitecture', ... % Source model 'TPMS_LogicalArchitecture' ... % Target model );
To see the allocation set, open the Allocation Editor by using the following command.
The Allocation Editor has three parts: the toolstrip, the browser pane, and the allocation matrix.
Use the toolstrip to create and manage allocation sets. For instance, you can use the New Allocation Set button to create a new allocation set between two models.
Use the Allocation Set Browser pane to browse and open existing allocation sets.
Use the allocation matrix to specify allocations between the source model elements in the first column and target model elements in the first row. You can create allocations programmatically or by double-clicking a cell in the matrix.
This example shows how to programmatically create allocations between two models in the TPMS project.
Get handles to the reporting functions in the functional architecture model.
functionalArch = systemcomposer.loadModel('TPMS_FunctionalArchitecture'); reportLevels = functionalArch.lookup('Path', 'TPMS_FunctionalArchitecture/Report Tire Pressure Levels'); reportLow = functionalArch.lookup('Path', 'TPMS_FunctionalArchitecture/Report Low Tire Pressure');
Get the handle to the TPMS reporting system component in the logical architecture model.
logicalArch = systemcomposer.loadModel('TPMS_LogicalArchitecture'); reportingSystem = logicalArch.lookup('Path', 'TPMS_LogicalArchitecture/TPMS Reporting System');
Create the allocations in the default scenario that is created.
defaultScenario = allocSet.getScenario('Scenario 1'); defaultScenario.allocate(reportLevels, reportingSystem); defaultScenario.allocate(reportLow, reportingSystem);
Save the allocation set.
Optionally, you can delete the allocation between reporting low tire pressure and the reporting system.