These instructions compare the sizes of two or more text strings.
LTascii : Performs a less than comparison.
LEascii : Performs a less than or equal comparison.
GTascii : Performs a greater than comparison.
GEascii : Performs a greater than or equal comparison.
Instruction Name FB/
FUN Graphic expression ST expression
LTascii
Text String Comparison Less Than
FUN
(@)LTascii
EN Out In1
: InN
: Out:=LTascii(In1, ···, InN);
LEascii
Text String Comparison Less Than or Equal
FUN
(@)LEascii
EN Out In1
: InN
: Out:=LEascii(In1, ···, InN);
GTascii
Text String Comparison Greater Than
FUN
(@)GTascii
EN Out In1
: InN
: Out:=GTascii(In1, ···, InN);
GEascii
Text String Comparison Greater Than or Equal
FUN
(@)GEascii
EN Out In1
: InN
: Out:=GEascii(In1, ···, InN);
Variables
Meaning I/O Description Valid range Unit Default
In1 to InN Comparison text
strings Input Text strings to compare
N = 2 to 5
Depends on
da-ta type. --- '’*1
Out Comparison result Output Comparison result Depends on
da-ta type. ---
---*1. If you omit the input parameter that connects to InN, the default value is not applied, and a building error will occur.
For example, if N is 3 and the input parameters that connect to In1 and In2 are omitted, the default values are applied, but if the input parameter that connects to In3 is omitted, a building error will occur.
Comparison Instructions
2
LTascii, LEascii, GTascii, and GEascii
Boo
lean Bit strings Integers
Real num-bers
Times, durations, dates, and text strings
BOOL BYTE WORD DWORD LWORD USINT UINT UDINT ULINT SINT INT DINT LINT REAL LREAL TIME DATE TOD DT STRING
In1 to InN OK
Out OK
Function
These instructions compare the sizes of from two to five text strings in In1 to InN (N = 2 to 5).
The output value Out is shown below for each instruction.
Instruction Value of Out
LTascii If In1 < In2 < ... < InN, Out is TRUE. Otherwise, it is FALSE.
LEascii If In1 ≤ In2 ≤ ... ≤ InN, Out is TRUE. Otherwise, it is FALSE.
GTascii If In1 > In2 > ... > InN, Out is TRUE. Otherwise, it is FALSE.
GEascii If In1 ≥ In2 ≥ ... ≥ InN, Out is TRUE. Otherwise, it is FALSE. The sizes of the character codes are compared. The comparison procedure
The sizes of the character codes are compared. The comparison procedure is as follows:
First, the first character codes in all of the text strings are compared. If the character codes are differ-ent, the result of the size comparison for the text strings is determined by the size relationship be-tween those character codes.
If the character codes are the same, comparison continues in order to the other characters until a dif-ferent character code is found.
If the lengths of the text strings are different, NULL characters (16#00) are added to the shorter text string to complete the comparison.
The relationships between various text strings are as follows:
'AD'(16#414400) < 'BC'(16#424400) 'ADC' (16#41444300) < 'B’ (16#42000000) 'ABC' (16#41424300) < 'ABD’ (16#41424400) 'ABC' (16#41424300) > 'AB’ (16#41420000) 'AB' (16#414200) = 'AB’ (16#414200)
If the text string contains multi-byte characters, the characters are separated into individual bytes be-fore comparison. For example, the two-byte character 16#C281 is handled as 16#C2 and 16#81.
The following example for the LEascii instruction is for when In1 is "AB", In2 is "AC", and In3 is "AC".
The value of variable abc will be TRUE.
abc:=LEascii(’AB’, ‘AC’, ‘AC’);
LD ST
‘AB’
‘AC’
‘AC’
LEascii abc EN In1 In2 In3
'AB' 'AC'
TRUE Out = abc
In1 In2 In3
Values are compared to see if In1 ≤ In2 ≤ In3.
The LEascii instruction determines if In1 ≤ In2 ≤ In3.
If the comparison conditions are met, the value of abc will be TRUE.
Comparison conditions met.
'AC'
Additional Information
The text string comparison instructions are convenient when you want to reorder text strings according to the character codes. For example, the character codes for alphabet characters are in the same or-der as the alphabet characters. This allows you to alphabetize.
Version Information
With Sysmac Studio version 1.02 or higher, the instructions, LT (<), LE (<=), GT (>), and GE
(>=) on page 2-108, can also be used to compare text strings. The specifications of the LT (<),LE (<=), GT (>), and GE (>=) instructions for comparing text strings are the same as those of the LTascii, LEascii, GTascii, and GEascii instructions.
Precautions for Correct Use
• Do not use this instruction as the rightmost instruction on a rung. If you do, an error occurs on the Sysmac Studio and you cannot transfer the user program to the Controller.
• If this instruction is used in a ladder diagram, the value of Out changes to FALSE when an error occurs in the previous instruction on the rung.
• Specify text strings that contain only ASCII characters for In1 to InN.
Comparison Instructions
2
LTascii, LEascii, GTascii, and GEascii
Cmp
The Cmp instruction compares two values.
Instruction Name FB/
FUN Graphic expression ST expression
Cmp Compare FUN
(@)Cmp EN ENO In1 Out In2 OutEQ OutGT OutGE OutNE OutLT OutLE
Out:=Cmp(In1, In2, OutEQ, OutGT, OutGE, OutNE, OutLT, OutLE);
You can omit Out.
Variables
Meaning I/O Description Valid range Unit Default
In1 and In2 Comparison data Input Values to compare Depends on
da-ta type. --- *1
Out Return value
Output
Always TRUE TRUE only
---
---OutEQ Equal flag Equal flag
Depends on da-ta type.
OutGT Greater than flag Greater than flag
OutGE Greater than or equal flag
Greater than or equal flag
OutNE Not equal flag Not equal flag
OutLT Less than flag Less than flag
OutLE Less than or equal flag Less than or equal flag
*1. If you omit the input parameter, the default value is not applied. A building error will occur.
Boo
lean Bit strings Integers
Real num-bers
Times, durations, dates, and text strings
BOOL BYTE WORD DWORD LWORD USINT UINT UDINT ULINT SINT INT DINT LINT REAL LREAL TIME DATE TOD DT STRING
In1 and In2 OK OK OK OK OK OK OK OK OK OK
Out OK
OutEQ OK
OutGT OK
OutGE OK
OutNE OK
OutLT OK
OutLE OK
Function
The Cmp instruction compares two values (In1 and In2) and outputs flag values.
The values of the flags are as follows:
Flag Value
OutEQ If In1 equals In2, the flag shows TRUE. Otherwise the flag shows FALSE.
OutGT If In1 is greater than In2, the flag shows TRUE. Otherwise the flag shows FALSE.
OutGE If In1 is greater than or equal to In2, the flag shows TRUE. Otherwise the flag shows FALSE.
OutNE If In1 is not equal to In2, the flag shows TRUE. Otherwise the flag shows FALSE.
OutLT If In1 is less than In2, the flag shows TRUE. Otherwise the flag shows FALSE.
OutLE If In1 is less than or equal to In2, the flag shows TRUE. Otherwise the flag shows FALSE.
The following example is for when In1 is INT#10 and In2 is INT#20. The values of variables def, ghi, and jkl will be FALSE, and the values of abc, mno, pqr, and stu will be TRUE.
abc:=Cmp(INT#10, INT#20, def, ghi, jkl, mno, pqr, stu);
LD ST
abc def ghi jkl mno pqr stu INT#10
INT#20
Cmp EN ENO In1 In2 OutEQ OutGT OutGE OutNE OutLT OutLE
INT#10 INT#20
TRUE FALSE FALSE FALSE TRUE TRUE TRUE Out=abc
OutEQ=def OutGT=ghi OutGE=jkl OutNE=mno OutLT=pqr OutLE=stu
In1 In2
In1 and In2 are compared.
The Cmp instruction compares In1 and In2.
The results are given below for the various criteria.
Out Always TRUE
OutEQ FALSE because In1 does not equal In2.
OutGT FALSE because In1 is not greater than In2.
OutGE FALSE because In1 is not greater than or equal to In2.
OutNE TRUE because In1 does not equal In2.
OutLT TRUE because In1 is less than In2.
OutLE TRUE because In1 is less than or equal to In2.
Precautions for Correct Use
• If the data types of In1 and In2 are different, one will be cast to the other data type which can ac-commodate every possible value in both of the data types before comparison.
• If In1 and In2 are real numbers and include any non-terminating decimal numbers, error may cause unexpected processing results.
• Signed integers (SINT, INT, DINT, and LINT) cannot be compared to unsigned integers (USINT, UINT, UDINT, and ULINT).
• Two values that are positive infinity or two values that are negative infinity are equivalent.
• If the value of either In1 or In2 is nonnumeric data, the values of OutEQ, OutGT, OutGE, OutNE,
OutLT, and OutLE are FALSE.Comparison Instructions
2
Cmp