From OpenSCADAWiki
Jump to: navigation, search
Other languages:
Constr.png Generic revision and translation

Author: Roman Savochenko

Novice users often have question about time intervals hold while programming calculation procedures in the OpenSCADA environment. This question is usually associated with the presence of previous programming experience in linear calculations and lack of experience in programming of cyclic real-time systems.

The so-called tact or cycle of periodical calculations, ie the life rhythm is used in the real-time systems. Some procedure is calculated in each cycle that should not take more time than the cycle. As a consequence, if the cycle procedure stops for waiting, the life of the real-time system stops too. Hence, the using of traditional sleep task functions into such procedures is unacceptable!

The solution of the desired exposure time interval in the real-time systems, within the rhythm of life, is made in two ways. The first way is to decrement the counter value, set to the time interval, in each cycle by the cycle frequency to the value <= 0, for example, in OpenSCADA it is implemented as follows:

if((tm_cnt-=1/f_frq) <= 0)  //Decrement
{
    tm_cnt = 10; //Set the counter to a value of 10 seconds
    //Other actions with the periodicity of 10 seconds
}

The second way is based on the astronomical time, ie the comparison with the current time is made in the cycle, for example, in OpenSCADA it is implemented as follows:

if(SYS.time() > tm_to)
{ 
    tm_to = SYS.time()+10; //Setting the waiting threshold for 10 seconds more than the current time
    //Other actions with the periodicity of 10 seconds
}

The second method is more reliable because it excludes the operation delay problem due to the possibility of calculating the cycle procedure over the cycle time. Although in the properly configured systems and tasks, this problem should not occur.