Hello alps,
I would recommend avoiding the C-Script unless you absolutely cannot achieve what you need using standard PLECS control blocks.
Also, while the code snippet is helpful, it is difficult to understand the full context without seeing the rest of your simulation setup. Sharing the model would make it much easier to provide useful guidance.
Here is a very simple solution for on-time measurement using basic PLECS blocks. Maybe this is sufficient for your application?
onTimeMeasurement.plecs (11.5 KB)