Table of Contents

Compose Modules

The hardware and software modules are composed to a module tree.

Example

This example shows the module tree for a station that contains two cavities in order to test two workpieces at the same time. It also contains a script module (Script) in which the user can define the test program. The type data module (TypeData) contains the parameters and characteristics of the current type. The results are saved in a database (ResultsDatabase).

LisRT Module Tree

This example is generated by this source code:

// Export the station, you can directly access the StationModule instance via MEF or IoC
[Export]
// Export the station as RootModule
[Export(ModulesService.RootModuleName, typeof(ILisrtModule))]
internal class StationModule : InitializableCompositeModule
{
    public StationModule()
        : base("Station")
    {
        // Build the station
        WorkPieceModule = new WorkPieceModule(
            TypeDataModule,
            "WorkPiece",
            new Loehnert.TypeAndResult.Station("Station"));

        SubModules.Add(new Cavity("Cavity1", TypeDataModule));
        SubModules.Add(new Cavity("Cavity2", TypeDataModule));

        SubModules.Add(ScriptModule);
        SubModules.Add(TypeDataModule);
        SubModules.Add(ResultsDatabase);
    }

    public ScriptModule ScriptModule { get; } = new ScriptModule("Script");
    public TypeDataModule TypeDataModule { get; } = new TypeDataModule("TypeData");
    public ResultsDatabaseModule ResultsDatabase { get; } 
        = new ResultsDatabaseModule("ResultsDatabase");

    public override void Initialize() { ... }
}

internal class Cavity : CompositeModule
{
    public Cavity(string name, TypeDataModule typeDataModule) : base(name)
    {
        WorkPieceModule = new WorkPieceModule(
            typeDataModule,
            "WorkPiece",
            new Loehnert.TypeAndResult.Station("Station"));
        SubModules.Add(WorkPieceModule);
        SubModules.Add(PowerSupply);
        SubModules.Add(Multimeter);
    }

    public WorkPieceModule WorkPieceModule { get; }
    public PowerSupplyModule PowerSupply { get; } = new DummyPowerSupplyModule("PowerSupply");
    public MultimeterModule Multimeter { get; } = new DummyMultimeterModule("Multimeter");
}

Export a Root Module

Add this export statement, to export an instance as RootModule:

[Export(ModulesService.RootModuleName, typeof(Loehnert.Lisrt.Contracts.ILisrtModule))]

You can also export multiple root modules. The priority is defined by the RootModuleMetadata attribute.

[RootModuleMetadata(priority: 5)]
[Export(ModulesService.RootModuleName, typeof(Loehnert.Lisrt.Contracts.ILisrtModule))]

See Also