Chapter 6 Applied Instructions
6-457
API Instruction code Operand
Function
2106 $LEN P
S, D
Calculating the length of the string
Device
X Y M S T C HC D L SM SR E PR K 16# “$” DF
Pulse instruction 16-bit instruction (5-11 steps)
32-bit instruction
Symbol:
S
:
String Word/Double word
D
:
Length of the string Word/Double word
Explanation:
1. The length of the string in S is calculated, exclusive of 16#00 with which the string ends. The
length of the string is stored in D.
2. The value stored in D should be within the range between 0 and 65535.
If the number of characters contained in the string is 65536, which is equal to 16#10000, the
value in D is 0.
If the number of characters contained in the string is 65537, which is equal to 16#10001, the
value in D is 0.
b15
b0
b7 b8
First character
S
S+1
b15
b0
D
Length of the string
Second character
Third character
Fourth character
Fifth character
Sixth character
n character
th
16#00
()Endind character
S+2
S+n
n
If the data in S~S+4 is ABCDEFGHI, the calculation result is as follows.
b15
b0
b7 b8
S
S+1
b15
b0
D
16#00
()Ending character
S+2
S+4
S+3
16#41(A)16#42(B)
16#43(C)
16#44(D)
16#45(E)16#46(F)
16#47(G)
16#48(H)
16#49(I)
ABCDEFGHI
9
Example 1:
Suppose S is the string “DELTA”. When the PLC runs, the value in D0 is 5.