參考文獻: MELSEC-Q/L/F Structured Programming Manual (Fundamentals).pdf
- The ST language is a text language with a similar grammatical structure to the C language.
- Controls such as conditional judgement and repetition process written in syntax can be described.
- This language is suitable for programming complicated processes that cannot be easily described by a graphic language (structured ladder/FBD language).
Operators & Data Types
- Operators
- Data Types
Syntax
- Assignment
- 格式:<Left side> := <Right side>;
- 範例
- intV1 := 0;
- intV2 := 2;
- Array type labels
- The data type and the number of elements need to be the same for left side and right side.
- intAry1 := intAry2;
- Structure labels
- The data type (structured data type) needs to be the same for left side and right side.
- dutVar1 := dutVar2;
- IF THEN Conditional Syntax
- 格式:IF <Boolean expression> THEN<Syntax ...>;END_IF;
- 範例IF bool1 THENintV1 := intV1 + 1;END_IF
- IF ...ELSE Conditional Syntax
- 格式:IF <Boolean expression> THEN<Syntax 1 ...>;ELSE<Syntax 2 ...>;END_IF;
- 範例IF bool1 THENintV3 := intV3 + 1;ELSEintV4 := intV4 + 1;END_IF;
- IF ...ELSEIF Conditional Syntax
- 格式:IF <Boolean expression 1> THEN<Syntax 1 ...>;ELSIF <Boolean expression 2> THEN<Syntax 2 ...>;ELSIF <Boolean expression 3> THEN<Syntax 3 ...>;END_IF;
- 範例IF bool1 THENintV1 := intV1 + 1;ELSIF bool2 THENintV2 := intV2 + 1;ELSIF bool3 THENintV3 := intV3 + 1;END_IF;
- CASE Conditional Syntax
- 格式:CASE <Integer expression> OF<Integer selection 1> : <Syntax 1 ...>;<Integer selection 2> : <Syntax 2 ...>;···<Integer selection n> : <Syntax n ...>;ELSE<Syntax n+1 ...>;END_CASE;
- 範例CASE intV1 OF1: bool1 := TRUE;2: bool2 := TRUE;ELSEintv1 := intv1 + 1;END_CASE;
- FOR ...DO Syntax
- 格式:FOR <Repeat variable initialization>TO <Last value>BY <Incremental expression> DO<Syntax ...>;END_FOR;
- 範例FOR intV1 := 0TO 30BY 1 DOintV3 := intV1 + 1;END_FOR;
- WHILE...DO Syntax
- 格式:WHILE <Boolean expression> DO<Syntax ...>;END_WHILE;
- 範例WHILE intV1 = 30 DOintV1 := intV1 + 1;END_WHILE;
- REPEAT...UNTIL Syntax
- 格式:REPEAT<Syntax ...>;UNTIL <Boolean expression>END_REPEAT;
- 範例REPEATintV1 := intV1 + 1;UNTIL intV1 = 30END_REPEAT;
- RETURN Syntax
- 格式:RETRUN;
- 範例IF bool1 THENRETURN;END_IF;
- EXIT Syntax
- 格式:EXIT;
- 範例FOR intV1 := 0TO 10BY 1 DOIF intV1 > 10 THENEXIT;END_IF;END_FOR;
Calling Functions
- 格式function_name(Var1, Var2, ...);
- 範例Output1 := ABS(Input1);Output1 := MAX(Input1, Input2, Input3);boolENO := MOV(boolEN, Input1, Output1);
Calling Function Blocks
- 格式instance_name(Input var1 := Var1, ... Output var1 := Var2, ...);
- 範例FBADD1(IN1 := Input1);Output1 := FBADD1.OUT1;FBADD2(IN1 := Input1, IN2 := Input2, IN3 := Input3);Output1 := FBADD2.OUT1;Output2 := FBADD2.OUT2;