Siemens S7-1200/1500 PLC Data Types

1

Concept

Data types are used to specify the size and format of data elements, as well as how to interpret the data, describing the length of the data (i.e., the number of binary bits) and its attributes.

All data in user programs must be identified by data types, and only variables of the same data type can be used in calculations. When defining a variable, its data type must be set, and when using instructions, functions, or function blocks, appropriate variables must be used according to the required data type of the operands.

2

Common Data Types

1

Basic Data Types (Binary, Integer, Floating Point, Timer, DATE, TOD, LTOD, CHAR, WCHAR)

Siemens S7-1200/1500 PLC Data Types

Numeric Types

(1) Bit Data: bit, Byte, word, Dword

(2) Integers: signed and unsigned short, integer, double integer

(3) Floating Point: Real, LReal

Character Types

(1) Single Character: Char, WChar (Wide Character)[^2]

(2) String: String, WSTRING (Wide String)[^1]

2

Complex Data Types (DT, LDT, DTL, ARRAY, STRUCT)

Siemens S7-1200/1500 PLC Data Types

(1) Complex data types are combinations of basic data types, such as: STRUCT, a structure data type, similar to a composite that can contain any basic data types. This function is similar to user-defined data types.

(2) ARRAY data type: allows for the bulk creation of similar data types.

3

User-Defined Data Types (PLC Data Types (UDT))

Siemens S7-1200/1500 PLC Data Types

For complex data structures that are reused in projects (such as motor parameters, valve objects, recipe data, etc.), it is strongly recommended to create UDTs. This can greatly improve programming efficiency, consistency, and maintainability. Once a UDT definition is modified, all variables using that UDT will be automatically updated.

4

Pointers

Siemens S7-1200/1500 PLC Data Types

(1) POINTER type pointer

Prefixed with “P#”, a pointer that can point to a specific variable.

(2) Variant Data Type

The Variant data type does not directly occupy storage space but acts as a “pointer” or “reference” that can point to almost any type of data (basic types, arrays, structures, UDTs, etc.), and can carry type information of the data it points to at runtime. It is commonly used for:

Writing more generic, reusable functions (FC) or function blocks (FB) that can handle data of various types.

Working with instructions like `VariantGet`, `VariantPut`, etc., to dynamically read and write the data it points to.

5

REF, ANY Pointers

Siemens S7-1200/1500 PLC Data Types

In high-level module programming, REF and ANY pointers are used. Among them, REF pointers are only used for Siemens 1500 PLC.

Siemens S7-1200/1500 PLC Data Types

Footnotes:

[^1]: The data type for WSTRING (wide string) operands is used to store multiple data types of WCHAR Unicode characters in a single string. If no length is specified, the string length is preset to 254 characters. All characters supported by the operating system can be used in a string. This means that Chinese characters can also be used in the string. Windows only supports a portion (most) of the characters defined by Unicode.

[^2]: The variable length of the WCHAR (wide character) data type is 16 bits, occupying two BYTEs of memory. The WCHAR data type saves a single character from the extended character set in UTF-16 encoding. However, it only involves a portion of the entire Unicode range. Characters that cannot be displayed will be shown using an escape character.

Leave a Comment