For Loop
-
Hi all,
Is it possible to get a simple For loop working in scripting data source on MangoES ?
I have the following code running :for ( var i = 0; LineCurrent1 > 271 ; i + 1) {
value.set(i);
}
The aim of the code is to increment a value when a condition is met.Is this something I will be able to do using scripting data sources ?
Thank You!
-
Here's some code that I'm using in production on one of my systems, Joel helped with the syntax originally which was handy, it has javascript type syntax layout it would seem.
// check if in auto mode at Driveway Tank AND tank level below Absolute Low Point AND pump not running if((p36.value == true) && (p23.value < p52.value) && (p11.value == false)) { // open southern solenoid p28.set(true); // close northern solenoid p24.set(false); // close western solenoid p22.set(false); // start pump p11.set(true); }
Hope this helps, cheers Dan
-
Hi Udara,
The scripts use Java's implementation of JavaScript, so in Java 6 and 7 this is the Rhino engine and in Java 8 it is Nashorn. Both have all the loops and basic language features.
Your for loop may have some issues as written. For instance, it will perform 271 sets very quickly. Using our NoSQL database, you can only have one value per point per millisecond. It may work with the H2 or MySQL databases, but I don't think it's what you want.
It sounds like you want some kind of if condition leading to a...
p.set(p.value + 1);
The Scripting data source is run on a cron, so if it's on pattern 0/1 * * * * ? the point would reflect 'total seconds in state' and if you wanted to zero it when the condition is lost you can...
p.set(0);
-
@phildunlap
Thank You very much. That helped a lot.