Introduction
Quite often we need to break down some Tags and get certain information from it. For example, we want to get some characters from a barcode scanner’s read strings or we want the minutes of a date and time tag or we want a certain alarm bit from an alarm word.
In TIA Portal, there are multiple ways to achieve the above target and I am going to introduce 3 of them that are most frequently used.
Absolute Access
Absolute access is the simplest way to access the data under a tag. Though it is limited to the basic data types of Bool, Byte, Word and DWord, it can cover most of the scenarios that we need to do this kind of programming.
In the below example, I have a LWord tag and I will use the absolute access to pick the first bool, the fifth byte, the third word and the second DWord. The LWord tag targetTag has the value of 16#0F0E_0D0C_0B0A_0803, each absolute access will slice targetTag into bools, bytes, words and DWords independently then grab the respective data based on the offset specified in the program.
Below is potentially a better demonstration of this process from SIEMENS support page.
AT Overlay
The AT overlay is an older way to access the underlying data though still very popular. Note that the AT overlay requires non-optimized data access.
In the below example, I want to slice a string into individual characters. The string data has my favorite quote from movie the Grand Budapest Hotel:
“To be frank, I think his world had vanished long before he even entered it. But I will say, he certainly sustained the illusion with a marvelous grace.”
All that I need to do is to create a tag overlay in the data declaration. The extra char array and the program is merely to show the result. In a practical situation, they’re not required.
To create an AT overlay, follow the below process.
- Insert a line below the tag that you want to create the data overlay and type AT in the data type cell then press enter.
- Change the overlay tag’s data type and tag name.
Now you can use the overlaid tags in your program freely.
Note that the overlaid tags can only be used inside the FB / FC and can’t be observed. If you need to access them from the outside of the FB / FC, you need to first put them in a defined place in the block’s static memory or interface.
Serialize
The third method is to use the serialize command. This command can be combined with the deserialize command to process data transmission seamlessly. Though it will be another topic.
The serialize command basically puts data from any tag to a defined tag array. While doing so, it helps break down tags into individual elements.
In the below example, the program reads the system date and time. With the serialize command, the program breaks down the complex data type into 8 bytes that represent the defined bytes of data and time datatype.
Based on the definition of date and time data type, it is made from 8 bytes following the below definition.
Byte | Component | Value Range |
---|---|---|
0 | Year | 0 - 99: 1990 - 2089 |
1 | Month | 1 - 12: Jan - Dec |
2 | Day | 1 - 31 |
3 | Hour | 0 - 23 |
4 | Minute | 0 - 59 |
5 | Second | 0 - 59 |
6 | The two most significant digits of MSEC | 0 - 999 |
7 (4MSB) | The least significant digit of MSEC | 0 - 9 |
8 (4LSB) | Weekday | 1 - 7: Sun - Sat |
MSB: most significant bit.
LSB: least significant bit.
As we can see the breakdown bytes reflects the date and time values accurately.
Conclusion
This article introduces 3 different ways to access tags’ underlying data in S7-1200 / 1500. The absolute access way is the simplest but is limited to individual Bool, Byte, Word and DWord. The AT overlay method is a very elegant and efficient way to break down large and complex tags but it requires non-optimized data access. The serialize command is the latest way, complies with optimized data access and offers program flexibility.