文档

以编程方式抑制诊断消息

以下示例显示了如何以编程方式管理诊断抑制。

以编程方式抑制诊断消息

此示例显示了如何访问仿真元数据以管理诊断抑制并以编程方式恢复诊断消息。

创建一个新文件夹并复制相关文件

  1. Create a local working folder, for example,C:\ diadnostic_suppressor_demo

  2. Change to thedocroot\toolbox\simulink\examplesfolder. At the MATLAB®命令行,输入:

    cd(fullfile(docroot, 'toolbox', 'simulink', 'examples'))

  3. 复制getDiagnosticObjects.m,,,,suppressor_script.m,,,,anduspressor_cli_demo。slx文件到您本地的工作文件夹。

    getDiagnosticObjects.mfunction queries the simulation metadata to access diagnostics that were thrown during simulation. Thesuppressor_script.m脚本包含用于抑制和恢复诊断的命令uspressor_cli_demo模型。

    getDiagnosticObjects.m

Open and Simulate the Model

打开模型。访问万博1manbetxSimulink.SimulationMetadata,,,,set theReturnWorkspaceOutputs参数值为'上'。模拟模型。

模型='suppressor_cli_demo';Open_System(模型);set_param(型号,“ returnworkSpaceOutputs”,,,,'上');out = sim(model);

Get Message Identifiers from Simulation Metadata

Find the names of diagnostic message identifiers using the simulation metadata stored in theMSLDiagnosticobject.

if(exist('out',,,,'var'))diag_objects = getDiagnosticObjects(out);结尾

在模拟过程中产生了几个警告,包括数据类型转换器block. Query thediag_objects可变以获取有关标识符的更多信息。

diag_objects(5)
ANS =具有属性的MSLDIANGNOSTIC:标识符:'SimulinkFixedPoint:U万博1manbetxTIL:饱和杂费'消息:'发生饱和。它起源于“ uspressor_cli_demo/con…”路径:{'suppressor_cli_demo/convert/fixpt to fixpt3'}原因:{} stack:[0×1 struct]

抑制块上的饱和诊断

使用万博1manbetxsimulink.suppressdiagnosticfunction to suppress the saturation diagnostic on the data type conversion block only. Simulate the model.

万博1manbetxsimulink.suppressdiagnostic('suppressor_cli_demo/convert/fixpt to fixpt3',,,,...'万博1manbetxsimulinkfixedpoint:util:饱和度');set_param(型号,“仿真”,,,,'start');

Restore the Saturation Diagnostic

使用Simulink.restoreDiagnostic功能以恢复同一块的饱和诊断。

Simulink.restoreDiagnostic('suppressor_cli_demo/convert/fixpt to fixpt3',,,,...'万博1manbetxsimulinkfixedpoint:util:饱和度');set_param(型号,“仿真”,,,,'start');

Suppress Multiple Diagnostics on a Source

You can suppress multiple warnings on a single source by creating a cell array of message identifiers. Suppress the precision loss and parameter underflow warnings of theConstant堵塞,,,,,in the model.

diags = {'万博1manbetxsimulinkFixedPoint:util:fxpparameterPrecisionLoss',,,,...'SimulinkFixedPoint:util:fxpParameterUnderflow'}; Simulink.suppressDiagnostic('suppressor_cli_demo/一个',诊断);set_param(型号,“仿真”,,,,'start');

Restore All Diagnostics on a Block

Restore all diagnostics on a specified block using theSimulink.restoreDiagnostic功能。

Simulink.restoreDiagnostic('suppressor_cli_demo/一个');set_param(型号,“仿真”,,,,'start');

Suppress a Diagnostic on Many Blocks

You can suppress one or more diagnostics on many blocks. For example, use thefind_system创建所有单元格数组的功能数据类型转换器blocks in a system, and suppress all saturation warnings on the specified blocks.

dtc_blocks = find_system('suppressor_cli_demo/convert',,,,...'blocktype',,,,'DataTypeConversion');万博1manbetxsimulink.suppressdiagnostic(dtc_blocks,'万博1manbetxsimulinkfixedpoint:util:饱和度');set_param(型号,“仿真”,,,,'start');

Restore All Diagnostics Inside a Subsystem

您也可以使用Simulink.restoreDiagnosticfunction to restore all diagnostics inside a specified subsystem.

Simulink.restoreDiagnostic('suppressor_cli_demo/convert',,,,...'找到所有',,,,'上');set_param(型号,“仿真”,,,,'start');

一个dd Comments and User Information to a Suppression

一个SuppressedDiagnostic对象包含有关抑制源和抑制诊断消息标识符的信息。您还可以包括评论,以及上次修改抑制作用的用户名称。

Object = Simulink.SuppressedDiagnostic('Suppressor_CLI_Demo/Convert/FixPt To FixPt1',,,,...'万博1manbetxsimulinkfixedpoint:util:饱和度');object.comments ='Reviewed: John Doe';Object.LastModifiedBy ='Joe Schmoe'set_param(型号,“仿真”,,,,'start');
Object = SuppressedDiagnostic with properties: Source: 'Suppressor_CLI_Demo/Convert/FixPt To FixPt1' Id: 'SimulinkFixedPoint:util:Saturationoccurred' LastModifiedBy: 'Joe Schmoe' Comments: 'Reviewed: John Doe' LastModified: '2016-Jun-21 18:23:01'

Get Suppression Data

抑制数据为了a certain subsystem or block, use the万博1manbetxsimulink.getSuplastedDiarostics功能。

object = 万博1manbetxsimulink.getSuppressedDiagnostics('Suppressor_CLI_Demo/Convert/FixPt To FixPt1');set_param(型号,“仿真”,,,,'start');

还原模型上的所有诊断

When a model contains many diagnostic suppressions, and you want to restore all diagnostics to a model, use the万博1manbetxsimulink.getSuplastedDiarostics返回数组的功能万博1manbetxsimulink.suppresseddiarostic对象。然后使用万博1manbetxsimulink.suppresseddiagnostic.restore当您通过阵列迭代时的方法。

objects = 万博1manbetxsimulink.getSuppresseddiagnostics('suppressor_cli_demo');为了iter = 1:numel(Objects) restore(Objects(iter));结尾set_param(型号,“仿真”,,,,'start');

抑制引用模型的诊断消息

This example shows how to suppress a diagnostic when the diagnostic originates from a referenced model. By accessing theMSLDiagnostic警告的特定实例的对象,您只能在指定的顶部模型中模拟引用模型的情况下抑制警告。

此示例模型包含相同引用模型的两个实例,RefModel。该模型RefModel参考另一个模型,RefModel_LowRefModel_Low包含两个Gainblocks that each produce a wrap on overflow warning during simulation. Suppress one of the four instances of this warning in the model by accessing theMSLDiagnostic与溢出警告的包装相关联的对象,由一个增益块之一产生RefModel_Low仅当模型被引用Ref_block1

Open the top model. Simulate the model and store the output in a variable,out

out = sim('TopModel');

一个ccess the simulation metadata stored in theMSLDiagnosticobject.

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

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

为了i = 1:numel(diag)disp(diag(i));disp(diag(i).cause {1});结尾

抑制一种从溢流警告中的包裹RefModel_Lowonly when it is simulated fromtopmodel/ref_block1通过访问特定的诊断。模拟模型。

万博1manbetxsimulink.suppressdiagnostic(diag(1));out = sim('TopModel'

访问模拟元数据。该模拟仅发出三个警告。

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

恢复模型的诊断。

Simulink.restoreDiagnostic(diag(1));

也可以看看

|||||

Was this topic helpful?