Siemens#Let’s use DB_ANY

This time I will discuss DB_ANY.

This concept may be a little bit strange, but I will try my best to explain it.Let’s start!

Firstly while we see the F1 Help in DB_ANY,  TIA will explain like this:

Identification (name or number) of a DB,
The data type “DB_ANY” has the length 0 in the section “Temp”

In my view, it seems DB_ANY can save the DB “Numbers” and its Attributes.  S7-1500 has 3 types of DB – Global ,Instance and ArrayDB, also with Attributes of Optimized block access or not.

Here is the place to set-up optimized block access or not.

Let’s make some simple programs. We created a Global DB with DB_Anys Array.

And then Create one more Global DB with DB Number “1”.

But.. If I try to directly move the myDB to the DB_ANYs DB, TIA does not allow me.

It seems that Global access to data blocks with memory reserve is not permitted here.

Open the properties of myDB1 and switch to the tab “Download without reinitialization.”.

you can see Memory reserve is set with a default value of 100 bytes.

Let’s set this value to 0.

The Error is gone :).

After downloading the project, you can see DB_ANYs.DB_ANYs[0] has a value of “1”.

This “1” is the number of myDB1.


So, what is the next-step?

Firstly I will use this Function – can use this function to get the properties of DB.

  • REQ:Bool,Execute while True
  • DB_NUMBER:DB_ANY,UINT, The properties of DB that you would like to get.
  • RET_VAL:The result of this function.
  • DB_LENGTH:DB length(Count by Bytes), Result is 0 while that DB is in optimized access mode.
  • ATRIB:DB properties.
    • Bit0:1=Load Memory
    • Bit1:1=Write-protecteDB
    • Bit2:1=At least a variables is retained.
    • Bit3:1=Both loaded into Load Memory and Work Memory.

And this is the result.

Using with Technology Object

In this chapter, I will discuss how to use DB_ANY with Technology Object.

Hardware Configuration

this Project, I will try to connect the PLC to a S120(with 2 axes) and G120, then control these drives by Technology Object.

Create 3 Technology Objects.



Create A Global DB that is named “DB_AXIS” with an Array of DB_ANY.


OB100 is a startup OB while the CPU switches from Stop to Run.

While OB100 is executed, Assign the Technology Objects DB to DB_AXIS.myAxis[..].


Create some program with a positioning axis.

The main point is – in the InOut interface of your FB, using TO_PositioningAxis as your parameters.

After that , use PLC_OPEN MC Blocks to implement your control.


Same as FB_Drive_PositionAxis, but change the type of Axis to TO_SpeedAxis.


Finally, I will explain this Function – EQ_TypeOfDB.

It will compare with IN1 and IN2 , if these 2 DB are in the same type, Out=True.


using EQ_TypeOfDB to check if the DB_ANY type is TO_PositioningAxis or not.

If yes, pass this DB_ANY into my FB_Drive_PositionAxis Block.

Same as the FB_Drive_SpeedAxis.


  • このエントリーをはてなブックマークに追加