~~NOCACHE~~ ====== LamaPLC: Simatic datatypes ====== {{ :simatic:simatic_s7_1500_7.png?300|}} * [[#tia_types|TIA Portal datatypes (S7-1500 / S7-1200 / S7-400 / S7-300)]] * [[#classic_types|Simatic classic datatypes (S7-400 / S7-300)]] * [[#tia_data_type_codes|TIA Data types codes]] * [[#data_types|Data-types]] * [[#pointer|Pointer]] * [[#real|Real]] * [[#string|String]] * [[#s5time|S5time]] * [[#indirect_addr_classic|Indirect addressing in Simatic Classic]] * [[#indirect_addr_tia|Indirect addressing in TIA Portal]] * [[#slice_addr_tia|TIA Portal slice access]] ====== TIA Portal datatypes ====== {{ :simatic:digi.png?100|TIA Portal datatypes}} {{anchor:tia_types}} 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. \\ \\ ^Datatyp^Width (bits)^Range of values^Examples^S7-300/400^S7-1200^S7-1500| ^**Binaries**||||||| |{{anchor:bool}}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|X|X|X| |{{anchor:byte}}BYTE (b)|8|B#16#00 .. B#16#FF \\ -128 .. +127 or 0 .. +255 \\ 2#0 .. 2#11111111|15, \\ BYTE#15, \\ B#15|X|X|X| |{{anchor:word}}WORD (w)|16|W#16#0000 .. W#16#FFFF \\ -32768 .. 65535 \\ B#(0, 0) .. B#(255, 255) |55555,\\ WORD#55555,\\ W#555555|X|X|X| |{{anchor:dword}}DWORD (dw)|32|DW#16#0000 0000 .. DW#16#FFFF FFFF|DW#16#DEAD BEEF \\ B#(111, 222, 255, 200)|X|X|X| |{{anchor:lword}}LWORD (lw)|64|LW#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| ^Datatyp^Width (bits)^Range of values^Examples^S7-300/400^S7-1200^S7-1500| ^**Integers**||||||| |{{anchor:sint}}SINT (si)|8|-128 .. 127 \\ (hex nur poz.) 16#0 .. 16#7F|+42, SINT#+42 \\ 16#1A, SINT#16#2A|-|X|X| |{{anchor:int}}INT (i)|16|-32768 .. 32767 \\ (hex nur poz.) 16#0 .. 16#7FFF |+1234, INT#+3221 \\ 16#1ABC|X|X|X| |{{anchor:dint}}DINT (di)|32|-2147483648 .. +2147483647 \\ (hex nur poz.) \\ 16#00000000 .. 16#7FFFFFFF|123456, DINT#123456, \\ 16#1ABC BEEF|X|X|X| |{{anchor:usint}}USINT (usi)|8|0 .. 255|42, USINT#42 \\ 16#FF|-|X|X| |{{anchor:uint}}UINT (ui)|16|0 .. 65535|12345, UINT#12345 \\ 16#BEEF|-|X|X| |{{anchor:udint}}UDINT (udi)|32|0 .. 4294967295|1234567890, UDINT#1234567890 |-|X|X| |{{anchor:lint}}LINT (li)|64|-9223372036854775808 .. +9223372036854775807|+1234567890123456789, LINT#+1234567890123456789|-|-|X| |{{anchor:ulint}}ULINT (uli)|64|0 .. 18446744073709551615|123456789012345, ULINT#123456789012345|-|-|X| ^Datatyp^Width (bits)^Range of values^Examples^S7-300/400^S7-1200^S7-1500| ^**floating point numbers**||||||| |{{anchor:real}} 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|X|X|X| |{{anchor:lreal}} LREAL (lr)|64|-1.7976931348623158e+308 .. -2.2250738585072014e-308 \\ .. \\ +2.2250738585072014e-308 .. +1.7976931348623158e+308|0.0, LREAL#0.0|-|X|X| ^Datatyp^Width (bits)^Range of values^Examples^S7-300/400^S7-1200^S7-1500| ^**Times**||||||| |{{anchor:s5time}}S5TIME (s5t) \\ [[#s5time|→details]]|16|S5T#0H_0M_0S_0MS .. S5T#2H_46M_30S_0MS|S5T#10s, S5TIME#10s|X|-|X| |{{anchor:time}}TIME (t)|32|T#-24d20h31m23s648ms .. T#+24d20h31m23s647ms|T#13d14h15m16s630ms, TIME#1d2h3m4s5ms|X|X|X| |{{anchor:ltime}}LTIME (lt)|64|LT#-106751d23h47m16s854ms775us808ns .. LT#+106751d23h47m16s854ms775us807ns|LT#1000d10h15m24s130ms152us15ns, LTIME#200d2h2m1s8ms652us315ns|-|-|X| |**Timer operations:** **[[simatic:scl_commands#iec_timers|IEC timers]]**, **[[simatic:scl_commands#ton|TON]]** (Generate on-delay), **[[simatic:scl_commands#tof|TOF]]** (Generate off-delay), **[[simatic:scl_commands#tp|TP]]** (Generate pulse), **[[simatic:scl_commands#tonr|TONR]]** (Time accumulator) ||||||| ^Datatyp^Width (bits)^Range of values^Examples^S7-300/400^S7-1200^S7-1500| ^**Counters**||||||| |{{anchor:char}}CHAR|8|ASCII character set|'A', CHAR#'A'|X|X|X| |{{anchor:wchar}}WCHAR (wc)|16|Unicode character set|WCHAR#'A'|-|X|X| |{{anchor:string}}STRING (s) \\ [[#string|→details]]|n+2 (Byte)|0 .. 254 characters (n)|'Name', STRING#'OB121'|X|X|X| |{{anchor:wstring}}WSTRING (ws)|n+2 (Word)|0 .. 16382 characters (n)|WSTRING#'OB121'|-|X|X| |**Counter operations:** **[[simatic:scl_commands#ctu|CTU]]** (count up), **[[simatic:scl_commands#ctd|CTD]]** (count down), **[[simatic:scl_commands#ctud|CTUD]]** (count up and down) ||||||| ^Datatyp^Width (bits)^Range of values^Examples^S7-300/400^S7-1200^S7-1500| ^**Date & time**||||||| |{{anchor:date}}DATE (d)|16|D#1990-01-01 .. D#2168-12-31|D#2020-08-14, DATE#2020-08-14|X|X|X| |{{anchor:tod}}TOD (tod) \\ (TIME_OF_DAY)|32|TOD#00:00:00.000 .. TOD#23:59:59.999|TOD#11:22:33.444, \\ TIME_OF_DAY#11:22:33.444|X|X|X| |{{anchor:ltod}}LTOD (ltod) \\ (LTIME_OF_DAY)|64|LTOD#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| |{{anchor:dt}}DT (dt) \\ (DATE_AND_TIME)|64|Min.: DT#1990-01-01-0:0:0 \\ Max.: DT#2089-12-31-23:59:59.999|DT#2020-08-14-2:44:33.111, \\ {{anchor:date_and_time}}DATE_AND_TIME#2020-08-14-11:22:33.444|X|-|X| |{{anchor:ldt}}LDT (ldt) \\ (L_DATE_AND_TIME)|64|Min.: 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| |{{anchor:dtl}}DTL (dtl)|96|Min.: 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|-|X|X| ^Datatyp^Width (bits)^Range of values^Examples^S7-300/400^S7-1200^S7-1500| ^**Pointers**||||||| |{{anchor:pointer}}POINTER (p) \\ [[#pointer|→details]]|48||Symbolic: "DB"."Tag" \\ Absolute: \\ P#10.0 \\ P#DB4.DBX3.2|X|-|X| |{{anchor:any}}ANY (any)|80||Symbolic: \\ "DB".StructVariable.firstComponent \\ Absolut: P#DB11.DBX12.0 INT 3 \\ P#M20.0 BYTE 10|X|-|X| |{{anchor:variant}}VARIANT (var)|0||Symbolic:\\ "Data_TIA_Portal".\\ StructVariable.firstComponent \\ Absolute: %MW10 \\ P#DB10.DBX10.0 INT 12|-|X|X| |{{anchor:block_fb}}BLOCK_FB|0||-|X|-|X| |{{anchor:block_fc}}BLOCK_FC|0||-|X|-|X| |{{anchor:block_db}}BLOCK_DB|0||-|X|-|-| |{{anchor:block_7sdb}}BLOCK_SDB|0||-|X|-|-| |{{anchor:void}}VOID|0||-|X|X|X| |{{anchor:plc_data_type}}PLC_DATA_TYPE|0||-|X|X|X| ===== TIA Data types codes ===== {{anchor:tia_data_type_codes}} |< 100% >| ^Hexadecimal code^Data type^Description| ^B#16#00|NIL|Null pointer| ^B#16#01|BOOL|Bits| ^B#16#02|BYTE|bytes, 8 bits| ^B#16#03|CHAR|8-bit characters| ^B#16#04|WORD|16-bit words| ^B#16#05|INT|16-bit integers| ^B#16#06|DWORD|32-bit words| ^B#16#07|DINT|32-bit integers| ^B#16#08|REAL|32-bit floating-point numbers| ^B#16#0B|TIME|Time duration| ^B#16#0C|S5TIME|Time duration| ^B#16#09|DATE|Date| ^B#16#0A|TOD|Date and time| ^B#16#0E|DT|Date and time| ^B#16#13|STRING|Character string| ^B#16#17|BLOCK_FB|Function block| ^B#16#18|BLOCK_FC|Function| ^B#16#19|BLOCK_DB|Data block| ^B#16#1A|BLOCK_SDB|System data block| ^B#16#1C|COUNTER|Counter| ^B#16#1D|TIMER|Timer| ====== Simatic classic datatypes (S7-300 / S7-400) ====== {{anchor:classic_types}} | ** Type and description ** | ** size in bits ** | ** format options ** | ** Area and number notation \\ (lower .. higher value) ** | ** example in STL ** | |BOOL (Bit)| 1|Boolean text|TRUE/FALSE|TRUE| |BYTE (Byte)| 8|Hexadecimal number|B#16#0 to B#16#FF|L B#16#10\\ L byte#16#10| |WORD (Word)| 16|Binary number|2#0 to 2#1111_1111_1111_1111|L 2#0001_0000_0000_0000| |Hexadecimal number|W#16#0 to W#16#FFFF|L W#16#1000\\ L word#16#1000| |BCD|C#0 to C#999|L C#998| |Decimal number unsigned|B#(0,0) to B#(255,255)|L B#(10,20)\\ L byte#(10,20)| |DWORD (Double word)| 32|Binary number|2#0 to 2#1111_1111_1111_1111_\\ 1111_1111_1111_1111| L 2#1000_0001_0001_1000_\\ 1011_1011_0111_1111 | |Hexadecimal number|W#16#0000_0000 to W#16#FFFF_FFFF|L DW#16#00A2_1234\\ L dword#16#00A2_1234| |Decimal number unsigned|B#(0,0,0,0) to B#(255,255,255,255)|L B#(1, 14, 100, 120)\\ L byte#(1,14,100,120)| |INT (Integer)| 16|Decimal number signed|-32768 to 32767|L 101| |DINT (Double integer)| 32|Decimal number signed|L#-2147483648 to L#2147483647|L L#101| |REAL (Floating-point number)| 32|IEEE Floating-point number|Upper limit +/-3.402823e+38\\ Lower limit +/-1.175495e-38|L 1.234567e+13| |S5TIME (SIMATIC time)| 16|S7 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)| 32|IEC time in steps of 1 ms, integer signed|T#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)| 16|IEC date in steps of 1 day|D#1990-1-1 to\\ D#2168-12-31|L D#1996-3-15\\ L DATE#1996-3-15| |TIME _OF_DAY (Time)| 32|Time in steps of 1 ms|TOD#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)| 8|ASCII characters|A', 'B' etc.|L 'E'| ====== Data-types ====== {{anchor:data_types}} ===== Pointer ===== {{anchor:pointer}} An example above to the pointer: P#DB100.DBX14.0 WORD 4 \\ The following elements make up a pointer: |< 100% >| |**P#**|Pointer identifier| |**DB100**|Start Data block / memory area| |**.DB14.0**|Start offset within the data block| |**WORD 4**|Length 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. [[simatic:scl_commands#blkmov|BLKMOV]] must be used instead, and in order to use that, [[:simatic:tia_knowhow#db_opt|Optimized Data must be turned off]]! ===== Real, LReal IEEE 754 ===== {{anchor:real}} {{:simatic:real_type.png|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 ===== {{anchor: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 ===== {{anchor: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 ==== {{:simatic:s5timeformat.png?400|"S5TIME" Format}} |Time base|Binary Code| |10 ms|00| |100 ms|01| |1 s|10| |10 s|11| ====== Indirect addressing in Simatic Classic ====== {{anchor:indirect_addr_classic}} |< 100% >| ^Indirect addressing^Example| ^Indirect addressing of a DB|Data 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/O|QB(IDX :=#myInt):P| ^Indirect addressing of PLC tags|IX(IDX :=#myInt1,Bit:=#myInt2) \\ \\ QB(IDX :=#myInt) \\ \\ MW(IDX :=#myInt)| ====== Indirect addressing in TIA Portal ====== {{anchor:indirect_addr_tia}} 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 ===== {{anchor:slice_addr_tia}} * 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; \\ {{tag>simatic s7 scl datatype}} \\ This page has been accessed for: Today: {{counter|today}}, Until now: {{counter|total}}