St language is one of the 5 standard languages stipulated in Iec61131-3, the PLC which is commonly used to see the brand supports this language (Schneider, AB can directly choose to create this type of program segment or function block, Siemens a little Trouble), one of the advantages of St language is good transplant, The St language of the family is basically similar, so if there is a giant good algorithm, with St language implementation is no better, so it can be easily transplanted in multiple brands of PLC, at present, there is a precondition is in this algorithm do not use too many system function block, Because the system function block is often each brand compares the individuality thing, will cause the transplant to be troublesome. In addition, the St language is most suitable for writing some complex algorithms, the personal feel especially corresponding to some array of operations, with St language is the most convenient, of course, ladder diagram can also be achieved, but far from the convenience of St. St language syntax and Pascal very much like, sometimes a variety of languages with more, will be mixed, so here are the St language of several commonly used control statements recorded. 1,IF structure: The basic syntax is: IF bool_expression_1 then< Logical Statement >elsif bool_expression_2 then//These two lines optional < logical statement >else//These two lines are optional < Logical statements >END_IF; Examples: IF a>b thenflag:=1; elsif a<b thenflag:=2; elseflag:=3; end_if; Description: The If statement and ladder diagram in the normally open normally closed instruction is similar, not recommended to write complex logic with if statement, bool logic or ladder diagram is easy to write and intuitive, unless the St language is very love at the same time on the ladder diagram do not understand.
2,FOR structure: The basic syntax is: for
count:= Initial_valueTo
Final_valueBy
Incrementdo< Loop Body >END_FOR; Example: sum:=0;for
i:= 2To
-By
2Do
sum:=sum+i;//calculates an even number within 0-100 and containsend_for; Description: By can be followed by the step is optional, if not the default is 1. If you want to exit the loop early, you can add a judging condition inside the loop, with the exit statement, as follows: for
count:= Initial_valueTo
Final_valueBy
IncrementDoif bool_expression Thenexit; end_if; End_for; 3,case structure: Basic syntax: Case numeric_expression ofselector_1:< Logical Statements >......selector_n:< logical Statements >ELSE< logical statements >end_case ; Example: Case num of1,2,3:a:=10;4:a:=20;elsea:=100; end_case; Description: The case statement is similar to the case statement in other high-level languages, but with less break, the case here actually executes only the first statement that satisfies the condition, equivalent to automatically adding a break operation to each option. 4,while structure: Basic syntax: While bool_expression do< logic statements >END_WHILE; examples: i:=0;sum:=0; While i=100 dosum:=sum+i;i:=i+1; End_while; note: While and for are almost universally available, use it with your personal preference. The basic structure of the above, the above syntax refers to the AB information, different brands may be a slight difference between the specific use can refer to the specific brand manual.
Several program flow control statements of St language in PLC