Data and Parameter Types
C.1 Data Types
All the data in a user program must be identified by a data type. The following data types are available:
S Elementary data types provided by STEP 7
S Complex data types that you yourself can create by combining elementary data types
S User-defined data types
S Parameter types with which you define parameters to be transferred to FBs or FCs
Each elementary data type has a defined length. The data type BOOL has, for example, only one bit, a byte (BYTE) consists of 8 bits, a word (WORD) consists of 2 bytes (16 bits), a double word (DWORD) has 4 bytes (32 bits).
Table C-1 lists the elementary data types.
Table C-1 Description of the Elementary Data Types Type and
Description
Size in Bits
Format Options Range and Numeric Representation (lowest to highest value)
Example
BOOL (Bit)
1 Boolean text TRUE/FALSE TRUE
BYTE (Byte)
8 Hexadecimal number
B16#0 to B16#FF L B#16#10
L byte#16#10
WORD 16 Binary number
Hexadecimal
Table C-1 Description of the Elementary Data Types, continued Type and
Description
Example Range and Numeric
Representation (lowest to highest value)
Upper limit: ±3.402823e+38
Lower limit: ±1.175 495e-38 L 1.234567e+13
S5TIME (SIMATIC time)
16 S7 time in steps of
32 IEC time in steps of 1 ms, integer signed
16 IEC date in steps of 1 day
D#1990-1-1 to D#2168-12-31
L D#1994-3-15 L DATE#1994-3-15 TIME_OF_DAY 32 Time in steps of
1 ms
Complex data types define data groups that are larger than 32 bits or data groups consisting of other data types. STEP 7 permits the following complex data types:
Table C-2 describes the complex data types. They define structures and arrays either in the variable declaration of the logic block or in a data block.
Table C-2 Description of the Complex Data Types
Data Type Description
DATE_AND_TIME DT
Defines an area with 64 bits (8 bytes). This data type saves the following information (in binary coded decimal format): year in byte 0, month in byte 1, day in byte 2, hours in byte 3, minutes in byte 4, seconds in byte 5, milliseconds in byte 6 and half of byte 7, weekday in the other half of byte 7.
STRING Defines a group with a maximum of 254 characters (data type CHAR). The standard area reserved for a character string is 256 bytes long. This is the space required to save 254 characters and a header of 2 bytes. You can reduce the memory required for a string by defining the number of characters that will be stored in the character string (for example: string[9] ‘Siemens’).
ARRAY Defines a multi-dimensional grouping of one data type (either elementary or complex). For example: “ARRAY [1..2,1..3] OF INT” defines and array in the format 2 x 3 consisting of integers. You access the data stored in an array using the Index (“[2,2]”). You can define up to a maximum of 6 dimensions in one array. The index can be any integer (-32768 to 32767).
STRUCT Defines a grouping of any combination of data types. You can, for example, define an array of structures or a structure of structures and arrays.
FB, SFB You determine the structure of the assigned instance data block and allow the transfer of instance data for several FB calls in one instance DB (multiple instances, see Section 2.10).
In STEP 7, you can combine complex and elementary data types to create your own “user-defined” data type (UDT). UDTs have their own name and can therefore be used more than once. In a UDT, you can structure large amounts of data and simplify the input of data types when you want to create data blocks or declare variables in the variable declaration.
Complex Data Types
User-Defined Data Types
长沙工控帮教育科技有限公司整理
In addition to elementary, complex, and user-defined data types, you can also define parameter types for formal parameters that are transferred between blocks (see Table C-3). STEP 7 recognizes the following parameter types:
S TIMER or COUNTER: this specifies a particular timer or particular counter that will be used when the block is executed. If you supply a value to a formal parameter of the TIMER or COUNTER parameter type, the
corresponding actual parameter must be a timer or a counter, in other words, you enter “T” or “C” followed by a positive integer.
S BLOCK: specifies a particular block to be used as an input or output. The declaration of the parameter determines the block type to be used (FB, FC, DB etc.). If you supply values to a formal parameter of the BLOCK parameter type, specify a block address as the actual parameter. Example:
“FC101” (when using absolute addressing) or “Valve” (with symbolic addressing).
S POINTER: references the address of a variable. A pointer contains an address instead of a value. When you supply a value to a formal
parameter of the parameter type POINTER, you specify an address as the actual parameter. In STEP 7, you can specify a pointer in the pointer format or simply as an address (for example M 50.0). Example of a pointer format for addressing the data beginning at M 50.0: P#M50.0 S ANY: this is used when the data type of the actual parameter is unknown
or when any data type can be used. For more information about the ANY parameter type refer to Section C.6.
A parameter type can also be used in a user-defined data type (UDT). For more information about UDTs, refer to Section C.5.
Table C-3 Parameter Types
Parameter Size Description
TIMER 2 Bytes Indicates a timer to be used by the program in the called logic block.
Format: T1
COUNTER 2 Bytes Indicates a particular counter to be used by the program in the called logic block.
Format: C10 BLOCK_FB
BLOCK_FC BLOCK_DB BLOCK_SDB
2 Bytes Indicates a particular block to be used by the program in the called logic block.
Format: FC101 DB42
POINTER 6 Bytes Identifies the address.
Format: P#M50.0
ANY 10 Bytes Is used when the data type of the current parameter is unknown (see Section C.6).
Format: P#M50.0 BYTE 10 P#M100.0 WORD 5 Parameter Types
长沙工控帮教育科技有限公司整理