With the transition from „Classic“ Step 7 to TIA Portal and introduction of Optimized Data Blocks the syntax for accessing parts of variable has changed.
Since Optimised DBs automatically assign where variable is stored by their type (to optimize the memory usage) the means of accessing parts of variable with direct addressing are no longer available.
TIP! You can turn off DB optimization for the blocks of your choice. This is helpful if you require to do direct addressing (but not slicing) because of how your code is structured.
TIA Portal How To: Table of Contents
1. Required TIA Portal version.
- STEP 7 (TIA Portal) V11+SP1+Upd 2 (or higher) for S7-1200 (firmware V2.0 and higher).
- STEP 7 (TIA Portal) V12 (or higher) for S7-1500.
2. Syntax of variable slicing
In Step 7 classic to access 6th Bit of variable Tag_1 (type: Word, address: DB4.DBW2) we would use expression: DB4.DBX2.5
Currently, in TIA Portal, we would use the following syntax: “Slicing”.Tag_2.%X5
Please notice that we don’t even have the byte number anymore in either the expression or the DB (remember – only in optimized blocks) – instead we use the tag name.
Symbolic Bit, Byte and Word Access in a variable (tag):Picture source: Siemens Website
3. Examples of variable slicing
Here you will find examples referring to tags defined in DB4 (“Slicing”) from picture in Point 2 above.
- Access bit in a byte:
- Access Bit in a Word
- Access Byte in a Word
In Double Word
- Access Bit in a DWord
- Access Byte in a DWord
- Access Word in a DWord
- Access Bit in an Int
- Access Byte in an Int
In Long Integer
- Access Bit in a LInt
- Access Byte in a LInt
- Access Word in a LInt
Liked this article?Remember to sign up for newsletter to get notified of new entries.