22.11.13 Operation Example
Logical Operation
Examples
The following shows logical operation examples.
Result: ON
Result: OFF
Result: ON
Result: OFF
Result: OFF
Result: ON
Result: True if D200 is smaller than 10.
Result: True if D200 is 0.
Result: True if D200 is 2 or 5.
Result: True if D200 is greater than 5 and
less than 10.
Result: True if D200 is smaller than 5, and
D300 is smaller than 8.
Bit Operation
Examples
The following shows bit operation examples.
Result: The data in D200 is shifted 4 bits to
the left.
Result: The data in D200 is shifted 4 bits to
the right.
[ w:[PLC1]D200 ] = [w:[PLC1]D300 ] >>
[w:[PLC1]D301 ]
Result: The data in D300 is shifted 12 bits to the right and
assigned to D200.
Result: The data in D200 is shifted 4 bits to
the left.
Result: The data in D200 is shifted 4 bits to
the right.
[ w:[PLC1]D200 ] = [w:[PLC1]D300 ] >>
[w:[PLC1]D310 ]
Result: The data in D300 is shifted 12 bits to the right and
assigned to D200.
0 & 0 // Result is 0
0 & 1 // Result is 0
1 & 1 // Result is 1
0x1234 & 0xF0F0 // Result is 0x1030
0 | 0 // Result is 0
0 | 1 // Result is 1
1 | 1 // Result is 1
0x1234 | 0x9999 // Result is 0x9BBD
0 ^ 0 // Result is 0
0 ^ 1 // Result is 1
1 ^ 1 // Result is 0
~ 0 // Result is 0xFFFF
~ 1 // Result is 0xFFFE
Conditional Branch
Usage Calculation Examples
Control program flow using "if-endif" and "if-else-endif"
if (condition)
{expression1}
endif
If the condition is true, Process 1 is run. If false, skips
Process 1.
For example,
if ( [w:[PLC1]D200 ] < 5 )
{
[ w:[PLC1]D100 ] = 1
}
endif
If data in D200 is less than 5, then assigns 1 to D100.
if (condition)
{expression1}
else
{expression2}
endif
If the condition is true, runs Process 1. If false, runs Process
2.
For example,
if ( [w:[PLC1]D200 ] < 5 )
{
[ w:[PLC1]D100 ] = 1
}
else
{
[ w:[PLC1]D100 ] = 0
}
endif
If the value in D200 is less than 5, assigns 1 to D100.
Otherwise, assigns 0.
Offset
Address Usage Calculation Examples
Offset Specification: Special Calculation Examples Using
[w:D00100]#[t:0000].
100+65526=64(Hex)+FFF6(Hex)=1005A*1(Hex)→005A(Hex)=90
100+(-10)=64(Hex)+FFF6(Hex)=1005A*1(Hex)→005A(Hex)=90
100+4294901840=64(Hex)+FFFF0050(Hex)=FFFF00B4*1(Hex)→00B4(Hex)=180
100+(-65456)=64(Hex)+FFFF0050(Hex)=FFFF00B4*1(Hex)→00B4(Hex)=180
-
Offset addresses are always treated as 16
bit Bin values, regardless of the script's Bit Length and Data Type
settings. If the result exceeds 16 bits (Maximum Value: 65535),
Bits 0 to 15 are treated as the valid bits, and bits 16 and higher
are discarded.
|