当前位置:
文档之家› 老外写的ST语言教程-很详细
老外写的ST语言教程-很详细
ST statements block with input variables, local variables, and output variables. This can be called at different points of the program. Recursion is not allowed.
The variable names are not case-sensitive ‘Valve’, ‘VaLVe’ e ‘VALVE’ are the same variable.
10
The qualifier CONSTANT
Textual declaration of Constants
• The keyword CONSTANT can declare a constant. • The constants do not occupy space in memory as the variables • During compilation instead of the constant is replaced a numeric value.
• PROGRAM • FUNCTION • FUNCTION BLOCK
POU type
Program
Keyword
PROGRAM main
Function
END_PROGRAM FUNCTION
Function block
END_FUNCTION FUNCTION_BLOCK
END_FUNCTION_BLOCK
In assignment operations with BOOL values, 1 or TRUE, or 0 or FALSE can be used indifferently.
8
Textual declaration
To declare variables in ST you have to use the following ‘declaration block’:
Note: 1. there is no ; in the end of END_VAR; 2. we can give the default value in the declaration.
Global variables declared in text mode will not be visible in the Variable List.
9
Rules of the identifiers (variables name)
The name of an identifier (variable or constant) can be any combination (see Example) of the characters listed below:
Assignment operator :=
Assign to a variable:
• a constant value • the value of another variable • the result of an expression.
Syntax
Assignment operator
Valve, VALVE
Note
The 1st character must not be numeric. “.” is not included in the set of characters. Spaces are not allowed.
Only single underscores “_” are allowed. Not case-sensitive.
Bitstring Integers
Keyword
Data type
Lower limit
BOOL BYTE WORD DWORD
Boolean Bit string Bit string Bit string
FALSE (0) 0 0 0
SINT USINT INT UINT DINT UDINT
Global variables declaration
Variable List
Button ‘User’
‘CarelType’ • Boolean • Integer/Analog
Usable in any
7
environment
Button ‘Extend’
‘IECType’ • BOOL • INT •… • REAL
4
Basic concepts
POU
When programming in ST, the application can be organised using three fundamental programming elements generically called ‘Program Organization Units’ (POU):
3
Creation of a solution ST Language
Choosing : - FBD, the application will be 'mixed’, it will consist of a main with Atoms, Macroblocks ... but you can use routines (functions and function blocks) written in the ST - ST, the application will be developed entirely using ‘ST language’
Note: we can define more functions and function blocks, but only one program main
5
The basic types
The following table lists all the properties of basic types (IECType):
Type
Costanti Locali
Costanti Globali
Syntax
VAR CONSTANT END_VAR VAR_GLOBAL CONSTANT END_VAR
Description
Declares a group of local constants to a program, function or function block.
Declares a group of global constants, shared by program, functions or function blocks.
11Biblioteka CommentsThe code comments
• You can use two ways to make a comment - To comment a single code line use “\\” - To comment more code lines use “(*” and “*)”
• ‘a’..‘z’, ‘A’..‘Z’ • ‘0’..‘9’ • ‘_’
Example
Rules to create identifiers.
Valid identifiers
Mn2
Invalid identifiers
2Mn
_3exit
_3exit.1
Enrg_off _Drill
Enrg off __Drill
6
Declaration of Global variables
There are two ways to declare Global variables:
• ‘Variable List’ • ‘Textual mode’ of ST language
Note: if you want to see the variable in the pGD, please declare the variable in the Variable List
Type
Syntax
Descrition
Gloabal
VAR_GLOBAL END_VAR
Declares a group of global variables, shared by program, functions or function blocks.
Local
VAR END_VAR
Declares a group of local variables to a program, function or function block.
Varaible_name := expression ;
Statement terminator
Note: there is a ; in the end of statement
In assignment operations “:=” the variables involved must all be the same type, each statement must use “;” as the statement terminator.
REAL
Short Integer
Unsigned Short Integer
Integer
Unsigned Integer
Double Integer
Unsigned Double Integer
Real Number
-128 0 -32768 0 -2^31 0
-10^38
Upper limit
Textual mode
‘IECType’ • BOOL • INT •… • REAL
Usable only in the Strategy Editor ST (no: MASK, FBD Strategy Editor)