Sie sind auf Seite 1von 10

How do you create and parameterize variables and the IN, OUT and IN_OUT parameters of the

UDT data type?


Entry ID:11302987 Date:2007-02-08
STEP 7 -- Creating S7 programs -- Addressing variables and data structures
How do you create and parameterize variables and the IN, OUT and IN_OUT parameters of the UDT
data type?

Instructions:
The UDT is not a data type in the sense of a data type that the CPU recognizes, but it is a user-
defined (composed) data type in the offline project. User-defined data types of the S7 program are not
loaded into the S7 CPU. They are either created by an incremental editor and edited or they originate
from the compilation of sources. It is not possible to transfer UDTs for use as memory area when
transferring variables on block calls. For this it is recommended to specify the BYTE data type with the
relevant data length as an absolute value, or to parameterize the IN, OUT and IN_OUT declaration
symbolically, because then the system creates the address accordingly.
The table below describes how to proceed to create create and parameterize variables of the UDT
type. We will take the example of identical motors ten of which each stand in two different halls. The
UDT! maps all the inputs of these motors.

No. Procedure
1 Insert a user-defined data type in your STEP 7 project. For this you mark the block folder and
right-click. Then select "Insert New Object > Data Type" in the pop-up menu that opens.

Fig. 01
2 In the "Properties - Data Type" dialog that opens you enter a symbolic name for the UDT1 (in
this example "Motor") and acknowledge with OK.
http://support.automation.siemens.com/WW/view/en/11302987
Page 1 of 10 9/5/2014 9:56:11 PM

Fig. 02
3 Open the UDT1 and enter your variables with the relevant data types and initial values. Fig. 03
here shows a sample variable declaration in the UDT1.

Fig. 03
4 Then add a data block DB1 to your STEP 7 project via "Insert > S7 Block > Data Block" and in
the "Properties - Data Block" dialog assign a symbolic name (like here in this example
"Halle_Motoren" (Hall - Motors). Then acknowledge with "OK".

Fig. 04
5 Open the DB1 and now enter the variables in the data block with the data type UDT1 (symbolic
name "Motor"). The example as shown in Fig. 05 has two ARRAY variables each with 10
components (Index 1 to 10) of the data type UDT1.

Fig. 05
Since for this example the two halls are to be separate, create a data structure for each hall in
DB1. The structure for Hall 1 would then be "Hall_1_Motor" with an Array[1..10] of the type
"Motor".
6 Select the menu command "View > Data View" to view the data.
http://support.automation.siemens.com/WW/view/en/11302987
Page 2 of 10 9/5/2014 9:56:11 PM

Fig. 06
Note:
In the case of data blocks assigned to a UDT you can only edit the actual values for the
variables. You input current values for the variables in the Data View of data blocks. The "Initial
Value" column shows the preset values that you defined for the variables in the UDT. The
initial value is taken as the current value for the variable when the data block is stored for the
first time.
7 Input of the IN parameter of a function or function block of the type UDT
When you create a function or function block you can create an input of the type UDT1 (Motor)
as shown in Fig. 07.
Example of an AND operation: "U #Eingabe.Einschalten" (#Input.Switch On)
Input: Input parameter of function FC1
Switch On: Name of one of the variables from UDT1

Fig. 07
These inputs are also valid for other variables of the data type UDT for the OUT and IN_OUT
parameters.
8 Addressing and programming via the data block DB1
Fig. 08 shows a sample program with the structure of the data block DB1 and the assigned
UDT1.
http://support.automation.siemens.com/WW/view/en/11302987
Page 3 of 10 9/5/2014 9:56:11 PM
Notes on data blocks with the property "unlinked".
If you use UDTs in your data blocks and you configure your DBs with the property "unlinked", then in
STEP 7 V5.2 / V5.3, if you change the UDTs and then automatically adapt your data blocks using the
"Check block consistency" function, the "unlinked" property might be lost. After the block consistency
check, make sure that the DBs configured with the "unlinked" property still have that property and
make the appropriate changes to the property as necessary.
More information is also available in the STEP 7 Online Help under
User-Defined Data Types (UDT)
Entering and Displaying the Structure of Data Blocks Referencing a UDT
Entering the Data Structure of Shared Data Blocks
Example of an AND operation: "U Halle_Motoren".Halle_1_Motor[2].Einschalten ("U
Hall_Motors.Hall_1_Motor[2].Switch On)
Halle_Motoren: Symbolic name of DB1
Halle_1_Motor[2]: DB variable of data type "ARRAY" and Index 2
Switch On: Name of one of the variables from UDT1

Fig. 08
9 Parameterizing the IN parameters of a function or a function block
When you call function FC1, the input of the UDT type must be supplied. In order to supply the
first motor in Hall 1, for example, you write the following to the input:
"Halle_Motoren".Halle_1_Motor[1] ("Hall_Motors".Hall_1_Motor[1]).

Fig. 09
This parameterization is of course also valid for other variables of the data type UDT for the
OUT and IN_OUT parameters.
10 When the cross-reference list is displayed you get a list of the operands of the memory area
(e.g. DB1) used in the S7 user program, its addresses and their application.

Fig. 10
http://support.automation.siemens.com/WW/view/en/11302987
Page 4 of 10 9/5/2014 9:56:11 PM
Keywords:
Template, Sample block, User-Defined Data Type
Fig. 01

Fig. 02
http://support.automation.siemens.com/WW/view/en/11302987
Page 5 of 10 9/5/2014 9:56:11 PM

Fig. 03

Fig. 04
http://support.automation.siemens.com/WW/view/en/11302987
Page 6 of 10 9/5/2014 9:56:11 PM

Fig. 05

Fig. 06
http://support.automation.siemens.com/WW/view/en/11302987
Page 7 of 10 9/5/2014 9:56:11 PM

Fig. 07
http://support.automation.siemens.com/WW/view/en/11302987
Page 8 of 10 9/5/2014 9:56:11 PM

Fig. 08

Fig. 09
http://support.automation.siemens.com/WW/view/en/11302987
Page 9 of 10 9/5/2014 9:56:11 PM

Fig. 10

Entry ID:11302987 Date:2007-02-08
Siemens AG 2014 - Corporate Information - Privacy Policy - Terms of Use
http://support.automation.siemens.com/WW/view/en/11302987
Page 10 of 10 9/5/2014 9:56:11 PM

Das könnte Ihnen auch gefallen