老外写的ST语言教程-很详细

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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.
• ‘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
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.
ST Language
Basic Course
1
ST Language
Basic Course
Key word
If there is any unclear or uncorrected, please feel free to speak out
2
Requirements
Hardware
The programming language ST is only available for following programmable controllers:
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
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):
Comment using keyword {REGION… ENDREGION}
• You can hide several lines of code using the keyword {REGION … ENDREGION}.
• So increase the readability of the code on the screen. • The code is replaced with a comment. • Clicking on comment it will appear again the code.
TRUE (1) 255 65535 4.294.967.2 95 127 255
Memory Space
8 Bit 8 Bit 16 Bit 32 Bit
8 Bit 8 Bit
32767 65535
16 Bit 16 Bit
(2^31)-1
32 Bit
2^32 -1
32 Bit
10^38
32 Bit
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’
Global variables declaration
Variable List
ButtoBiblioteka Baidu ‘User’
‘CarelType’ • Boolean • Integer/Analog
Usable in any
7
environment
Button ‘Extend’
‘IECType’ • BOOL • INT •… • REAL
Assignment operator :=
Assign to a variable:
• a constant value • the value of another variable • the result of an expression.
Syntax
Assignment operator
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:
4
Basic concepts
POU
When programming in ST, the application can be organised using three fundamental programming elements generically called ‘Program Organization Units’ (POU):
Description
Main program that includes: • read/write I/O • definition of local variables • calls to Functions or Function Blocks
ST statements block with input variables, local variables, and if specified a return value. This can be called at different points of the program. Recursion is not allowed.
Textual mode
‘IECType’ • BOOL • INT •… • REAL
Usable only in the Strategy Editor ST (no: MASK, FBD Strategy Editor)
You don’t see these variables in Variable List
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
• PROGRAM • FUNCTION • FUNCTION BLOCK
POU type
Program
Keyword
PROGRAM main
Function
END_PROGRAM FUNCTION
Function block
END_FUNCTION FUNCTION_BLOCK
END_FUNCTION_BLOCK
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
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.
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.
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.
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’:
Declares a group of global constants, shared by program, functions or function blocks.
11
Comments
The 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 “*)”
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.
• pCO3 • Supernode • pCO5 • pCO compact
pCO3 Supernode
pCO5
BIOS
To support ST language, bios version must greater than 5.0
Software
Use a version of 1tool > = 2.1.x
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.
相关文档
最新文档