Background scripts have three predefined procedures for handling events, whose declarations are automatically generated when a new script is created:


    1. OnInitialize
    2. OnTimer
    3. OnTerminate


It is also possible to define new standard procedures (routines or functions) that can be recalled by the code contained in the special procedures.


OnInitialize

The OnInitialize procedure is a default procedure that is invoked (executed) only once, when the script engine starts. In this procedure, enter the program portions that are to be executed only at system startup, for example initialization instructions.
Within the OnInitialize procedure, the Period statement is used to specify the period of execution of the OnTimer cyclic procedure. Period receives as an argument the interval between an OnTimer procedure call and the next one, expressed in milliseconds.

OnTimer

The default OnTimer procedure is executed cyclically until the system is closed. The interval between two successive executions is specified by the Period statement, set during the execution of the OnInitialize procedure.
The OnTimer procedure contains the code to be executed cyclically for the entire period of system activity.
When the script engine is closed, the last iteration of the procedure is completed, then the repetition cycle is interrupted and the control goes to the On-terminated procedure.

 

Note: the OnTimer procedure automatically manages the interlocking of the call if the previous execution has not been completed, avoiding re-entry problems.

Procedura OnTerminate

La procedura OnTerminate viene invocata al termine dell’ultima iterazione della procedura OnTimer, in seguito alla richiesta di chiusura del motore script, ed è eseguita una sola volta.

Inserire in questa procedura le porzioni di codice che devono essere eseguite all’arresto del sistema di supervisione.

 


Caution! L’esecuzione della procedura OnTerminate viene effettuata alla chiusura del Gestore Script: se il gestore script viene chiuso manualmente, l’esecuzione della procedura non coincide con la chiusura del sistema di supervisione ma con quella del modulo!