Simulink Mask 初始化命令和 RuntimeObject
Simulink Mask initialization command and RuntimeObject
这是我的掩码初始化代码我想用它根据其中一个块的输出更改颜色
systems = find_system(gcb,'LookUnderMasks' , 'on', 'FollowLinks','on', 'SearchDepth', 1,'regexp','on','Name','Multi');
rto=get_param(systems{1,1},'RuntimeObject')
if rto.OutputPort(1).Data == 1
set_param(gcb,'BackgroundColor','red')
else
set_param(gcb,'BackgroundColor','green')
end
当我按确定时,我得到 Error: Dot indexing is not supported for variables of this type
当我使用 keyboard
进行调试时,我得到了这个
K>> rto
rto =
handle
它似乎无法获取运行时对象,但是当我在调试模式下执行此操作时
rto=get_param(systems{1,1},'RuntimeObject');
在调试时我确实得到了它
rto =
Simulink.RunTimeBlock
你的方法行不通。掩码初始化发生在模型初始化期间,此时模块输出甚至可能没有值。即使您显示的代码确实执行了,因为随着模拟的进行,掩码初始化不会发生,所以您的块的颜色不会随着信号值的变化而变化。
唯一的方法(即更改块颜色)是让代码随着模拟的进行在每个时间步执行。这通常使用 S-Function 来实现。下面是一个非常简单的 S-Function,它将根据模块输入信号的值改变它所在的子系统的颜色。
S-Function 中的代码是:
function msfcn_times_two(block)
% Level-2 MATLAB file S-Function for times two demo.
% Copyright 1990-2009 The MathWorks, Inc.
setup(block);
%endfunction
function setup(block)
%% Register number of input and output ports
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
%% Setup functional port properties to dynamically
%% inherited.
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
%% Set block sample time to inherited
block.SampleTimes = [-1 0];
%% Set the block simStateCompliance to default (i.e., same as a built-in block)
block.SimStateCompliance = 'DefaultSimState';
%% Run accelerator on TLC
block.SetAccelRunOnTLC(true);
%% Register methods
block.RegBlockMethod('Outputs', @Output);
%endfunction
function Output(block)
if block.InputPort(1).Data < -0.5
set_param(get_param(block.BlockHandle,'Parent'),'BackgroundColor','red')
elseif block.InputPort(1).Data < 0.5
set_param(get_param(block.BlockHandle,'Parent'),'BackgroundColor','green')
else
set_param(get_param(block.BlockHandle,'Parent'),'BackgroundColor','blue')
end
%endfunction
这是我的掩码初始化代码我想用它根据其中一个块的输出更改颜色
systems = find_system(gcb,'LookUnderMasks' , 'on', 'FollowLinks','on', 'SearchDepth', 1,'regexp','on','Name','Multi');
rto=get_param(systems{1,1},'RuntimeObject')
if rto.OutputPort(1).Data == 1
set_param(gcb,'BackgroundColor','red')
else
set_param(gcb,'BackgroundColor','green')
end
当我按确定时,我得到 Error: Dot indexing is not supported for variables of this type
当我使用 keyboard
进行调试时,我得到了这个
K>> rto
rto =
handle
它似乎无法获取运行时对象,但是当我在调试模式下执行此操作时
rto=get_param(systems{1,1},'RuntimeObject');
在调试时我确实得到了它
rto =
Simulink.RunTimeBlock
你的方法行不通。掩码初始化发生在模型初始化期间,此时模块输出甚至可能没有值。即使您显示的代码确实执行了,因为随着模拟的进行,掩码初始化不会发生,所以您的块的颜色不会随着信号值的变化而变化。
唯一的方法(即更改块颜色)是让代码随着模拟的进行在每个时间步执行。这通常使用 S-Function 来实现。下面是一个非常简单的 S-Function,它将根据模块输入信号的值改变它所在的子系统的颜色。
S-Function 中的代码是:
function msfcn_times_two(block)
% Level-2 MATLAB file S-Function for times two demo.
% Copyright 1990-2009 The MathWorks, Inc.
setup(block);
%endfunction
function setup(block)
%% Register number of input and output ports
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
%% Setup functional port properties to dynamically
%% inherited.
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
%% Set block sample time to inherited
block.SampleTimes = [-1 0];
%% Set the block simStateCompliance to default (i.e., same as a built-in block)
block.SimStateCompliance = 'DefaultSimState';
%% Run accelerator on TLC
block.SetAccelRunOnTLC(true);
%% Register methods
block.RegBlockMethod('Outputs', @Output);
%endfunction
function Output(block)
if block.InputPort(1).Data < -0.5
set_param(get_param(block.BlockHandle,'Parent'),'BackgroundColor','red')
elseif block.InputPort(1).Data < 0.5
set_param(get_param(block.BlockHandle,'Parent'),'BackgroundColor','green')
else
set_param(get_param(block.BlockHandle,'Parent'),'BackgroundColor','blue')
end
%endfunction