Understanding the Siemens Data Block (DB) File Format in TIA Portal

Article summary

This engineering brief presents a practical method for initializing a large number of variables in a Siemens TIA Portal Data Block (DB). Data may be developed in Excel and transferred to the PLC tool using a text file. The method can save time and eliminate errors associated with manually entering a large dataset.

:stopwatch: Estimated reading time: 4 minutes

What is a data block?

A Data Block (DB) is a memory container for the Siemens PLC. In some respects, the DB is like the memory associated with other Program Organizational Units (POUs). However, unlike programs and UDFBs, they do not contain instructions.

When used with arrays, the DB operates as a lookup table allowing indexed retrieval of preinitialized variables.

Figure 1: Image of an array stored in a Siemens data block.

Author’s personal experience

Personally, I find the DB especially useful for array initialization. We see this in Figure 1 where a DB called TestBlock contains an 11-element (zero-indexed) array for myVar. A start value has been assigned for each array member.

In this application the DB acts as a preinitialized lookup table. In a future article I will demonstrate how this lookup table was used to make the S7-1200 sing a song. This is a classic application on the microcontroller side of the house where the song demonstrates understanding of indexed memory.

How is a data block initialized?

There are two methods to initialize the start values for a data block.

Manually

Manually entering the values into the TIA portal tool as shown in Figure 1. This works for small datasets but becomes increasingly difficult and time consuming at the dataset grows. If we had to place a number on this, we should shift when a dataset grows beyond about 25 items.

Automated

The automated method allows us to transfer the hard work to a spreadsheet or our favorite programming language. This significantly reduces the chance of human transposing error. Depending on the application, this has the potential to increase the speed as numbers may be automatically generated. The secret to this automated process is TIA Portal’s ability to read and write to external files. The .db file associated with Figure 1 is shown in Figure 2.

Figure 2: Screen capture of the data block definition contained within Notepad++.

How can I determine the format of a Siemens DB file?

To get started, construct a small representative DB from within TIA Portal. After you have verified that it compiles correctly, export the DB to an external file. From there, you will be able to modify the file by including additional array members, changing the size of the array, or adding additional variables.

This is the technique used to construct the featured DB. Figure 2 started out as an array with three elements. The operational database in Figure 1 was constructed by uploading Figure 1.

Spreadsheet automation

We can argue that a spreadsheet such as Microsoft Excel is one of the most useful “programming” tools used by engineers. It allows the designer to quickly enter data, perform limited data processing, concatenate the data into strings, and add notes.

An example is shown in Figure 3. This is part of my upcoming article to make the PLC sing. The columns are organized as:

  • Musical note
  • Frequency in Hz
  • Components of the string in columns D to H
  • Concatenated strings in column I

Figure 3: Example spreadsheet used to build strings suitable for array initialization.

Tech Tip: The structured text keyword VAR can be elusive. We often see it in the literature and AI vibe coding. However, we don’t often find it in the wild as most POU variables are defined in the graphical declaration table (an OEM dependent statement).

Close inspection of Figure 1 and Figure 2 shows the similarity as we declare our variable as an array with the statement myVar : Array[0..10] of UDInt;.

How to move the data back into TIA Portal

At this point we have concatenated strings contained within a spreadsheet (Figure 3). The next step is to copy the string back into the .db text file (Figure 2). Save the file. Our final step is to add a new external file as shown in Figure 4.

Figure 4: Project tree showing the location of the TestBlock.db text file and operational TestBlock [DB4].

Parting thoughts

This procedure provides a simple way to construct a lookup table in Siemens TIA Portal.
Perhaps another day we can explore the utility of the method as there are potential risks to the read-modify-write procedure. Version control immediately comes to mind. Also, the tools weren’t exactly built for this method.

However, with an abundance of caution and attention to the final DB it is reasonably safe; certainly as safe as manually entering the values.

Let us know what you think by leaving your comments and suggestions in the space below. Also, let us know what you were doing that required arrays or multidimensional arrays with more than 25 elements.

Best wishes,

APDahlen

Related articles by this author

If you enjoyed this article, you may also find these related articles helpful:

TL;DR

  • The Siemens data block may be used as a lookup table
  • Array values may be developed using Excel and then transferred into the data block using Notepad++ text-based files.
  • The keyword VAR is used to declare a variable
  • The technique is fast but not without risks, especially version control, incorrectly formatted variables, or poor calculations

About this author

Aaron Dahlen, LCDR USCG (Ret.), serves as an application engineer at DigiKey. He has a unique electronics and automation foundation built over a 27-year military career as a technician and engineer which was further enhanced by 12 years of teaching (interwoven). With an MSEE degree from Minnesota State University, Mankato, Dahlen has taught in an ABET-accredited EE program, served as the program coordinator for an EET program, and taught component-level repair to military electronics technicians. Dahlen has returned to his Northern Minnesota home and thoroughly enjoys researching and writing articles such as this.