meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
automation:direct_indirect_addressing [2026/01/16 13:45] vamsanautomation:direct_indirect_addressing [2026/01/16 17:24] (current) vamsan
Line 1: Line 1:
-=== Direct / indirect addressing ===+=== Direct/indirect addressing ===
  
 Addressing methods are mostly tied to variable types, not areas, so the following procedures apply to both DB and Tag variables. Addressing methods are mostly tied to variable types, not areas, so the following procedures apply to both DB and Tag variables.
Line 28: Line 28:
 </WRAP> </WRAP>
  
-Direct addressing is also applicable to [[#structure|STRUCTURE]] and [[#array|ARRAY]] types, as long as both sides have identical structures. +Direct addressing is also applicable to [[#structure|STRUCTURE]] and [[#array|ARRAY]] types, provided both sides have identical structures. 
  
-Another approach is direct addressing, which involves referring to sub-elements of a variable. Although this method applies to a limited range of variables, it is a simple form of assignment. While it isn't as straightforward as the S7-Classic AT command that many programmers prefer, it is at least available:+Another approach is direct addressing, which involves referring to a variable'sub-elements. Although this method applies to a limited range of variables, it is a simple form of assignment. While it isn't as straightforward as the S7-Classic AT command that many programmers prefer, it is at least available:
  
 == Slice addressing == == Slice addressing ==
 {{anchor:slice}} {{anchor:slice}}
-Slice addressing involves dividing a memory region, such as a byte or word, into smaller segments like booleans. With S7-1200 and S7-1500, you can target specific parts within declared variables (**only by byte, word, dword**) and access segments of 1, 8, 16, or 32 bits. +Slice addressing involves dividing a memory region, such as a byte or word, into smaller segments, such as booleans. With S7-1200 and S7-1500, you can target specific parts within declared variables (**only by byte, word, dword**) and access segments of 1, 8, 16, or 32 bits. 
  
 {{:automation:slice_1.png|Slice addressing TIA Portal}} {{:automation:slice_1.png|Slice addressing TIA Portal}}
Line 76: Line 76:
 ^Name^Length^Description| ^Name^Length^Description|
 ^Syntax ID|1 byte|Always 16#10 for S7| ^Syntax ID|1 byte|Always 16#10 for S7|
-^Data Type|1 byte|Code for the type of data being pointed to (e.g., 16#02 for Byte; see bellow in the table "TIA Coding of data types"|+^Data Type|1 byte|Code for the type of data being pointed to (e.g., 16#02 for Byte; see below in the table "TIA Coding of data types"|
 ^Repetition Factor|2 bytes|Number of elements of the specified data type| ^Repetition Factor|2 bytes|Number of elements of the specified data type|
 ^DB Numbe|2 bytes|The number of the data block (0 if not in a DB)| ^DB Numbe|2 bytes|The number of the data block (0 if not in a DB)|
-^Memory Area|1 byte|Code for the memory area (e.g., 16#84 for DB; see bellow in the table "TIA Coding of the memory area")|+^Memory Area|1 byte|Code for the memory area (e.g., 16#84 for DB; see below in the table "TIA Coding of the memory area")|
 ^Address|3 bytes|The start address of the data (bit and byte address)| ^Address|3 bytes|The start address of the data (bit and byte address)|
  
Line 88: Line 88:
 == Example of using the ANY type == == Example of using the ANY type ==
  
-The pointer with the ANY type is most frequently used with the [[#blkmov|BLKMOV]] command, which copies data from one area to another indirectly. In the example below, the created data set is transferred to one of three mobile data areasbased on the location of the variable //"assHMI".Panel1ASS// points:+The pointer with the ANY type is most frequently used with the [[#blkmov|BLKMOV]] command, which copies data from one area to another indirectly. In the example below, the created dataset is transferred to one of three mobile data areas based on the location of the variable //"assHMI".Panel1ASS// points:
  
 <code pascal> <code pascal>
Line 102: Line 102:
 END_CASE; END_CASE;
 </code> </code>
 +== VARIANT versus ANY ==
 +
 +  * **ANY** is a fixed 10-byte structure that references an absolute memory address.
 +  * **VARIANT** is a type-safe pointer that preserves the original data type information and enables symbolic addressing without the need for fixed memory location overhead.
 +  * The **ANY** is an older type, already available in the S300 / 400 series.
 +* The **ANY** can only be used with the S7-1500, whereas **VARIANT** are accessible on all S7 models.
  
  
 == VARIANT type == == VARIANT type ==
 {{anchor:variant}} {{anchor:variant}}
 +A VARIANT type parameter is a pointer that can reference various data types beyond a simple instance. This pointer can be an object of a basic data type like [[#int|INT]] or [[#real|REAL]], or it can be a [[#string|STRING]], [[#dtl|DTL]], [[#array_of_struct|ARRAY of STRUCT]], [[#udt|UDT]], or an [[#array_of_udt|ARRAY of UDT]]. The VARIANT pointer can also recognize structures and point directly to individual members of those structures. An operand of VARIANT type does not consume space in the instance data block or work memory but does require memory on the CPU.
 +
 +<WRAP center round important 80%>
 +  * Directly assigning a tag to a VARIANT, like //myVARIANT := #Variable//, is not possible.
 +  * Direct reading or writing of a signal from an I/O input or output is only possible with an S7-1500 module. 
 +  * You can only reference a complete data block if it was originally created from a user-defined data type ([[#udt|UDT]]).
 +</WRAP>
 +