Main Content

Report System Inputs and Outputs

This example shows how to create a report that describes the inputs and outputs of a model or subsystem. The report includes a chapter for the top-level model and each subsystem in the model. Each chapter includes a section for the inputs and outputs and a section for the blocks in the system.

This image shows the input and output summaries included in the report.

Open Model

Open a model. This example uses a model that has top-level input and output blocks and a subsystem with inputs and outputs. The top-level input signals are stored in a variable, mappedIO, which is created when the model is opened.

model = "slreportgen_demo_SystemIO";
open_system(model);

Report Setup

Import the Report Generator API namespaces so you do not have to use long, fully-qualified class names.

import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.finder.*

Create and open a Simulink report object. To create a Microsoft® Word, HTML, or single-file HTML report, change "pdf" to "docx", "html", or "html-file", respectively.

rpt = slreportgen.report.Report(model + "_SystemIO_Report","pdf");
open(rpt);

Add a title page and table of contents.

titlepage = TitlePage("Title",model + ": System I/O Report","Author","Jane Doe");
add(rpt,titlepage);
toc = TableOfContents();
add(rpt, toc);

Report on Inputs and Outputs

Find and loop through all systems in the model.

finder = SystemDiagramFinder(model);
while hasNext(finder)
    system = next(finder);

Create a new chapter and add the diagram result.

    ch = Chapter("Title",sprintf("System %s",system.Name));
    add(ch,system);   

Create an "Inputs and Outputs" section and a SystemIO reporter.

    ioSect = Section("Inputs and Outputs");
    ioRptr = SystemIO(system);    

For subsystem inputs and outputs, the SystemIO reporter by default includes details about the input and output ports of the subsystem. For model inputs and outputs, the reporter includes details about inport and outport blocks. If the system is a model, set the SystemIO options to omit these block details because this report includes the same information in the "Blocks" section of the chapter.

    if strcmp(system.Type,"Simulink.BlockDiagram")
        ioRptr.ShowDetails = false;
    end
    add(ioSect,ioRptr);
    add(ch,ioSect);

Create a section to include details about each block in the system. Source and destination blocks included in SystemIO summary tables link to the corresponding block details in this section.

    blkSect = Section("Blocks");
    blkFinder = BlockFinder(system);
    results = find(blkFinder);
    add(blkSect,results);
    add(ch,blkSect);

Add the chapter to the report.

    add(rpt,ch);
end

Close Report

Close and view the report.

close(rpt);
rptview(rpt);