Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

About Slicing

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

PLC concepts

5.4 Data types

You create a custom PLC data type structure using the same editing methods that are used in
the data block editor. Add new rows for any data types that are necessary to create the data
structure that you want.
If a new PLC data type is created, then the new PLC type name will appear in the data type
selector drop-down lists in the DB editor and code block interface editor.
You can potentially use PLC data types in the following ways:
● As a data type in a code block interface or in data blocks
● As a template for the creation of multiple global data blocks that use the same data structure
● As a data type for PLC tag declarations the I and Q memory areas of the CPU
For example, a PLC data type could be a recipe for mixing colors. You can then assign this PLC
data type to multiple data blocks. You can adjust the variables within each data block to create
a specific color.

The data type Variant can point to variables of different data types or parameters. The Variant
pointer can point to structures and individual structural components. The Variant pointer does
not occupy any space in memory.

Table 5-40 Properties of the Variant pointer

0 Symbolic Operand MyTag


DB_name.Struct_name.element_name MyDB.Struct1.pressure1
Absolute Operand %MW10
DB_number.Operand Type Length P#DB10.DBX10.0 INT 12

PLC tags and data block tags can be accessed at the bit, byte, or word level depending on their
size. The syntax for accessing such a data slice is as follows:
● "<PLC tag name>".xn (bit access)
● "<PLC tag name>".bn (byte access)
● "<PLC tag name>".wn (word access)
● "<Data block name>".<tag name>.xn (bit access)
● "<Data block name>".<tag name>.bn (byte access)
● "<Data block name>".<tag name>.wn (word access)
A double word-sized tag can be accessed by bits 0 - 31, bytes 0 - 3, or word 0 - 1. A word-sized
tag can be accessed by bits 0 - 15, bytes 0 - 1, or word 0. A byte-sized tag can be accessed by

S7-1200 Programmable controller


124 System Manual, V4.4 11/2019, A5E02486680-AN
PLC concepts
5.4 Data types

bits 0 - 7, or byte 0. Bit, byte, and word slices can be used anywhere that bits, bytes, or words
are expected operands.

Valid data types that can be accessed by slice are Byte, Char, Conn_Any, Date, DInt, DWord,
Event_Any, Event_Att, Hw_Any, Hw_Device, HW_Interface, Hw_Io, Hw_Pwm,
Hw_SubModule, Int, OB_Any, OB_Att, OB_Cyclic, OB_Delay, OB_WHINT, OB_PCYCLE,
OB_STARTUP, OB_TIMEERROR, OB_Tod, Port, Rtm, SInt, Time, Time_Of_Day, UDInt, UInt,
USInt, and Word. PLC Tags of type Real can be accessed by slice, but data block tags of type
Real cannot.

In the PLC tag table, "DW" is a declared tag of type DWORD. The examples show bit, byte, and
word slice access:

IF "DW".x11 THEN
...
END_IF;

IF "DW".b2 = "DW".b3
THEN
...
END_IF;

out:= "DW".w0 AND


"DW".w1;

S7-1200 Programmable controller


System Manual, V4.4 11/2019, A5E02486680-AN 125

You might also like