主要内容

Suppress Diagnostic Messages Programmatically

这following examples show how to manage diagnostic suppressions programmatically.

Suppress Diagnostic Messages Programmatically

This example shows how to access simulation metadata to manage diagnostic suppressions and to restore diagnostic messages programmatically.

Create a New Folder and Copy Relevant Files

  1. 创建一个本地工作文件夹,例如C:\ Diagnostic_suppressor_demo

  2. 更改为docroot \ toolbo金宝appx \ simulink \示例文件夹。在Matlab®command line, enter:

    CD(FullFile(DocRoot,“工具箱”,“ Simul金宝appink”,“示例”))

  3. Copy thegetDiagnosticObjects.m,suppressor_script.m, 和uspressor_cli_demo.slxfiles to your local working folder.

    getDiagnosticObjects.m功能查询模拟元数据以访问模拟过程中投掷的诊断。这suppressor_script.mscript contains the commands for suppressing and restoring diagnostics to theSuppressor_CLI_Demomodel.

    getDiagnosticObjects.m

打开并模拟模型

Open the model. To accessSimulink.SimulationMetadata,设置returnworkSpaceOutputsparameter value to'on'。模拟模型。

model ='Suppressor_CLI_Demo';open_system(model); set_param(model,'ReturnWorkspaceOutputs','on');out = sim(型号);

从模拟元数据中获取消息标识符

使用存储在msldiagnostic目的。

如果(存在('出去','var')) diag_objects = getDiagnosticObjects(out);end

Several warnings were generated during simulation, including a saturation of the数据类型转换堵塞。查询diag_objectsvariable to get more information on the identifiers.

diag_objects(5)
ans = MSLDiagnostic with properties: identifier: 'SimulinkFixedPoint:util:Saturationoccurred' message: 'Saturation occurred. This originated from 'Suppressor_CLI_Demo/Con…' paths: {'Suppressor_CLI_Demo/Convert/FixPt To FixPt3'} cause: {} stack: [0×1 struct]

Suppress Saturation Diagnostic on a Block

Use theSimulink.suppressDiagnostic功能仅在数据类型转换块上抑制饱和诊断。模拟模型。

金宝appsimulink.suppressdiagnostic('Suppressor_CLI_Demo/Convert/FixPt To FixPt3',。。。'SimulinkFixedPoint:util:Saturationoccurred');set_param(型号,'SimulationCommand','开始');

恢复饱和诊断

Use the金宝appsimulink.restorediagnostic功能to restore the saturation diagnostic of the same block.

金宝appsimulink.restorediagnostic('Suppressor_CLI_Demo/Convert/FixPt To FixPt3',。。。'SimulinkFixedPoint:util:Saturationoccurred');set_param(型号,'SimulationCommand','开始');

在源上抑制多个诊断

您可以通过创建消息标识符的单元格数组来抑制单个源上的多个警告。抑制精度损失和参数下流警告持续的block,one,在模型中。

diags = {'SimulinkFixedPoint:util:fxpParameterPrecisionLoss',。。。'金宝appsimulinkfixedpoint:util:fxpparameterunderflow'};金宝appsimulink.suppressdiagnostic('Suppressor_CLI_Demo/one',diags); set_param(model,'SimulationCommand','开始');

恢复在一个块上的所有诊断

使用金宝appsimulink.restorediagnostic功能。

金宝appsimulink.restorediagnostic('Suppressor_CLI_Demo/one');set_param(型号,'SimulationCommand','开始');

在许多块上抑制诊断

您可以在许多块上抑制一个或多个诊断。例如,使用find_system功能to create a cell array of all数据类型转换系统中的块,并抑制指定块上的所有饱和警告。

dtc_blocks = find_system('Suppressor_CLI_Demo/Convert',。。。'BlockType',“ datatypeconversion');金宝appsimulink.suppressdiagnostic(dtc_blocks,'SimulinkFixedPoint:util:Saturationoccurred');set_param(型号,'SimulationCommand','开始');

恢复子系统中的所有诊断

You can also use the金宝appsimulink.restorediagnostic功能以还原指定子系统内的所有诊断。

金宝appsimulink.restorediagnostic('Suppressor_CLI_Demo/Convert',。。。'FindAll','On');set_param(型号,'SimulationCommand','开始');

将评论和用户信息添加到压制中

A抑制诊断object contains information on the source of the suppression and the suppressed diagnostic message identifier. You can also include comments, and the name of the user who last modified the suppression.

object = 金宝appsimulink.suppresseddiarostic('suppressor_cli_demo/convert/fixpt to fixpt1',。。。'SimulinkFixedPoint:util:Saturationoccurred');对象。评论=``评论:约翰·doe'';object.lastModifiedby ='Joe Schmoe'set_param(型号,'SimulationCommand','开始');
object =带有属性的抑制诊断:源:'suppressor_cli_demo/convert/fixpt to fixpt1'id:'simulinkFixedPoint:util:util:ataperat金宝appionoccurred'lastmodifiedby:'joe schmoe''''23:01'

获取抑制数据

要获取特定子系统或块的抑制数据,请使用Simulink.getSuppressedDiagnostics功能。

Object = Simulink.getSuppressedDiagnostics('suppressor_cli_demo/convert/fixpt to fixpt1');set_param(型号,'SimulationCommand','开始');

Restore All Diagnostics on a Model

当模型包含许多诊断抑制时,您想将所有诊断恢复到模型Simulink.getSuppressedDiagnostics返回一个数组的功能Simulink.SuppressedDiagnosticobjects. Then use the恢复method as you iterate through the array.

Objects = Simulink.getSuppressedDiagnostics('Suppressor_CLI_Demo');foriter = 1:numel(objects)还原(对象(iter));endset_param(型号,'SimulationCommand','开始');

Suppress Diagnostic Messages of a Referenced Model

此示例显示了当诊断源自引用模型时,如何抑制诊断。通过访问msldiagnosticobject of the specific instance of the warning, you can suppress the warning only for instances when the referenced model is simulated from the specified top model.

This example model contains two instances of the same referenced model,refModel。这modelrefModelreferences yet another model,refmodel_lowrefmodel_lowcontains two获得在模拟过程中,每个块都会在溢出警告上产生包裹。通过访问该警告的四个实例之一,通过访问该警告的四个实例之一msldiagnosticobject associated with the wrap on overflow warning produced by one of the Gain blocks in therefmodel_lowmodel only when it is referenced byref_block1

打开顶部模型。模拟模型并将输出存储在变量中,出去

出去= sim('超模');

访问存储在msldiagnostic目的。

diag = getDiagnosticObjects(out)
diag = 1×4 MSLDiagnostic array with properties: identifier message paths cause stack

您可以在诊断查看器或命令行中查看诊断及其原因。

fori = 1 : numel(diag) disp(diag(i)); disp(diag(i).cause{1});end

Suppress one of the wrap on overflow warnings fromrefmodel_low只有从模拟中TopModel/Ref_block1by accessing the specific diagnostic. Simulate the model.

金宝appsimulink.suppressdiagnostic(diag(1)); out = sim('超模')

Access the simulation metadata. This simulation produced only three warnings.

diag = getDiagnosticObjects(out)
diag = 1×3带有属性的MSLDINGNOSTIC数组:标识符消息路径导致堆栈

Restore the diagnostic to the model.

金宝appsimulink.restorediagnostic(diag(1));

See Also

|||||