TiaPortal DB.DBW Indirect Addressing

GiusiB

Member
Join Date
Aug 2022
Location
Vicenza
Posts
3
Hi All,

which the best way to do the indirect addressing in an optimize DB?

Ccurrently this is my partial code inside an FB:

#StartMotorCommand.%X0 := #MotorsDelay[0].Q;
#StartMotorCommand.%X1 := #MotorsDelay[1].Q;
#StartMotorCommand.%X2 := #MotorsDelay[2].Q;

........ and so on till

#StartMotorCommand.%X31 := #MotorsDelay[31].Q

All data are declared as static inside the FB........

Now I'm looking to reduce this part of code by means a loop like this:

FOR i:= 0 TO 31 DO:
#StartMotorCommand.%X:=#MotorsDelay.Q;
END_FOR;

Obviously the syntax .%X is unacceptable.
What could be the solution to do this?

Is necessary use the PEEK/POKE instructions or there are other way
to avoid making 32 moves?

Thanks in advance for your reply and tips
 
Sometimes it happens to me to look for the most complicated solutions when you have the simplest and most practical solution under your eyes.

I'll do what you just suggested.

Thanks
 
My preference goes to structures.



dutMotors:


Control :
On
Off


Config:
IsEnabled
IsOnDelayed
IsWhatever


Status
IsFaulted
IsRunning
IsOFF

Etc.


And you would address it accordingly:
myMotors : Array [1..100] of udtMotors
myMotors[1].Control.On := TRUE;


Or better yet, create meaningful names as constants:


INPUT_CONVEYOR_MOTOR
EJECTION_MOTOR


myMotors[EJECTION_MOTOR].Contorl.On := TRUE;


And of course a loop is a loop and you can index the array the same way.
 
My preference goes to structures.



dutMotors:


Control :
On
Off


Config:
IsEnabled
IsOnDelayed
IsWhatever


Status
IsFaulted
IsRunning
IsOFF

Etc.


And you would address it accordingly:
myMotors : Array [1..100] of udtMotors
myMotors[1].Control.On := TRUE;


Or better yet, create meaningful names as constants:


INPUT_CONVEYOR_MOTOR
EJECTION_MOTOR


myMotors[EJECTION_MOTOR].Contorl.On := TRUE;


And of course a loop is a loop and you can index the array the same way.

I'll take it in consideration for future uses
 
i am guessing you have many motor starters, and you have decided to make a program block that loops through them all, rather than calling an FB many times.
How do you assign the IO to this code ?

The way I make a program for many similar objects (such as a standard motor starter), is to create a standard FB for 1 object, then call this FB many times with an instance-DB per object. Each time an FB is called, the IO for the object gets assigned to the FB instance.
I don't see any other 'clever' way to do it.
I would not loop through the DBs/IDBs despite it would theoretically be possible to make arrays of FBs. The problem is how to pass the IO in and out of the FB ?
 
i am guessing you have many motor starters, and you have decided to make a program block that loops through them all, rather than calling an FB many times.
How do you assign the IO to this code ?

The way I make a program for many similar objects (such as a standard motor starter), is to create a standard FB for 1 object, then call this FB many times with an instance-DB per object. Each time an FB is called, the IO for the object gets assigned to the FB instance.
I don't see any other 'clever' way to do it.
I would not loop through the DBs/IDBs despite it would theoretically be possible to make arrays of FBs. The problem is how to pass the IO in and out of the FB ?


+1


I like this approach best not just for assigning IOs but it makes it so much easier to reuse; all I have to know is what services the block provides and how to use the interface (Inputs, Outputs, etc.).


Edit: And structures (UDT) work well with this approach too.
 

Similar Topics

Does anyone know if there's a technical reason why Siemens HMIs can't have the program uploaded from them into TIAPortal as a project file, or is...
Replies
5
Views
794
I have a nice project in Visilogic that I have been asked to re-create in Tiaportal/Siemens. (Bosses / maintenance want to standardise on one...
Replies
2
Views
1,313
Hello everyone, I dont know if this is a common error or if im wrong but whenever i create a screen i am allways afraid of my life with this...
Replies
4
Views
2,056
Hello everyone, I am currently trying to build a HMI(KTP400 basic) for myself. I have some UDT data and use these UDT data for 20~...
Replies
7
Views
1,259
Hello, I am currently trying to control a motor in my plc. I've made a simple on/off button logic. And it works pretty well, when i press the...
Replies
25
Views
6,028
Back
Top Bottom