I have the following code in a single CALC block:
'^/TIME.CV' := time_to_str("%h", time('$time_format:Local'));
IF '^/TIME.CV' < '^/STOP.CV' OR '^/TIME.CV' >= '^/START.CV' THEN '^/PARAM1.CV' := "OK";ELSE '^/PARAM1.CV' := "NOT OK";ENDIF;
The code basically checks if the time is within a range and sets a parameter based on this using the IF statement.
TIME, START and START are all 32 bit unsigned integers. The hour value is getting written to the TIME parameter but the block is showing an error and not executing the IF statement.
BUT
If I split the code across two CALC blocks as below:
CALC Block 1:
CALC Block 2:
IF '^/TIME.CV' < '^/STOP.CV' OR '^/TIME.CV' >= '^/START.CV' THEN'^/PARAM1.CV' := "OK";ELSE'^/PARAM1.CV' := "NOT OK";ENDIF;
the code works with no issues.
Any idea why this may be?
In reply to Trevor Osborne:
Andre Dicaire
In reply to Andre Dicaire:
Andre, followup question: Based on what you said above, if the TIME parameter is updated at the end of the scan and then used on the next scan why does it matter if it's set at the start or end of the CALC block? Would it not execute as per the below?: Scan 1: The IF statement does not work as the TIME parameter does not yet have a value. Time value is set at the end of the first scan. Scan 2: TIME parameter has a value from scan 1 so IF statement can now execute.
NOTE: TIME is an integer.
In your example the TIME parameter will always have a value and the IF statement will run on the first scan using the configured default value of TIME parameter. After this execution it will be using what the value was the last time the logic was executed.
Here is a quick test config I did to help show how execution of this works: