meta data for this page
Differences
This shows you the differences between two versions of the page.
| — | simatic:typedef [2025/01/16 10:00] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ~~NOCACHE~~ | ||
| + | ====== LamaPLC: Simatic datatypes ====== | ||
| + | {{ : | ||
| + | |||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | * [[# | ||
| + | |||
| + | ====== TIA Data type limits ====== | ||
| + | |< 100% >| | ||
| + | ^Decimal^Hex^TIA data type^Byte^Description| | ||
| + | |18, | ||
| + | |9, | ||
| + | |9, | ||
| + | |4, | ||
| + | |2, | ||
| + | |16, | ||
| + | |65, | ||
| + | |32, | ||
| + | |255|FF|[[# | ||
| + | |127|7F|[[# | ||
| + | |−128|80|[[# | ||
| + | |−32, | ||
| + | |−2, | ||
| + | |−9, | ||
| + | ====== TIA Datatypes ====== | ||
| + | {{ : | ||
| + | {{anchor: | ||
| + | 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/ | ||
| + | ^**Binaries**||||||| | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | ^Datatyp^Width (bits)^Range of values^Examples^S7-300/ | ||
| + | ^**Integers**||||||| | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | ^Datatyp^Width (bits)^Range of values^Examples^S7-300/ | ||
| + | ^**floating point numbers**||||||| | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | ^Datatyp^Width (bits)^Range of values^Examples^S7-300/ | ||
| + | ^**Times**||||||| | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |**Timer operations: | ||
| + | ^Datatyp^Width (bits)^Range of values^Examples^S7-300/ | ||
| + | ^**Counters**||||||| | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |**Counter operations: | ||
| + | ^Datatyp^Width (bits)^Range of values^Examples^S7-300/ | ||
| + | ^**Date & time**||||||| | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | ^Datatyp^Width (bits)^Range of values^Examples^S7-300/ | ||
| + | ^**Pointers**||||||| | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |{{anchor: | ||
| + | |||
| + | ===== TIA Coding of data types ===== | ||
| + | {{anchor: | ||
| + | |||
| + | The following table lists the coding of data types for the ANY pointer: | ||
| + | |< 100% >| | ||
| + | ^Hexadecimal code^Data type^Description| | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | ^B# | ||
| + | |||
| + | ===== TIA Coding of the memory area ===== | ||
| + | {{anchor: | ||
| + | The following table lists the coding of the memory areas for the ANY pointer: | ||
| + | |||
| + | |< 100% >| | ||
| + | ^Hexadecimal code^Area^Description| | ||
| + | |B# | ||
| + | |B# | ||
| + | |B# | ||
| + | |B# | ||
| + | |B# | ||
| + | |B# | ||
| + | |B# | ||
| + | |B# | ||
| + | ====== Simatic classic datatypes (S7-300 / S7-400) ====== | ||
| + | {{anchor: | ||
| + | |||
| + | |< 100%>| | ||
| + | | ** Type and description ** | ** size in bits ** | ** format options ** | ** Area and number notation \\ (lower | ||
| + | |BOOL (Bit)| | ||
| + | |BYTE (Byte)| | ||
| + | |WORD (Word)| | ||
| + | |Hexadecimal number|W# | ||
| + | |BCD|C#0 to C#999|L C#998| | ||
| + | |Decimal number unsigned|B# | ||
| + | |DWORD (Double word)| | ||
| + | |Hexadecimal number|W# | ||
| + | |Decimal number unsigned|B# | ||
| + | |INT (Integer)| | ||
| + | |DINT (Double integer)| | ||
| + | |REAL (Floating-point number)| | ||
| + | |S5TIME (SIMATIC time)| | ||
| + | |TIME (IEC time)| | ||
| + | |DATE (IEC date)| | ||
| + | |TIME _OF_DAY (Time)| | ||
| + | |CHAR (Character)| | ||
| + | |||
| + | ====== Data-types ====== | ||
| + | {{anchor: | ||
| + | [[# | ||
| + | |||
| + | ===== Pointer ===== | ||
| + | {{anchor: | ||
| + | An example above to the pointer: <color blue> P# | ||
| + | \\ | ||
| + | The following elements make up a pointer: | ||
| + | |||
| + | |< 100% >| | ||
| + | |<color blue> | ||
| + | |<color blue> | ||
| + | |<color blue> | ||
| + | |<color blue> | ||
| + | |||
| + | 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: | ||
| + | |||
| + | A parameter of the type POINTER is a pointer that can point to a specific tag. It occupies 6 bytes (48 bits) in memory and may contain the following tag information: | ||
| + | |||
| + | * DB number, or 0 if the data is not stored in a DB | ||
| + | * Memory area in the CPU | ||
| + | * Tag address | ||
| + | |||
| + | The following figure shows the structure of parameter type POINTER: | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | ===== Any ===== | ||
| + | An ANY type parameter points to the start of a data area and specifies its length. An ANY pointer occupies 10 bytes of memory and may contain the following information: | ||
| + | |||
| + | **Data type:** \\ | ||
| + | Data type of the elements of the data area \\ | ||
| + | | ||
| + | **Repetition factor:** \\ | ||
| + | Number of elements of the data area \\ | ||
| + | | ||
| + | **DB number:** \\ | ||
| + | Data block that contains the declaration of data area elements. \\ | ||
| + | | ||
| + | **Memory area:** \\ | ||
| + | Memory area of the CPU that stores the data area elements. \\ | ||
| + | | ||
| + | **Start address of the data in the format " | ||
| + | Data area start identified by the ANY pointer. \\ | ||
| + | | ||
| + | **Zero pointer:** \\ | ||
| + | Use the zero pointer to indicate a missing value. A missing value may indicate that no value exists, or that the value is not yet known. A zero value represents the absence of a value, but is also a value. \\ | ||
| + | | ||
| + | In the programming languages SCL and STL, memory of any kind can be transferred upon a block call if an ANY pointer has been programmed at a block parameter. | ||
| + | |||
| + | The ANY pointer cannot, however, store any information on the structure of the memory. For example, the ANY pointer does not save the information that it points to a tag of the PLC data type. The ANY pointer sees this as an ARRAY of BYTE. | ||
| + | |||
| + | Parameters of the ANY data type can be passed to system function blocks (SFBs) or system functions (SFCs). | ||
| + | |||
| + | <WRAP center round important 100%> | ||
| + | **Memory area** \\ | ||
| + | For an S7-1500 CPU, the ANY pointer can also only point to memory areas with " | ||
| + | </ | ||
| + | |||
| + | |||
| + | {{ : | ||
| + | |||
| + | ===== Variant ===== | ||
| + | A parameter of the VARIANT type is a pointer that can point to tags of different data types other than an instance. The VARIANT pointer can be an object of an elementary data type, such as INT or REAL. It can also be a STRING, DTL, ARRAY of STRUCT, UDT, or ARRAY of UDT. The VARIANT pointer can recognize structures and point to individual structure components. An operand of data type VARIANT occupies no space in the instance data block or work memory. However, it will occupy memory space on the CPU. | ||
| + | |||
| + | A tag of the VARIANT type is not an object but rather a reference to another object. Individual elements of the VARIANT type can only be declared on formal parameters within the block interface of a function in the VAR_IN, VAR_IN_OUT and VAR_TEMP sections. For this reason, it cannot be declared in a data block or in the static section of the block interface of a function block, for example, because its size is unknown. The size of the referenced objects can change. | ||
| + | |||
| + | You can use VARIANT to generate generic function blocks or functions. When a block is called, you can connect the parameters of the block to tags of any data type. When a block is called, the type information of the tag is transferred in addition to a pointer to the tag. The code of the block can then be executed according to its type in line with the tag transferred during runtime. | ||
| + | |||
| + | If, for example, a block parameter of a function has the VARIANT data type, then a tag of the integer data type can be transferred at one point in the program, and a tag of the PLC data type can be transferred at another point in the program. With the help of the VARIANT instructions, | ||
| + | |||
| + | <WRAP center round important 100%> | ||
| + | You can only point to a complete data block if it was originally derived from a user-defined data type (UDT). | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Array ===== | ||
| + | The Array data type represents a data structure that consists of a fixed number of components of the same data type. All data types except Array are permitted. | ||
| + | |||
| + | A tag with the Array data type always starts at a WORD limit. | ||
| + | |||
| + | The array components are addressed by means of an index. In the array declaration, | ||
| + | |||
| + | **Length:** Number of components * length of the data type \\ | ||
| + | **Format:** Array [low limit...high limit] of <data type> \\ | ||
| + | **Index limits:** Depending on the CPU, the storage capacity of a data block is limited and the number of components of the Array is therefore also limited. However, you may initialize the addressing of the array components at any position within index limits. \\ | ||
| + | **Index limits (16-bit limits):** [-32768..32767] of <data type> \\ | ||
| + | **Index limits (32-bit limits):** [-2147483648..2147483647] of <data type> \\ | ||
| + | **Data type:** Bit strings, integers, floating-point numbers, timers, character strings, structures \\ | ||
| + | |||
| + | ===== Real, LReal IEEE 754 ===== | ||
| + | {{anchor: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * **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. | ||
| + | ===== Char ===== | ||
| + | An operand of data type CHAR has a length of 8 bits and occupies one BYTE in the memory. | ||
| + | |||
| + | The CHAR data type stores a single character in [[com: | ||
| + | |||
| + | **Length (bits):** 8 \\ | ||
| + | **Format:** ASCII characters \\ | ||
| + | **Value range:** ASCII character set \\ | ||
| + | **Example of value inputs:** ' | ||
| + | |||
| + | ===== WChar ===== | ||
| + | An operand of data type WCHAR (Wide Characters) has a length of 16 bits and occupies two BYTE in the memory. | ||
| + | |||
| + | The WCHAR data type saves a single character of an expanded character set which is stored in Unicode format. However, only a subset of the entire Unicode range is covered. When a control character is entered, it is represented with a dollar sign. | ||
| + | |||
| + | **Length (bits):** 16 bit \\ | ||
| + | **Format:** Unicode \\ | ||
| + | **Range of values:** $0000 - $D7FF \\ | ||
| + | **Example of value input:** WCHAR#' | ||
| + | |||
| + | |||
| + | ===== String ===== | ||
| + | |||
| + | String types in S7 are not NULL //" | ||
| + | |||
| + | So the string definition MyStr: STRING[10]: | ||
| + | |||
| + | 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: " | ||
| + | |||
| + | **Length (bits):** n + 2 (An operand of the STRING data type occupies two bytes more than the specified maximum length in the memory) \\ | ||
| + | **Format:** ASCII character string incl. special characters \\ | ||
| + | **Value range:** 0 to 254 characters \\ | ||
| + | **Example of value inputs:** ' | ||
| + | |||
| + | ===== WString ===== | ||
| + | An operand of data type WSTRING (Wide String) stores several Unicode characters of data type WCHAR in one character string. If you do not specify a length, the character string has a preset length of 254 characters. In a character string, all characters of the Unicode format are permitted. This means you can also use Chinese characters in a character string. | ||
| + | |||
| + | **Length (bits):** n + 2 (An operand of the WSTRING data type occupies two WORDs more in the memory than the specified maximum length) \\ | ||
| + | **Format:** Unicode character string; \\ | ||
| + | **Range of values:** Preset value: 0 to 254 characters, maximal possible value: 0 to 16382 \\ | ||
| + | **Example of value inputs:** WSTRING#' | ||
| + | |||
| + | When declaring an operand of data type WSTRING you can define its length using square brackets (for example WSTRING[10]). If you do not specify a length, the length of the WSTRING is set to 254 characters by default. You can declare a length of up to 16382 characters (WSTRING[16382]). | ||
| + | |||
| + | The specification of the characters occurs in single quotes and always with the qualifier WSTRING#. | ||
| + | |||
| + | A character string can also contain special characters. The escape character $ is used to identify control characters, dollar signs and single quotation marks. | ||
| + | |||
| + | |< 100%>| | ||
| + | ^Character^Hex^Meaning^Example| | ||
| + | ^$L or $l|000A|Line feed|' | ||
| + | ^$N|000A and 000D|Line break \\ The line break occupies 2 characters in the character string.|' | ||
| + | ^$P or $p|000C|Page feed|' | ||
| + | ^$R or $r|000D|Carriage return (CR)|' | ||
| + | ^$T or $t|0009|Tab|' | ||
| + | ^$$|0024|Dollar sign|' | ||
| + | ^$' | ||
| + | |||
| + | The maximum length of the character string can be specified during the declaration of an operand using square brackets after the keyword WSTRING (for example, WSTRING[4]). If the specification of the maximum length is omitted, the standard length of 254 characters is set for the respective operand. | ||
| + | |||
| + | If the actual length of a specified character string is shorter than the declared maximum length, the characters are written to the character string left-justified and the remaining character spaces remain undefined. Only occupied character spaces are considered in the value processing. | ||
| + | |||
| + | **Access to block parameters of data type WSTRING** \\ | ||
| + | Operands of the data type WSTRING can be transferred as parameters up to the maximum length for blocks with //" | ||
| + | |||
| + | For function blocks (FB) with //" | ||
| + | |||
| + | The function value of an FC in the //" | ||
| + | |||
| + | **Example** \\ | ||
| + | The example below shows the byte sequence if the WSTRING[4] data type is specified with output value ' | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | |||
| + | ===== S5TIME ===== | ||
| + | {{anchor: | ||
| + | * 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 ==== | ||
| + | {{: | ||
| + | |||
| + | |Time base|Binary Code| | ||
| + | |10 ms|00| | ||
| + | |100 ms|01| | ||
| + | |1 s|10| | ||
| + | |10 s|11| | ||
| + | |||
| + | ===== IEC timers (TP, TONR, TON, TOF) ===== | ||
| + | {{anchor: | ||
| + | You can find more information about these timer types here: [[simatic: | ||
| + | ====== Indirect addressing in Simatic Classic ====== | ||
| + | {{anchor: | ||
| + | |< 100% >| | ||
| + | ^Indirect addressing^Example| | ||
| + | ^Indirect addressing of a DB|Data type " | ||
| + | ^Indirect addressing of DB tags|# | ||
| + | ^Indirect addressing of I/O|QB(IDX : | ||
| + | ^Indirect addressing of PLC tags|IX(IDX : | ||
| + | ====== Indirect addressing in TIA Portal ====== | ||
| + | {{anchor: | ||
| + | |||
| + | 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 " | ||
| + | |||
| + | For example | ||
| + | * In the case of SCADA transmission, | ||
| + | * 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, | ||
| + | ===== TIA Portal slice access ===== | ||
| + | {{anchor: | ||
| + | |||
| + | * from Bit to: BYTE, WORD, DWORD | ||
| + | * from Byte to: WORD, DWORD | ||
| + | * from Word to: DWORD | ||
| + | |||
| + | <code pascal> | ||
| + | bit := byte.%X1; | ||
| + | bit := word.%X4; | ||
| + | bit := dword.%X11; | ||
| + | |||
| + | byte := word.%B1; | ||
| + | byte := dword.%B2; | ||
| + | |||
| + | word := dword.%W0; | ||
| + | </ | ||
| + | The following example is a SPLIT function that splits a WORD Input variable into bits: | ||
| + | <code pascal> | ||
| + | // FC Input : inWord (Word) | ||
| + | // FC output: 16 variable bit0..bit15 (Bool) | ||
| + | // splitting | ||
| + | #bit0 := # | ||
| + | #bit1 := # | ||
| + | #bit2 := # | ||
| + | #bit3 := # | ||
| + | #bit4 := # | ||
| + | #bit5 := # | ||
| + | #bit6 := # | ||
| + | #bit7 := # | ||
| + | #bit8 := # | ||
| + | #bit9 := # | ||
| + | #bitA := # | ||
| + | #bitB := # | ||
| + | #bitC := # | ||
| + | #bitD := # | ||
| + | #bitE := # | ||
| + | #bitF := # | ||
| + | </ | ||
| + | And this is a JOIN function that assembles a WORD from 16 bits: | ||
| + | <code pascal> | ||
| + | // 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> | ||
| + | \\ | ||
| + | This page has been accessed for: Today: {{counter|today}}, | ||