Main Content

Report Diagnostic Messages Programmatically

The sldiagviewer functions enable you to generate, display, and log diagnostic messages in the Diagnostic Viewer.

By using these functions, you can programmatically:

  • Create new diagnostic stages.

  • Report diagnostic messages in the Diagnostic Viewer.

  • Log diagnostic messages in a text file.

Create Diagnostic Stages

The Diagnostic Viewer organizes and displays the error, warning, and information messages in the Diagnostic Message Pane in different stages. Each stage represents a runtime operation, such as model load, simulation, build, or diagram update. As more operations occur, new stages are created. For cases involving multiple operations, child stages are created to form a hierarchical structure.

To initialize a stage, to log the diagnostic messages for the upcoming runtime operation, create a stage object by using the sldiagviewer.createStage function. If you create a new stage object without ending the current stage, the new stage is a child stage of the current stage.

To end a stage, close the stage object. If you delete a parent stage object, the parent and its child stages close in the Diagnostic Viewer.

Create Stage to Display Diagnostic Messages

Create a stage to display diagnostic messages in the Diagnostic Viewer using sldiagviewer.createStage.

Load the model DiagnosticDemo.

model = "DiagnosticDemo";
load_system(model);

Create a stage to display the diagnostic messages.

myStage = sldiagviewer.createStage("Analysis","ModelName",model);

After you create the stage, you can report the diagnostics of your next Simulink® operation in the Diagnostic Viewer in the Analysis stage. For more information, see Diagnostic Viewer.

Report Diagnostic Messages

Use the sldiagviewer.reportError, sldiagviewer.reportWarning, and sldiagviewer.reportInfo functions to report error, warning, and information messages, respectively, in the Diagnostic Viewer.

Optionally, you can specify the name of the component or the product that generates the diagnostic message, such as Simulink, Model Advisor, or Stateflow.

Log Diagnostic Messages in a File

Use the sldiagviewer.diary function to log diagnostic messages and build information in a text file.

By default, sldiagviewer.diary logs the diagnostic messages in a text file diary.txt located in the current folder using the default character encoding of your system. You can also specify a filename to log messages and set character encoding to UTF-8. For more information, see and . You can also switch the logging state to on or off in the current log file.

See Also

Tools

Topics