Novice users often have a question about providing time intervals 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 the experience in programming of the cyclic real-time systems.
In real-time systems, the so-called tact or cycle of periodic calculations is used — the rhythm of "life". At each tact, some procedure is performed, which should not take more time of the tact — cycle period. As a result, if the tact procedure stops at the waiting, then the life of the real-time system stops. Accordingly, it is inappropriate to use traditional functions of sleeping the task in these procedures in large intervals!
Solving the problem of holding a large time interval, more than the periodicity of the cycle, in the systems of real time is carried out in two ways.
The first method consists in decrement of the counter, set in the time interval value, in each cycle, and at the periodicity of the cycle to the value of <= 0, for example, in OpenSCADA this is implemented as follows:
if((tm_cnt-=1/f_frq) <= 0) { //Decrement
tm_cnt = 10; //Setting the counter to 10 seconds
//Perform other actions with the 10 seconds period
}
The second method is based on absolute time, that is 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 — loss of loops-cycles. Although this effect should not occur in properly configured configurations and tasks, and also the latest versions of OpenSCADA mainly take into account such loop losses in the calculation of the value f_frq.
Documents/How_to/Cyclic_programming/en - GFDL | May 2024 | OpenSCADA 0.9.7 |