Professional Documents
Culture Documents
TABLE OF CONTENTS
Chapter 6 Variables and Data Types ............................................................................................................................................. 6-1
6.1 General Information ............................................................................................................................................................. 6-3
6.1.1 Description .................................................................................................................................................................... 6-3
6.1.2 Objectives...................................................................................................................................................................... 6-3
6.1.3 Reference Documentation............................................................................................................................................. 6-3
6.2 Kind of Variables ................................................................................................................................................................. 6-4
6.2.1 Application Variables ................................................................................................................................................... 6-4
6.2.2 Program Variables......................................................................................................................................................... 6-7
6.2.3 Control Module Variables ............................................................................................................................................ 6-8
6.2.4 External Variables......................................................................................................................................................... 6-9
6.2.5 Access Variables ......................................................................................................................................................... 6-10
6.3 Declaration of Variables .................................................................................................................................................... 6-10
6.3.1 General ........................................................................................................................................................................ 6-10
6.3.2 Declaring Variables in POU ....................................................................................................................................... 6-11
6.4 Structured Data Types........................................................................................................................................................ 6-13
6.4.1 Components................................................................................................................................................................. 6-14
6.4.2 Dot Notation................................................................................................................................................................ 6-15
6.5 Project Constants................................................................................................................................................................ 6-16
6-1
6-2
6.1.2 Objectives
On completion of this chapter you will be able to:
Describe the scope of local variables, global variables and access variables.
6-3
6.2.1.1.1 Scope
6-4
6-5
6.2.1.2.1 Scope
6-6
6.2.2.1 Scope
6-7
6.2.3.1 Scope
6-8
6-9
6-10
Description
Bits
Initial value
bool
Boolean
False, 0
Dint
double integer
32
Int
Integer
16
Uint
Unsigned integer
16
String
Character string *
Word
Bit string
16
DWord
Bit string
32
Time
Duration
Date_And_Time
Real
Real number
T#0s
1979-12-31-00:00:00
32
0.0
6-11
6.3.2.1 Name
It is best to give the variables simple and explanatory names. It is advisable to begin a
variable name with a capital letter, and names consisting of more than one word
should have capital letters at the beginning of each new word. Examples of
recommended variable names are DoorsOpen or PhotoCell. Certain identifiers
(names) are reserved by the system and cannot be used for other purposes. If a
reserved word is used an error message is given in the message pane: Invalid
variable identifier, Reserved word or Name xxx not valid.
6.3.2.3 Attributes
The following attribute can be given to a variable:
Name
Description
No attribute
The value of the variable is not maintained after a restart. Instead it is set
to the initial value of the variable. If the variable has no initial value
assigned to it, it will get the default value of the data type (see table in
page 6.3)
retain
The value of the variable is maintained after a warm restart. The system
sets retain on all variables by default. To override this the attribute must be
left empty.
coldretain
constant
hidden
Note! Variables declared in a Contol Module can also have the attributes State or
Nosort. These are described in detail in chapter 10.
6-12
value is given. Otherwise the value of the variable is set to the default value of the data
type.
6.3.2.5 I/O-address
It is suitable to make the I/O connection from the I/O module editor. This is described
in chapter 15 Basic Hardware Configuration.
6.3.2.6 Description
Description describes and/or provides information about the variable. A short
descriptive text, for example, would include an explanation of the cause of a condition
or a simple event; 'Pump 1 is running'.
Start -
Stop-
Right spin -
Left spin -
Speed -
Feedback -
You can collect all these characteristics into one signal using a structured data type.
Given the specifications above you create a structured data type called Motor_Type,
with subordinate identifiers Start (Boolean), Stop (Boolean), RightSpin (Boolean),
LeftSpin (Boolean), Speed (real) and Feedback (Boolean).
6-13
6.4.1 Components
The variables in the structured Data Type are called Components.
6.4.1.1 Name
It is best to give the components simple and explanatory names.
6.4.1.3 Attributes
Press < Ctrl+J > in the Attribute column, to find a suitable attribute to be assigned.
6-14
6.4.1.5 Description
In the description fields a short description can be written at declaration of the Data
Type component.
If you want to set the Full component of the Tank variable to 1 (i.e. "True"), write:
tank.full := true ;
The rest of the subordinate variables are accessed in a similar way. A structured data
type is a data type that contains several components and can thus have several values,
one for each component.
6-15
6-16