LamaPLC: Simatic datatypes

TIA Portal datatypes

TIA Portal datatypes List of data types used by Simatic S7. The page contains the more modern TIA variable types as well as the earlier S7-classic types.

There are four data types in: Boolean, Text, Numeric, and Date/Time. Each data type defines the format of information that can be entered into a data field and stored in your database.

DatatypWidth (bits)Range of valuesExamplesS7-300/400S7-1200S7-1500
Binaries
BOOL (x) 1
(S7-1500 optimized
1 Byte)
FALSE or TRUE
BOOL#0 or BOOL#1
BOOL#FALSE oder BOOL#TRUE
TRUE
BOOL#1
BOOL#TRUE
XXX
BYTE (b)8B#16#00 .. B#16#FF
-128 .. +127 or 0 .. +255
2#0 .. 2#11111111
15,
BYTE#15,
B#15
XXX
WORD (w)16W#16#0000 .. W#16#FFFF
-32768 .. 65535
B#(0, 0) .. B#(255, 255)
55555,
WORD#55555,
W#555555
XXX
DWORD (dw)32DW#16#0000 0000 .. DW#16#FFFF FFFFDW#16#DEAD BEEF
B#(111, 222, 255, 200)
XXX
LWORD (lw)64LW#16#0000 0000 0000 0000 ..
LW#16#FFFF FFFF FFFF FFFF
-9223372036854775808 ..
18446744073709551615
LW#16#DEAD BEEF DEAD BEEF
B#(111, 222, 255, 200, 111, 222, 255, 200)
--X
DatatypWidth (bits)Range of valuesExamplesS7-300/400S7-1200S7-1500
Integers
SINT (si)8-128 .. 127
(hex nur poz.) 16#0 .. 16#7F
+42, SINT#+42
16#1A, SINT#16#2A
-XX
INT (i)16-32768 .. 32767
(hex nur poz.) 16#0 .. 16#7FFF
+1234, INT#+3221
16#1ABC
XXX
DINT (di)32-2147483648 .. +2147483647
(hex nur poz.)
16#00000000 .. 16#7FFFFFFF
123456, DINT#123456,
16#1ABC BEEF
XXX
USINT (usi)80 .. 25542, USINT#42
16#FF
-XX
UINT (ui)160 .. 6553512345, UINT#12345
16#BEEF
-XX
UDINT (udi)320 .. 42949672951234567890, UDINT#1234567890 -XX
LINT (li)64-9223372036854775808 .. +9223372036854775807+1234567890123456789, LINT#+1234567890123456789--X
ULINT (uli)640 .. 18446744073709551615123456789012345, ULINT#123456789012345--X
DatatypWidth (bits)Range of valuesExamplesS7-300/400S7-1200S7-1500
floating point numbers
REAL ( r)32-3.402823e+38 .. -1.175 495e-38
..
+1.175 495e-38 .. +3.402823e+38
0.0, REAL#0.0
1.0e-13, REAL#1.0e-13
XXX
LREAL (lr)64-1.7976931348623158e+308 .. -2.2250738585072014e-308
..
+2.2250738585072014e-308 .. +1.7976931348623158e+308
0.0, LREAL#0.0-XX
DatatypWidth (bits)Range of valuesExamplesS7-300/400S7-1200S7-1500
Times
S5TIME (s5t)
→details
16S5T#0H_0M_0S_0MS .. S5T#2H_46M_30S_0MSS5T#10s, S5TIME#10sX-X
TIME (t)32T#-24d20h31m23s648ms .. T#+24d20h31m23s647msT#13d14h15m16s630ms, TIME#1d2h3m4s5msXXX
LTIME (lt)64LT#-106751d23h47m16s854ms775us808ns .. LT#+106751d23h47m16s854ms775us807nsLT#1000d10h15m24s130ms152us15ns, LTIME#200d2h2m1s8ms652us315ns--X
Timer operations: IEC timers, TON (Generate on-delay), TOF (Generate off-delay), TP (Generate pulse), TONR (Time accumulator)
DatatypWidth (bits)Range of valuesExamplesS7-300/400S7-1200S7-1500
Counters
CHAR8ASCII character set'A', CHAR#'A'XXX
WCHAR (wc)16Unicode character setWCHAR#'A'-XX
STRING (s)
→details
n+2 (Byte)0 .. 254 characters (n)'Name', STRING#'OB121'XXX
WSTRING (ws)n+2 (Word)0 .. 16382 characters (n)WSTRING#'OB121'-XX
Counter operations: CTU (count up), CTD (count down), CTUD (count up and down)
DatatypWidth (bits)Range of valuesExamplesS7-300/400S7-1200S7-1500
Date & time
DATE (d)16D#1990-01-01 .. D#2168-12-31D#2020-08-14, DATE#2020-08-14XXX
TOD (tod)
(TIME_OF_DAY)
32TOD#00:00:00.000 .. TOD#23:59:59.999TOD#11:22:33.444,
TIME_OF_DAY#11:22:33.444
XXX
LTOD (ltod)
(LTIME_OF_DAY)
64LTOD#00:00:00.000000000 ..
LTOD#23:59:59.999999999
LTOD#11:22:33.444_555_111,
LTIME_OF_DAY#11:22:33.444_555_111
--X
DT (dt)
(DATE_AND_TIME)
64Min.: DT#1990-01-01-0:0:0
Max.: DT#2089-12-31-23:59:59.999
DT#2020-08-14-2:44:33.111,
DATE_AND_TIME#2020-08-14-11:22:33.444
X-X
LDT (ldt)
(L_DATE_AND_TIME)
64Min.: LDT#1970-01-01-0:0:0.000000000, 16#0
Max.: LDT#2262-04-11-23:47:16.854775807,
16#7FFF_FFFF_FFFF_FFFF
LDT#2020-08-14-1:2:3.4--X
DTL (dtl)96Min.: DTL#1970-01-01-00:00:00.0
Max.: DTL#2554-12-31-23:59:59.999999999
DTL#2020-08-14-10:12:13.23-XX
DatatypWidth (bits)Range of valuesExamplesS7-300/400S7-1200S7-1500
Pointers
POINTER (p)
→details
48Symbolic: “DB”.“Tag”
Absolute:
P#10.0
P#DB4.DBX3.2
X-X
ANY (any)80Symbolic:
“DB”.StructVariable.firstComponent
Absolut: P#DB11.DBX12.0 INT 3
P#M20.0 BYTE 10
X-X
VARIANT (var)0Symbolic:
“Data_TIA_Portal”.
StructVariable.firstComponent
Absolute: %MW10
P#DB10.DBX10.0 INT 12
-XX
BLOCK_FB0-X-X
BLOCK_FC0-X-X
BLOCK_DB0-X--
BLOCK_SDB0-X--
VOID0-XXX
PLC_DATA_TYPE0-XXX

TIA Data types codes

Hexadecimal codeData typeDescription
B#16#00NILNull pointer
B#16#01BOOLBits
B#16#02BYTEbytes, 8 bits
B#16#03CHAR8-bit characters
B#16#04WORD16-bit words
B#16#05INT16-bit integers
B#16#06DWORD32-bit words
B#16#07DINT32-bit integers
B#16#08REAL32-bit floating-point numbers
B#16#0BTIMETime duration
B#16#0CS5TIMETime duration
B#16#09DATEDate
B#16#0ATODDate and time
B#16#0EDTDate and time
B#16#13STRINGCharacter string
B#16#17BLOCK_FBFunction block
B#16#18BLOCK_FCFunction
B#16#19BLOCK_DBData block
B#16#1ABLOCK_SDBSystem data block
B#16#1CCOUNTERCounter
B#16#1DTIMERTimer

Simatic classic datatypes (S7-300 / S7-400)

Type and description size in bits format options Area and number notation
(lower .. higher value)
example in STL
BOOL (Bit) 1Boolean textTRUE/FALSETRUE
BYTE (Byte) 8Hexadecimal numberB#16#0 to B#16#FFL B#16#10
L byte#16#10
WORD (Word) 16Binary number2#0 to 2#1111_1111_1111_1111L 2#0001_0000_0000_0000
Hexadecimal numberW#16#0 to W#16#FFFFL W#16#1000
L word#16#1000
BCDC#0 to C#999L C#998
Decimal number unsignedB#(0,0) to B#(255,255)L B#(10,20)
L byte#(10,20)
DWORD (Double word) 32Binary number2#0 to 2#1111_1111_1111_1111_
1111_1111_1111_1111
L 2#1000_0001_0001_1000_
1011_1011_0111_1111
Hexadecimal numberW#16#0000_0000 to W#16#FFFF_FFFFL DW#16#00A2_1234
L dword#16#00A2_1234
Decimal number unsignedB#(0,0,0,0) to B#(255,255,255,255)L B#(1, 14, 100, 120)
L byte#(1,14,100,120)
INT (Integer) 16Decimal number signed-32768 to 32767L 101
DINT (Double integer) 32Decimal number signedL#-2147483648 to L#2147483647L L#101
REAL (Floating-point number) 32IEEE Floating-point numberUpper limit +/-3.402823e+38
Lower limit +/-1.175495e-38
L 1.234567e+13
S5TIME (SIMATIC time) 16S7 time in steps of 10ms (default)S5T#0H_0M_0S_10MS to
S5T#2H_46M_30S_0MS and
S5T#0H_0M_0S_0MS
L S5T#0H_1M_0S_0MS
L S5TIME#0H_1H_1M_0S_0MS
TIME (IEC time) 32IEC time in steps of 1 ms, integer signedT#24D_20H_31M_23S_648MS
to
T#24D_20H_31M_23S_647MS
L T#0D_1H_1M_0S_0MS
L TIME#0D_1H_1M_0S_0MS
DATE (IEC date) 16IEC date in steps of 1 dayD#1990-1-1 to
D#2168-12-31
L D#1996-3-15
L DATE#1996-3-15
TIME _OF_DAY (Time) 32Time in steps of 1 msTOD#0:0:0.0 to
TOD#23:59:59.999
L TOD#1:10:3.3
L TIME_OF_DAY#1:10:3.3
CHAR (Character) 8ASCII charactersA', 'B' etc.L 'E'

Data-types

Pointer

An example above to the pointer: P#DB100.DBX14.0 WORD 4
The following elements make up a pointer:

P#Pointer identifier
DB100Start Data block / memory area
.DB14.0Start offset within the data block
WORD 4Length of the data to be included in the pointer

You cannot use MOVE to access pointer data. This is because the Pointer is considered an “Any” data type, which MOVE does not accept. BLKMOV must be used instead, and in order to use that, Optimized Data must be turned off!

Real, LReal IEEE 754

Simatic Real, LReal IEEE 754

  • Sign (of Mantissa) : 0: positive, 1: negative
  • (Biased) exponent : The exponent field needs to represent both positive and negative exponents.
  • (Normalised) mantissa : Mantissa is part of a number in scientific notation or a floating-point number, consisting of its significant digits.

String

String types in S7 are not NULL “terminated” like C-style strings. They instead have 2 “hidden” characters that precede the string data. The first hidden character is the maximum size of the string, which is 'n' in the example above, and the second hidden character is the actual length of the string (i.e. the number of characters stored).

So the string definition MyStr: STRING[10]:=“abcdef” would contain the following ASCII codes:

10, 06, 97, 98, 99, 100, 101, 102

10: maximum (declared) length of the character string
06: the current length of the string
97, 98: “a”, “b”,..

S5TIME

  • Underscores in time and date are optional
  • It is not necessary to specify all time units (for example: T# 5h10s is valid)
  • Maximum time value = 9,990 seconds or 2H_46M_30S

S5TIME Struktur

"S5TIME" Format

Time baseBinary Code
10 ms00
100 ms01
1 s10
10 s11

Indirect addressing in Simatic Classic

Indirect addressingExample
Indirect addressing of a DBData type “BLOCK_DB”
Indirect addressing of DB tags#block.%DBW3

WORD_TO_BLOCK_DB(#myWord).%DBW3

#block.DW(IDX := #myInt)

WORD_TO_BLOCK_DB(#myWord).DW(IDX:=#myInt)

%DB1.DW(IDX :=#myInt)
Indirect addressing of I/OQB(IDX :=#myInt):P
Indirect addressing of PLC tagsIX(IDX :=#myInt1,Bit:=#myInt2)

QB(IDX :=#myInt)

MW(IDX :=#myInt)

Indirect addressing in TIA Portal

In many cases, indirect addressing may be necessary in PLC technology. Its typical application is the preparation of signals for communication and SCADA, as well as the transformation of communication and SCADA signals and the “unpacking” of bits.

For example

  • In the case of SCADA transmission, it is easier to use a WORD and transfer 16 bits in it
  • Modbus communication is based on WORD registers. These are easy to handle with indirect addressing
  • Many measuring units use two of the Modbus WORD registers (DWORD) to transfer one REAL. Structurally, DWORD and REAL are not the same, but the signals can be easily read with indirect addressing

TIA Portal slice access

  • from Bit to: BYTE, WORD, DWORD
  • from Byte to: WORD, DWORD
  • from Word to: DWORD

bit := byte.%X1;    // bit 1 from byte
bit := word.%X4;    // bit 4 from word
bit := dword.%X11;  // bit 11 from dword 
 
byte := word.%B1;   // 2.byte from word
byte := dword.%B2;  // 3. byte from dword
 
word := dword.%W0;  // 1. word from dword
The following example is a SPLIT function that splits a WORD Input variable into bits:
// FC Input : inWord (Word)
// FC output: 16 variable bit0..bit15 (Bool)
// splitting
#bit0 := #inWord.%X0;
#bit1 := #inWord.%X1;
#bit2 := #inWord.%X2;
#bit3 := #inWord.%X3;
#bit4 := #inWord.%X4;
#bit5 := #inWord.%X5;
#bit6 := #inWord.%X6;
#bit7 := #inWord.%X7;
#bit8 := #inWord.%X8;
#bit9 := #inWord.%X9;
#bitA := #inWord.%X10;
#bitB := #inWord.%X11;
#bitC := #inWord.%X12;
#bitD := #inWord.%X13;
#bitE := #inWord.%X14;
#bitF := #inWord.%X15;
And this is a JOIN function that assembles a WORD from 16 bits:
// FC Input: 16 variable bit00..bit15 (Bool)
// FC Output : OUT (Word)
// JOIN
// Assemble bits to a word
#OUT.%X0 := #bit00;
#OUT.%X1 := #bit01;
#OUT.%X2 := #bit02;
#OUT.%X3 := #bit03;
#OUT.%X4 := #bit04;
#OUT.%X5 := #bit05;
#OUT.%X6 := #bit06;
#OUT.%X7 := #bit07;
#OUT.%X8 := #bit08;
#OUT.%X9 := #bit09;
#OUT.%X10 := #bit10;
#OUT.%X11 := #bit11;
#OUT.%X12 := #bit12;
#OUT.%X13 := #bit13;
#OUT.%X14 := #bit14;
#OUT.%X15 := #bit15;


This page has been accessed for: Today: 2, Until now: 391