×

Subscribe to newsletter

subscribe to our weekly newsletter to get notified with latest story and article Subscribe now!




PLC BLOG | OMRON CX-Programmer Structured Text Control Statements

Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


OMRON CX-Programmer Structured Text Control Statements

Structured Text Control Statements execute other statements based on certain condition. Statements include If statements, WHILE Statement, REPEAT Statement, FOR Statement, CASE Statement, EXIT Statement, RETURN Statement and Nested FB call. in industrial automation control statements help to create program that can adapt to changing conditions and respond to user input. Control statements change the flow of execution of statements. control statements help for making a certain decision based process and perform various tasks repeatedly, or switch to any process.


OMRON CX-Programmer Structured Text If Statements

IF statements execute code if the condition is true other wise else condition execute. You can also define a condition without else statements. expression for if statements as below
  • IF expression1 THEN statement-list1;
  • ELSIF expression2 THEN statement-list2;
  • ELSE statement-list3;
  • END_IF;
expression1 and expression2 evaluate a Boolean value (true or false) if the expression1 condition is true than statement-list1 execute otherwise expression2 executed if expression2 is true then statement-list2 executed otherwise else condition is executed. multiple if statements is known as nested if statements. There can be several ELSIF statements within an IF Statement, but only one ELSE statement.

OMRON CX-Programmer Structured Text If Statements

OMRON CX-Programmer Structured Text WHILE DO Statement

a while loop execute statement repeatedly as long as a expression is true, execution of statement list continue until the expression condition is true. in a while loop result of an expression is a Boolean value which is either true or false. When the while loop expression is true than statement is executed Once the statement inside the while block is executed, the condition of expression again evaluated, and again if the expression condition is true then statement executed and again expression check, This process continues until the condition becomes False, at which point the execution of the while statement stops and the program continues with the next line of code.
  • WHILE expression DO
  • statement-list;
  • END_WHILE;
in a while do control statement ensure that expression condition will eventually become false, otherwise while loop will continue execute statement for infinite time. this condition known as infinite loop. it make your complete program crash or a serious error in plc. include some form of condition or counter within the loop that will eventually cause the loop to exit.

OMRON CX-Programmer Structured Text WHILE Statement

above is the example of OMRON CX-Programmer Structured Text WHILE DO Statement. The WHILE expression must evaluate to a Boolean value. The statement-list is a list of several simple statements. The WHILE keyword repeatedly executes the statement-list while the expression is true. When the expression becomes false control passes to the next statement after the END_WHI


OMRON CX-Programmer Structured Text FOR DO Statement

In Programming For_Do Loop Is A Conditional Statement Used To Repeatedly Execute A Block Of Code For A Specific Number Of Times Or Until A Certain Condition Is Met. It Is Used In Array, UDT Etc. For_Do Loop Not Used To Many Time In A Single Scan Because It Causes Controller Watchdog To Timeout And Causes A Major Fault And Controller Does Not Execute Other Statements In The Routine Until It Completes The Loop.Syntax For For_Do Loop Is Below
  • FOR control variable := integer expression1 TO integer expression2 [ BY integer expression3 ] DO
  • statement-list;
  • END_FOR;
  • control variable must be an integer variable type. The FOR Do control statement executes the statement-list repeatedly until the control variable is within the range of integer expression1 to integer expression2. BY keyword incremented by integer expression3 otherwise by default it is incremented by one. The control variable is incremented after every executed call of the statement-list. When the control variable is no longer in the range integer expression1 to integer expression2, control passes to the next statement after the END_FOR.

OMRON CX-Programmer Structured Text FOR DO Statement

OMRON CX-Programmer Structured Text CASE OF Statement

CASE OF Is a Control Flow Statement That Used for Execute Different Statement list Of Code Based on the Value of the Selector or Expression. CASE OF Is An Alternative Of Multiple If-Else-If Statements. CASE OF Easy To Understand. Basic Syntax Of CASE OF Statement Is A Selector Or Expression To Be Evaluated Based On Result Label Select. In Structured Text Language, CASE OF Is A Variable Selector Or Selection Statement That Allows A Program To Choose Among Multiple Alternatives Based On The Value Of A Variable. Use CASE_OF To Select What To Do Based On A Numerical Value. Syntax for
  • CASE Selector OF
  • case label1:
  • statement-list1;
  • case label2:
  • statement-list2;
  • case label3:
  • statement-list3;
  • ELSE
  • statement-list for else
  • END_CASE;

OMRON CX-Programmer Structured Text CASE OF Statement

CASE_OF Is Control Flow Statement Which Match Selector Value With Numeric_expression If Numeric_expression And Selector Value Matched Than Statement Of Select Selector Value Is Executed Otherwise Else Statement Executed. Following Is Representation Of Working Case_Of Statement.


OMRON CX-Programmer Structured Text REPEAT Statement

The REPEAT statement repeat a statement-list a certain number of times or until a certain condition is met. The REPEAT Statement repeatedly executes the statement-list while the expression is false. When the expression becomes true control passes to the next statement after END_REPEAT. syntax for REPEAT statement is
  • REPEAT
  • statement-list;
  • UNTIL expression
  • END_REPEAT;

OMRON CX-Programmer Structured Text REPEAT Statement
 
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


Suggested Post


 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

comment