CAI Webcontrol Non-Blocking Delay Function

apostolakisl

Senior Member
The non-blocking delay function isn’t well documented in the user manual. You can place a set of brackets [] after variables, ttl inputs, an ttl outpus in most PLC lines. How this worked exactly I endeavored to figure out. So I did a bunch of experiments and found the following:

First off, Whenever a variable, ttl input, or ttl output changes value, CAI logs the old value, new value, and the time of change.

There are two tests that occur on any line of code evaluating for a “true” or “false” response when a delay operator is used (like TSTGT, TSTEQ, etc).

1) The statement is evaluated as it would have normally (had no delay operator been present).
2) The value(s) with delays are checked to see if they have changed during the previous x milliseconds where x is what you put in brackets. If they have changed, the statement will be false regardless of what the previous value was.

For example: TSTGT VAR1[500] 1

1) Check if var1 is greater than 1, just like normal.
2) Check to see the last time VAR1 changed value. If VAR1 changed within the previous 500ms, it will be false, even if both the old and new value were greater than 1. For example, VAR1 might have been at the value 100, then 200ms prior to the above line of code executing it change to 200, even though both are 100 and 200 are greater than 1, it still runs false.

Both 1 and 2 must be true for the statement to be true.

Another example: TSTEQ VAR1[300] VAR2[200]

This will 1) check if var1 and var2 are currently equal, if yes, it checks to see if var1 has been unchanged for 300ms and var2 for 200ms. If no changes occurred, and var1 and var2 are equal, then it is true, otherwise it is false.



When a line of code sets a value and that value has a delay operator, the value will be set for the period of time specified, then it will revert to the old value.

For example, if VAR1 was currently set to 10 and the following line of code were encountered.

For Example: ADD 4 5 VAR1[2000]

The function will add 4 and 5 and place the answer (9) into VAR1. After 2000ms VAR1 will revert back to the original value of 10.



If you have a mathematical function (like add, sub, mul, etc), and one or more of the values have delay operators, the entire line of code is aborted if the values were not constant throughout the delay time period.

For example: ADD VAR1[500] 5 VAR2

The function will add the value of VAR1 plus 5 and place the answer in VAR2 only if VAR1 has remained unchanged for the previous 500ms. If VAR1 has not been stable during the previous 500ms, the function is not performed and VAR2 is left unchanged. When the function is aborted, the zero bit is not updated. So a BZ, or similar command in the next line will branch according to the zero bit value as it was prior to the aborted “ADD” line above.
 
For example: TSTGT VAR1[500] 1

1) Check if var1 is greater than 1, just like normal.
2) Check to see the last time VAR1 changed value. If VAR1 changed within the previous 500ms, it will be false, even if both the old and new value were greater than 1. For example, VAR1 might have been at the value 100, then 200ms prior to the above line of code executing it change to 200, even though both are 100 and 200 are greater than 1, it still runs false.

Both 1 and 2 must be true for the statement to be true.

This may explain why reading some A/I values with the TSTGT or the TSTLT with a delay deos not work. You statement indicats that even if the value always meets the "Greater Than" criteria but does change within the delay period it becomes false.

Example:
SET AIP VAR1
TSTGT VAR1[5000] 200
SET OP1 1

So if VAR1 bounces around at 300 to 305 within 5 seconds then OP1 will not be set to 1. Correct? This is problematic A/I values since they have some fluctuation.

I though it just means if its greater than 200 for longer than 5sec then go true regardless of whatt value >200.
 
This may explain why reading some A/I values with the TSTGT or the TSTLT with a delay deos not work. You statement indicats that even if the value always meets the "Greater Than" criteria but does change within the delay period it becomes false.

Example:
SET AIP VAR1
TSTGT VAR1[5000] 200
SET OP1 1

So if VAR1 bounces around at 300 to 305 within 5 seconds then OP1 will not be set to 1. Correct? This is problematic A/I values since they have some fluctuation.

I though it just means if its greater than 200 for longer than 5sec then go true regardless of whatt value >200.

Yes, this is a good explanation of stuff. It does not operate in an "intuitive" way for variables, but at least if we know about it we can work around it.
 
This may explain why reading some A/I values with the TSTGT or the TSTLT with a delay deos not work. You statement indicats that even if the value always meets the "Greater Than" criteria but does change within the delay period it becomes false.

Example:
SET AIP VAR1
TSTGT VAR1[5000] 200
SET OP1 1

So if VAR1 bounces around at 300 to 305 within 5 seconds then OP1 will not be set to 1. Correct? This is problematic A/I values since they have some fluctuation.

I though it just means if its greater than 200 for longer than 5sec then go true regardless of whatt value >200.

The fact that any change in the value of one of the non-delay operators automatically causes a false, sometimes switching your logic around from something like TSTGT to TSTLT (and of course reversing your subsequent logic) can give you the result you are looking for.

Edit:

I think of it this way. The CAI has limited memory. It only logs the current value, the previous value, and when it changed. The non-delay operator looks back in time, so its only resource is the log. If the value changes during the delay, then it loses the time stamp from the previous change, so, even if it knows the last 2 values, it doesn't know if there was a third preceding it.

Also, I do believe that analog values are not allowed to be used with the delay operator. I did not actually check this, however, the instruction manual specifically lists variables, ttl inputs, and ttl outputs as qualifying, but makes no mention of analog. It would make sense, since analog values tend to be so fickle in nature that a delay operator would almost always run false.
 
Lou,

You are absolutely correct. The non-blocking delay only work on IPx, OPx, and VARx.
Each time a value in those above being updated, the timestamp will be updated.
 
is there a way to test var1 against it previous value and if changed then do something? For instance (I don't think this will work but gives the idea of what I am after)
Tstne var1[2000] var1
Set webset
 
TJF1960 said:
is there a way to test var1 against it previous value and if changed then do something? For instance (I don't think this will work but gives the idea of what I am after)
Tstne var1[2000] var1
Set webset
 
 
This should accomplish what you want
 
TSTEQ VAR1[2000] VAR1
GOTO SKIP
WEBSET (your parameters)
SKIP:
 
 
or this
 
TSTEQ VAR1[2000] VAR1
NOP
CZ SUB1
 
SUB1:
WEBSET (your parameters)
RET
 
I haven't tested these, but the logic should work.  Webset should occur only if var1 has been unchanged for 2 seconds.
 
Lou is correct,
when VAR is NOT followed with non-blocking delay brackets, it will return current value. 
If it has delay and the delay has not expired, it will return older value.
It if has delay and the delay has already expired, it will return new value.
 
Thank you.
 
Is it possible using non-blocking delay to watch var1 for change, if it changes then webset, otherwise if no change then no webset. I am looking for it to webset only once every two seconds only if it changes since the last webset.
 
I do it now by copying var1 to ram1 then test against it every 2 seconds but it ties up ram1 for ever. Just trying to figure out if there is a simpler way or not and free up ram where possible.
 
TJF1960 said:
Thank you.
 
Is it possible using non-blocking delay to watch var1 for change, if it changes then webset, otherwise if no change then no webset. I am looking for it to webset only once every two seconds only if it changes since the last webset.
 
I do it now by copying var1 to ram1 then test against it every 2 seconds but it ties up ram1 for ever. Just trying to figure out if there is a simpler way or not and free up ram where possible.
 
 
 
TSTEQ VAR1[2000] VAR1
NOP
CZ SUB1
 
SUB1:
TSTEQ OP1 1
RET
WEBSET (your parameters)
SET OP1[2000] 1
RET
 
Back
Top