登录
首页 PLC论坛 西门子SIEMENS
回帖 发帖
正文

主题:61131-3现在在中国流行吗?

点击:6841 回复:31

POUs in IEC 1131-3
Program organization units or POUs are the language elements of a PLC program. They are small, independent software units containing the program code. The name of a POU should be unique within the project.
In IEC 1131-3 three types of POUs are distinguished referring to their different use:
programs
function blocks
functions
Each POU consists of two different parts: The declaration part and the code body part.
In the declaration part all necessary variables are declared.
The instruction or code body part of a POU is the part in which the instructions are programmed in the desired programming language.
04-11-03 19:56
Functions in IEC 1131-3
Functions are POUs with multiple input parameters and exactly one output parameter. Calling a function with the same values returns always the same result. Return values can be single data types. Within a function it is possible to call another function but not a function block or a program. Recursive calls are not allowed. The abbreviation for functions is FU.
IEC 1131-3 describes standard functions which can be used while editing your PLC program. According to your hardware and PLC type it is possible that not all standard functions are available or that firmware functions have been added.
For detailed information about the IEC 1131-3 standard functions please refer to the Function/Function block Online Help. For that purpose you can either select the corresponding menu item in the submenu 'Help' or call the context sensitive help topic out of the Edit Wizard. Additional information can be taken from the hardware documentation.
04-11-03 19:56
Programs in IEC 1131-3
Programs are POUs which contain a logical combination of functions and function blocks according to the needs of the controller process. The behavior and the use of programs are similar to function blocks. Programs have input and output parameters and they can have internal memory. Programs must be associated to tasks.
Within a program it is possible to call functions and function blocks. Recursive calls are not allowed
04-11-03 19:57
Instantiation
For reusing function block definitions IEC 1131-3 provides the possibility of instantiation. This means that a function block or a program is defined once and that its internal memory is allocated to different instances, different memory regions. Each instance has an associated identifier and contains the input and output parameter and the internal memory of the function block or program. A function block can be instantiated in another function block or in a program. The instance name of a function block has to be used as in the VAR declaration of the program or the function block. Programs can be instantiated within resources.
04-11-03 19:57
Data types in IEC 1131-3
Data types determine what kind of value the variable can have. Data types define the initial value, range of possible values and the number of bits.
IEC 1131-3 distinguishes three kinds of data types:
Elementary data types
Generic data types
User defined data types
04-11-03 19:57
Elementary data types
The value ranges and the bitsize of elementary data types are described in IEC 1131-3.
Elementary data types are shown in the following table:
Data type Description Size Range Default initial value
BOOL Boolean 1 0...1 0
SINT Short integer 8 -128...127 0
INT Integer 16 -32768...32767 0
DINT Double integer 32 -2.147.483.648 up to 2.147.483.647 0
USINT Unsigned short integer 8 0 up to 255 0
UINT Unsigned integer 16 0 up to 65535 0
UDINT Unsigned double integer 32 0 up to 4.294.967.295 0
REAL Real numbers 32 -3.402823466E+38...
-1.175494351E-38
0.0
+1.175494351E-38...
+3.402823466 E+38 0.0
TIME Duration 32   t#0s
BYTE Bit string of length 8 8   0
WORD Bit string of length 16 16   0
DWORD Bit string of length 32 32   0
The usage of elementary data types depends on your hardware. Please refer to your hardware documentation for the supported data types.
The data type STRING is also an elementary data type but does not belong to the above mentioned group. Its format in the memory depends on your PLC type.
The data type STRING has the following structure:
Byte 0-1 offset to maximum length (0 corresponds to 80)
Byte 2-3 current length
Byte 4-83 characters
Byte 84 zero terminator
The range given for the data type REAL is the normal range. It is precise up to 6-9 places.
04-11-03 19:58
Generic data types
Generic data types are data types which include hierarchical groups of elementary data types. ANY_INT includes the elementary data types DINT, INT, SINT, UDINT, UINT and USINT. If a function can be connected with ANY_INT it means that variables of the data types DINT, INT, SINT, UDINT, UINT and USINT can be handled.
Generic data types are shown in the following table:
ANY
   ANY_NUM
       ANY_REAL
           REAL
       ANY_INT
           DINT, INT, SINT
           UDINT, UINT, USINT
   ANY_BIT
       DWORD, WORD, BYTE, BOOL
   STRING
   TIME
 
The usage of data types also depends on your hardware. Please refer to your hardware documentation for restrictions concerning generic data types.
04-11-03 19:58
User defined data types
User defined data types are edited by the application programmer with a TYPE ... END_TYPE declaration using the text editor in a data type worksheet. Derived data types can be enumerated data types, structures or arrays.
Array data types include several elements of one data type. An array can be used to declare several elements of the same type with only one line in the type declaration. Click here to see an example.
Structured data types include several elements of different data types. Click here to see an example.
User defined strings are STRING data types with a variable number of characters. Declaring a user defined string the length is set in brackets behind the data type as it is shown in the example.
Enumerated data types limit the possible values to the enumerated ones. The variable in which the data type is used can have only the enumerated values. Click here to see an example.
The usage and (memory) format of structured data types, user defined strings, enumerated data types depends on your PLC type. Please refer to your hardware documentation concerning the use of these enumerated data types.
04-11-03 19:58
Variables in IEC 1131-3
In IEC 1131-3 different types of variables are described:
Symbolic variables
Directly represented variables
Located variables
Variables have to be declared in the variable worksheet of the POU using keywords.
04-11-03 19:58
Variable declaration keywords
In variable declarations variable declaration keywords have to be used. The keywords are described in the following table:
Keyword Description
VAR for internal variables which can be used only within POU
for declaring the instances of function blocks
can be used for the declaration of directly represented, located and symbolic variables
can be used with the keyword 'RETAIN' for declaring retentive variables

VAR_INPUT for variables which are inputs to functions, function blocks and programs
to give a value to the POU coming e.g. from another POU
its value is only read within the POU
can be used only for the declaration of symbolic variables

VAR_OUTPUT for variables which are outputs to function blocks and programs
supplies an output value for e.g. other POUs
its value is written within the POU
it is also allowed to read the value
can be used with the keyword 'RETAIN' for declaring retentive variables

VAR_IN_OUT address of the variable is passed by reference
the variable can be read or written
typically used for complex data types such as strings, arrays and structures

VAR_EXTERNAL for global variables in the POU
its value is supplied by the declaration of VAR_GLOBAL
its value can be modified within the POU
can be used only for the declaration of symbolic variables

VAR_GLOBAL for global variables which can be used in all programs and function blocks of the project
can be used for the declaration of directly represented, located and symbolic variables
can be used with the keyword 'RETAIN' for declaring retentive variables

END_VAR to finish a variable declaration block

In addition to these keywords three more keywords can be used in variable declarations: RETAIN for retentive variables and the keyword AT which is needed for directly represented and located variables.
The variable declarations differ in their structure according to the different variable types. Variable declarations are done either in the variable worksheet of each POU or in the worksheet for global variables
04-11-03 19:58

上一页 下一页

工控新闻

更多新闻资讯