Summary
For timed operations, Elvis offers a whole range of ready-made elements (time programs, sequences, metronome). Sometimes, however, you also need time-dependent behavior for your own scripts. This article discusses the ways to make that happen.
Details
Option 1: Time Input
This method is suitable when it comes to times and accuracies from 10 seconds.
Define an input variable of type DateTime and bind it to a time data point (e.g. TimeUTC in the system port) when using the CustomItem. As a result, this input variable is updated periodically (usually every 10 seconds) and the Execute method is called accordingly.
Option 2: Using timers
It is also possible to use timers. This can be one of the Timer classes available in the .NET Framework, or better the TimedCallbackService available in the Elvis server, which calls a given method at a specified time. One difficulty here is that Elvis only evaluates changes in the output variables after an execute call, but not if it occurs “spontaneously”. Therefore, the script must inform Elvis of changes to output variables that occur within the method called by the timer.