TIA Portal how to access part of a variable – TAG SLICING

0
TIA Portal how to access part of variable

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.

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

TIA Portal How To tag slicing
TIA Portal How To tag 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):

TIA Portal how to access part variable tag slicing
TIA Portal how to access part variable tag slicing
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.

In Byte:

  • Access bit in a byte:
TIA Portal How To access Bit in Byte
TIA Portal How To access Bit in Byte

In Word:

  • Access Bit in a Word
  • Access Byte in a Word
TIA Portal How To access Byte in Word
TIA Portal How To access Byte in Word

In Double Word

  • Access Bit in a DWord
  • Access Byte in a DWord
  • Access Word in a DWord
TIA Portal How To access Word in DWord
TIA Portal How To access Word in DWord

In Integer:

  • Access Bit in an Int
  • Access Byte in an Int
TIA Portal How To access Bit in Integer
TIA Portal How To access Bit in Integer

In Long Integer

  • Access Bit in a LInt
  • Access Byte in a LInt
  • Access Word in a LInt
TIA Portal Integer slicing
TIA Portal Integer slicing

Liked this article?

Remember to sign up for newsletter to get notified of new entries.