OUTPUTS, UPDATE and DERIVATIVE blocks of Level 2 S function are not called in Executable mode (Code Generation)

We have created a Level 2 Matlab S function which runs smoothly while running in RTW mode(clicking on the play button).
When we try to run the same S function in TLC mode via Code Generation we face the below challenge
The START, INITIALIZE and TERMINATE blocks run in Executable mode, while the OUTPUT, UPDATE and DERIVATIVE blocks do not even get called.
NEED help to invoke OUTPUT, UPDATE blocks. See below, the S Function .tlc and .m attached.
.tlc file
%% File : SfuncLevel2.tlc
%implements "SfuncLevel2" "C"
%function BlockTypeSetup(block, system) void
%openfile buffer
%closefile buffer
%<LibCacheFunctionPrototype(buffer)>
%endfunction %% BlockTypeSetup
%% Function: Outputs =======================================
%function Outputs(block, system) Output
/* %<Type> Block: %<Name> */
%assign u = LibBlockInputSignal(0, "", "", 0)
%assign y = LibBlockOutputSignal(0, "", "", 0)
%% PROVIDE THE CALLING STATEMENT FOR "wrapfcn"
%assign idx = LibBlockDWorkAddr(var_index, "", "", 0)
%assign yaxis = LibBlockDWorkAddr(YAxis, "", "", 0)
%endfunction %% Outputs
.m file
function SfuncLevel2(block)
setup(block);
%endfunction
function setup(block)
% Register number of ports
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Override input port properties
block.InputPort(1).Dimensions = [1];
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.AllowSignalsWithMoreThan2D = 1;
block.OutputPort(1).Dimensions = [1];
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
block.SampleTimes = [0 0];
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);
block.RegBlockMethod('SetInputPortSamplingMode', @SetInpPortFrameData);
block.RegBlockMethod('InitializeConditions', @InitializeConditions);
block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('Outputs', @Outputs); % Required
block.RegBlockMethod('Terminate', @Terminate); % Required
%end setup
function DoPostPropSetup(block)
block.NumDworks = 2;
block.Dwork(1).Name = 'var_index';
block.Dwork(1).Dimensions = [1];
block.Dwork(1).DatatypeID = 0; % double
block.Dwork(1).Complexity = 'Real'; % real
block.Dwork(2).Name = 'YAxis';
block.Dwork(2).Dimensions = [24001];
block.Dwork(2).DatatypeID = 0; % double
block.Dwork(2).Complexity = 'Real'; % real
function InitializeConditions(block)
block.Dwork(1).Data = 1;
fprintf('Initialize %d',block.Dwork(1).Data);
%end InitializeConditions
function Start(block)
block.Dwork(1).Data = 1;
fprintf('Start %d',block.Dwork(1).Data);
% %end
function SetInpPortFrameData(block, idx, fd)
block.InputPort(idx).SamplingMode = fd;
block.OutputPort(idx).SamplingMode = fd;
%endfunction
function Outputs(block)
fprintf('Output %d',block.Dwork(1).Data);
block.OutputPort(1).Data = block.InputPort(1).Data;
block.Dwork(2).Data(block.Dwork(1).Data) = block.InputPort(1).Data;
%end Outputs%
function Update(block)
%block.OutputPort(1).Data = block.InputPort(1).Data;block.Dwork(1).Data = block.Dwork(1).Data +1;
fprintf('Update %d',block.Dwork(1).Data);
%end Update
function Terminate(block)
block.OutputPort(1).Data = block.InputPort(1).Data;
s = block.Dwork(2).Data;
%get aggregated Yaxis value into 's' and print.
%end Terminate

Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Release

R2019b

Asked:

on 29 Dec 2020

Edited:

on 29 Dec 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!