misunderstanding CMP...
MartyMaucher said:
...This is a simple comparison of a bit to zero.
Yes, you were overthinking it and obviously very new to the instruction set available to you. The Examine-If-Open (XIO) and Examine-If-Closed (XIC) instructions are indeed the best comparison instructions to use on a single BOOL tag value for simple 0 or 1 evaluations. The Equal (EQU) and Limit (LIM) instructions also being of use in that regard.
But, for the Compare (CMP) instruction, as well as not supporting the use of the BOOL data type for tags you add to the expression, it is also important to note that you also cannot use boolean expressions, even when using one of the correct data types, such as the mentioned SINT, INT, DINT, REAL, or String.
An example of a boolean expressions is your "bHoldAnalogsDuringCal = 0". Even if that tag is of the DINT data type you cannot use that expression. Whether entered on their own, as you have done, or even if entered using any of the supported data types, the boolean "= 1" or "= 0" expressions are invalid. This can also be said for the Compute (CPT) instruction.
So an expression such as...
DINT tag:
TagToCompare1 = 0
...is invalid.
As is...
DINT tags:
TagToCompare1 = 0 OR TagToCompare2 = 0
They both contain boolean expressions, which are not supported.
The Compare (CMP) instruction is used with the bitwise operators OR, AND, XOR, NOT. These operators are used to create an expression which evaluates the value of say two tags.
So an expression such as...
DINT tags:
TagToCompare1 OR TagToCompare2
...would be valid.
For the above expression, if both DINT tag values = 0 then the instruction evaluates as FALSE.
If either tag value is a non-zero value then the instruction evaluates as TRUE.
For kicks...
If you wanted to "fool" the instruction and still evaluate a boolean value then you could assign a DINT tag as a BOOL holder and just use the first BOOL of the DINT, say "TagToCompare1.0", as your intended BOOL tag, leaving the rest of the DINT unused. This way, setting and resetting the BOOL within the DINT will only change the DINT value between "0" and "1". Now you have a valid data type, which acts as a boolean.
In the CMP instruction you can enter the expression...
DINT tag:
TagToCompare1
...and it will be valid.
Here, if the DINT tag value is 0, the instruction evaluates as FALSE.
If the tag value is a non-zero value then the instruction evaluates as TRUE.
You could also enter the expression...
DINT tag:
TagToCompare1 OR TagToCompare1
...and it would also be valid, even though the same tag is used twice. This is of no real use but it just demonstrates what is supported and what is not.
To take it a little further to something "useful" you could compare two BOOL values using two DINT tags setup as before, using only the first BOOL element of the DINT.
You could then enter the expression...
DINT tags:
TagToCompare1 OR TagToCompare2
...and again it would be valid.
Here, the result is similar to the earlier example using two actual DINT tags, except you are indirectly comparing two BOOL tag values...
If both BOOL tag values (within the DINTs) = 0 then the instruction evaluates as FALSE.
If either BOOL tag value is a non-zero value then the instruction evaluates as TRUE.
Again, this is just for kicks and only intended to demonstrate not only the aforementioned and unsupported BOOL data type, but also the unsupported boolean expression for these instructions. It would be convoluted to implement this sort of comparison at the boolean level.
Regards,
George