Copy UDT data to tempory data

Werner

Member
Join Date
Apr 2005
Location
IJsselstein
Posts
336
I am sure this topic has been discussed before. But there are so much topics about pointers etc. that it's hard to find what I am looking for. So here is my question.

I have a DB in which if have an UDT. This UDT is 34 bytes long. In total I use the UDT 30 times in this DB.

I have an FC in which I need to perform an action where I need the data from the a UDT.

I have to call this FC several times.

Call FC 1 with input data from the first UDT
Call FC 1 with input data from the second UDT
Call FC 1 with input data from the ... UDT
Call FC 1 with input data from the last UDT

Inside the FC I created a tempory off the type UDT.

Note: all the time I am talking about the same UDT nr. (So the data is always the same)

As input to the FC I want an any pointer to the data that is used that call.

Now I need to find a way to use this any pointer to copy data from the DB to the temporary UDT inside the FC. How can I do this?

Why I want this:

1 - The any pointer is very readable at the call. (outside the FC)
2 - The temporary bits/bytes have nice readable names. (inside the FC)
 
How are you passing the data to the FC ? If you use the same UDT as the type for the input parameter then you can use the same nice readable names. Post a small example of what you are doing (you can simply shorten the UDT for posting purposes).
 
This is a source file of what I am tring to do.

I now got it working by copying the data from the UDT one word/dword at a time. I use an any pointer to point to the data. If my DB changes the offset of the pointer automatically changes. So there is no absolute address in the FC.

I am looking for a faster/shorter way of doing this.

Is it possible to do a block move SFC20 from DB to temp variables?
 
How are the settings in the DB arrived at ? Is there a HMI device that will be used to change these values or are they set once during commissioning and then not adjusted ?

Which CPU are you running this code in ?
 
Last edited:
Answer - yes! And it will be much more simple and understandable to use BLKMOV. But you can use another simpler method too - defining IN_OUT variable of UDT type in your FC.
Copying to temporary variable have sense only if you call FC in DB loop scan with only 1 FC call placed in code part and when current UDT is selected by offset in that DB. In this case yes - you must to organize copying to temporary area. But if you want place FC call 30 times in your program (am I correct?), you don't need any pointers. You can use something like SettingsDB.Settings1. It's more readable than ANY.
 
If you are looking for a faster/shorter way, I wouldn't go down the UDT parameter route. I would re-organise the data into 30 data blocks and pass the data block in as the parameter and then access the data using L DBW 0 type instructions. OK you lose the nice names but this will be the fastest method. Accessing UDT parameters with an FC adds considerable code overhead.
 
L D[AR2 said:
How are the settings in the DB arrived at ? Is there a HMI device that will be used to change these values or are they set once during commissioning and then not adjusted ?

Which CPU are you running this code in ?

Yes, settings done via HMI. Normally set once during commisioning but can be changed if hardware is changed. (Different gearbox, different size rollers etc.)
I use the CPU 317F-2DP.
 
L D[AR2 said:
If you are looking for a faster/shorter way, I wouldn't go down the UDT parameter route. I would re-organise the data into 30 data blocks and pass the data block in as the parameter and then access the data using L DBW 0 type instructions.

This is not an option. Because I want all "settings" to be in one DB. Then it is easy to keep track of changes in settings. If I have settings in several DB's then I need to check all db's for changed settings.
 
Last edited:
Gambrinus,

UDT as in/out ok. But how do I get the data in the block? Can you give a small example. (Both from the calling block, as from inside the block)

I didn't know the block move could copy to temp variables. How do I do this?
 
Werner said:
This is not an option. Because I want all "settings" to be in one DB. Then it is easy to keep track of changes in settings. If I have settings in several DB's then I need to check all db's for changed settings.

What sort of "tracking" do you mean here ? Will the program be scanning the DB to check for a change or what ? You could always keep the settings in one DB and then copy them out to individual DB's. As you mentioned faster/shorter method, are you running into scan time/memory problems ?
 
Another option would be to "pass on" the pointer to the FB and retrieve the settings data using the pointer inside the FB.
 
L D[AR2 said:
What sort of "tracking" do you mean here ? Will the program be scanning the DB to check for a change or what ? You could always keep the settings in one DB and then copy them out to individual DB's. As you mentioned faster/shorter method, are you running into scan time/memory problems ?

I mean the customer changed settings. I come along with my "older" version of the db. The only thing I can see is that the actual values inside the DB are changed. If I have only 1 DB in which all my settings are included, then I only have to check this DB for changes. I can tell my service engineer, just check this one DB, all the others you can download without losing settings.
 
Why are you calling an FB from the FC - you could eliminate the need to pass on the variables if you did all the processing inside the FC itself. Note that as the FB is being called with the same instance DB for all 30 cases, STAT data will be of no use in this example.
 
L D[AR2 said:
Why are you calling an FB from the FC - you could eliminate the need to pass on the variables if you did all the processing inside the FC itself. Note that as the FB is being called with the same instance DB for all 30 cases, STAT data will be of no use in this example.

The FB is a "standard" block which I use. This time I need to do some conversions for this block to work. I do this on the outside of the FB. (Because I don't want to change the "standard" FB, of which I am 100% sure it works perfectly).

I need this block 4 times. (And also with 4 instance DB's). So I also use 4 different FC's to call the FB. The only thing I need to change in the FC's is the instance DB number of the block and the instance DB number of the FB1015 and the hardware address of the Lenze profibus inverter. (This address could also be an input of the FC).

I know it's not perfect but at least I can easaly duplicate the functionality I need with a low change of making mistakes. (For example forget to change one of the settings to the right DBW)

I use an FC because otherwise I get 4 more instance DB's which I really don't need.

Hope this makes sense to you guys?!
 
Werner, sorry, my PC have some bug now. You can solve your task in 3 ways:
1. Use FC working with TEMP. BLKMOV to copy data from DB to local data. You need to create source and destination pointers for BLKMOV.
2. Use IN_OUT variable. Simple set it's type as "UDT Height adjust settin" like you use WORD or BOOL.
3. The better way, IMHO. Change your FC to FB. FB2, for example. Define your tSettings in STAT section of this FB. You need to create another FB to call all FB2 from. In it's STAT section define variables with type FB2 and call it.
 

Similar Topics

Hello! I am completely new to PLCs, so I apologize in advance if this is a dumb question. I have a device that sends out its data as a number of...
Replies
5
Views
2,077
I have created a UDT (profile) it consists of 59 elements one of which is a string that contains the name of the profile that can be changed via...
Replies
2
Views
3,468
Hello Inside a FB, I´m trying to transfer a string from a DB to a IN_OUT var that was define as a UDT. The problem is that i can´t determine the...
Replies
4
Views
67
The PLC program I'm monitoring has a UDT of alarm booleans. 36 in total. What I'm trying to do is monitor a few rungs, and also monitor a possible...
Replies
3
Views
1,570
I have a separate program running for user security that i need to interface with existing security within my program. All of the external program...
Replies
1
Views
1,146
Back
Top Bottom