主要内容

本页采用了机器翻译。点击此处可查看英文原文。

addInstrument

将仪表对象添加到目标对象

说明

addInstrument(target_object,instrument_object) 向目标对象添加仪表对象。请确保在将仪表对象添加到目标对象之前,先向该仪表对象添加信号,否则将无法传输信号。

addInstrument() 函数将仪表与实时应用程序绑定时,Simulink® Real-Time™ 会验证仪表中的信号名称。为了缩短仪表验证所需的时间,请将该仪表添加到目标计算机一次,然后根据需要多次运行实时应用程序。即使实时应用程序停止并重新加载后,该仪表仍会保留在目标计算机上。

或者,您也可以在实时应用程序每次运行时添加该仪表。如果采用这种方法,请在实时应用程序关闭时移除该仪表。例如,如果在 App Designer 应用中添加代码,可以在 CloseRequestFcn 中添加一个 removeInstrument(hInst) 函数。

示例

addInstrument(target_object,instrument_object,'updateWhileRunning') 会向目标对象添加一个仪表对象,并更新目标连接,即使实时应用程序正在运行时也是如此。请确保在将仪表对象添加到目标对象之前,先向该仪表对象添加信号,否则将无法传输信号。

示例

示例

全部折叠

创建目标对象。构建实时应用程序。创建仪表对象。向仪表对象添加信号。加载实时应用程序。向目标对象添加一个仪表对象。启动实时应用程序。

tg = slrealtime;
mdlSTF = getSTFName(tg);
mdlName = 'slrt_ex_pendulum_100Hz';
openExample(mdlName);
set_param(mdlName,"SystemTargetFile",mdlSTF);
slbuild(mdlName);
hInst = slrealtime.Instrument('slrt_ex_pendulum_100Hz.mldatx');
hInst.addSignal('slrt_ex_pendulum_100Hz/cartposition',1)
load(tg,mdlName);
addInstrument(tg,hInst);
start(tg);

若要通过编程方式启动和停止向“仿真数据检查器”传输信号,可以使用 addInstrument 函数和 removeInstrument 函数。

% Create target object and build the real-time application.
tg = slrealtime;
mdlSTF = getSTFName(tg);
mdlName = 'slrt_ex_pendulum_100Hz';
openExample(mdlName);
set_param(mdlName,"SystemTargetFile",mdlSTF);
slbuild(mdlName);

% Create instrument object and add a signal to it. 
myInst = slrealtime.Instrument('slrt_ex_pendulum_100Hz.mldatx');
addSignal(myInst,'slrt_ex_pendulum_100Hz/cartposition',1); 

% Load the real-time application and start.
load(tg,mdlName);
start(tg);

% To start streaming to the Simulation Data Inspector
% add the instrument to the target object.
addInstrument(tg,myInst); 

% To stop streaming the signal, you can use removeInstrument.
removeInstrument(tg,myInst);

输入参数

全部折叠

表示目标计算机的对象,指定为 Target 对象。该对象提供了用于操作目标计算机属性的方法。

示例: tg

要创建仪表对象,请使用 Instrument 函数。

示例: hInst

版本历史记录

在 R2020b 中推出