MATLAB: How to use “LibGetTaskTimeFromTID” to get simulation time of the top-level model instead of the referenced model

absoluteEmbedded Coderlibgettasktimefromtidreferencetimetop

I have a model in which I have configured a one time event that fires from 1s to 1.25s, whereas in my referenced model, I have a subsystem enable that goes from 0.5s to 6s.
I am logging time with a custom TLC and S-function that creates a text file with the logged times.
The time in the produced text file with function "LibGetTaskTimeFromTID(block)" is written from 0-0.249 instead from 1-1.25 as if the time starts to count when it begins to be activated.
Do you have any recommended solutions to solve this issue and get the absolute time?

Best Answer

"LibGetTaskTimeFromTID" returns the absolute time of the task associated with the block with respect to the parent system.
This is a export model, which is referenced from a top model. The time elapsed inside the top model is not counted inside the referenced model, which is expected.
As a workaround, send the elapsed time of the top model to the referenced model as an input and add that to the return of "LibGetTaskTimeFromTID".
In order to send the elapsed time of the top model to the referenced model as an input and add that to the return of "LibGetTaskTimeFromTID", use another S-Function on the top model in which we use the function "LibGetTaskTimeFromTID(block)" and output that value.
Other option is to use the clock block to get the simulation time in the top model and pass that to the referenced model: