Description
You can use the "Greater than" instruction to query whether the value at input IN1 is greater than the value at input IN2. Both values to be compared must be of the same data type.
If the condition of the comparison is fulfilled, the instruction returns the result of logic operation (RLO) "1". If the comparison condition is not fulfilled, the instruction returns RLO "0".
Comparison of character strings
The individual characters are compared by means of their code (for example, 'a' is greater than 'A') during the comparison of the strings. The comparison is performed from left to right. The first character to be different decides the result of the comparison. If the left part of the longer string is identical to the shorter string, the longer string is considered greater.
The following table shows examples of string comparisons:
|
IN1 |
IN2 |
RLO of the instruction |
|---|---|---|
|
'BB' |
'AA' |
1 |
|
'AAA' |
'AA' |
1 |
|
'AA' |
'aa' |
0 |
|
'AAA' |
'a' |
0 |
You can also compare individual characters of a string. The number of the character to be compared is specified in square brackets next to the operand name. "MyString[2]", for example, compares the second character of the "MyString" string.
|
Note Status still displayed despite "inactive" instruction Under the following requirements:
Result: For the instruction "CMP >: Greater than" (data type STRING, WSTRING or VARIANT), the previous status is still shown in the network. When you switch "Monitoring on" off and on again or scroll to a different network, the correct status of the instruction "CMP >: Greater than" (data type STRING, WSTRING or VARIANT) is displayed. The instruction "CMP >: Greater than" is shown as grayed out in the network in the inactive status. |
Comparison of timers, date and time
In comparing timer values, the RLO of the instruction is "1" if the timer at input IN1 is greater (more recent) than the timer at input IN2.
Not all times can be compared directly with each other, such as S5TIME. In this case they are implicitly converted into another time so that they can be compared, for example to TIME.
If you want to compare dates and times of different data types, the value of the smaller date or time data type is implicitly converted into the larger date or time data type. This means the two date and time data types DATE and DTL, for example, are compared on the basis of DTL.
When the implicit conversions fail, the comparison result is FALSE.
Comparing tags of WORD data type to tags of the S5TIME data type
Both tags are converted to the TIME data type when comparing a tag of WORD data type to a tag of S5TIME data type. The WORD tag is interpreted as an S5TIME value. If one of the two tags cannot be converted, the comparison is not performed and the result is FALSE. If the conversion is successful the comparison is performed based on the selected comparison instruction.
Parameters
The following table shows the parameters of the "Greater than" instruction:
|
Parameters |
Declaration |
Data type |
Memory area |
Description |
|---|---|---|---|---|
|
IN1 |
Input |
Bit strings, integers, floating-point numbers, character strings, timers, date and time |
I, Q, M, D, L, P, or constant |
First comparison value |
|
IN2 |
Input |
Bit strings, integers, floating-point numbers, character strings, timers, date and time |
I, Q, M, D, L, P, or constant |
Second value to compare |
You can select the data type of the instruction from the "???" drop-down list of the instruction box.
Example
The following example shows how the instruction works:
The "TagOut" output is set when the following conditions are fulfilled:
-
The operand "TagIn_1" has the signal state "1".
-
The condition of the comparison instruction is fulfilled if "Tag_Value1" > "Tag_Value2".