Step 7 - Pass DB to FC

cdavis

Member
Join Date
Jan 2009
Location
Athens, AL
Posts
14
I am very new to Siemens. Here is my problem. I want to create a function to control an AB drive (on profibus). I have written the functions to read/write data to the drive. The inputs and outputs to each drive are contained in a DB. In my function, I have declared an In/Out parameter of type UDT 20 (which is the UDT for the drive I/O). How do I pass a data block to this function?
 
DB Derived From UDT

Any suggestions on how to do this with a DB derived from a UDT? I have a UDT that is structured to work with a FM353 Stepper controller. Because of some built in functions I have to use a DB that is derived from this UDT. Each one of the FM353's requires it's own DB derived from the UDT. I am trying to write a function to read and write values in the DB, but I do not want to write a different function for every axis. I would prefer to write one function that has an IN_OUT of the UDT type and pass the DB of the axis I want into the function. When I try this it does not work. Any suggestions?

Thanks
 
Post a cut down version of your project that includes all relevant blocks. i.e. Create a library, copy the blocks to the library, archive and then attach to your post.
 
Here is a simplified version of what I am trying to do. In OB1 I want to call FC1 and pass it DB1. The compiler would not let me save it that way, so it is not shown that way in OB1. I included a screen shot of the what I am trying to do with FC1. The whole point here is write 1 FC and be able to call it multiple times and pass it the DB that I currently want to work with.

Thanks

OB1.jpg
 

Attachments

  • DB.zip
    43 KB · Views: 8
I havent looked into your project, but I am guessing you have just defined one structure in DB1, based on the UDT.
Rather than passing the whole DB1, pass just the structure, like "MyDB".MyData
 
1st, give DB1 a symbolic name, that is important.

You cannot make a "DB of type UDT1". edit: Guess I was wrong there :=o
You can make a STRUCT inside the DB that is a type UDT1.
What did you call the data when you added it as a UDT1 ? That is what is to be after the symbolic name of DB1 when you pass it to FC1.
If you give DB1 the symbolic name "MyDB", and the name of the UDT1 structure inside DB1 is called MyData, the you pass it to FC1 as "MyDB".MyData
 
Last edited:
Further to what Jesper said, You might want to change your program fro address priority to symbol priority. Right click on the blocks folder, select the addressing tab and tick the "symbol has prioity" button.

See attached.

FYI,

This way of doing things works OK but there is a performance penalty in that every access to the UDT inside your FC causes a re-creation of the pointers to the actual data. You can create a local copy of the UDT inside your block and pass data in and out but that can get more involved.

Nick
 
I have attached a screenshot that shows creating a DB of Type UDT. The functions that come from Siemens to control the FM353 use this DB type. I have found that I can create another DB that has the UDT data type in it, the way you suggested before. I can then BLKMOVE DB1 into that UDT area of the DB, pass that into the FC, then BLKMOVE that back into DB1. That however seems very clunky, and probably a memory hog.

DB_UDT.png
 
I never use "DB of Type".
Not sure what they are good for.

If you do as I suggest, I guarantee that it will work.
edit: And by that I mean do not do all that stuff with BLKMOVE etc. Just pass "MyDB".MyData or whatever you call it.
 
Last edited:
I dont doubt you. As I stated above, if I create another DB that has the UDT type inside it, as you did above, I can pass that to the FC. I just have to copy DB1 into "MyData1".MyData and then back again after the FC has run using BLKMOVE. This might be what I have to do and just deal with the waste of memory.

Thanks
 

Similar Topics

Hi all, I have an FB that I've created that uses a timer. At the moment I've just given it an address (T 71) but I'd like to be able to pass...
Replies
7
Views
2,956
I am having a step7 v5.4 program where the blocks are encrypted and locked. And the manufacturer is stopped the support. Is there any ways to...
Replies
2
Views
176
Good Morning, Hoping someone with some Siemens experience can give me a hand with this one. Customer has a S7-200 cpu, which has a 6GK7...
Replies
0
Views
248
HI! HOW COULD I OBTAIN THE NAMES OF THE STEPS OF A ROUTINE IN SFC LANGUAGE IN STUDIO5000? Or is there a system variable that gives me those...
Replies
0
Views
339
I'm just trying to figure out the right method of adding a DO card to an existing rack. It's not the *next* open slot, but I have to move the AO...
Replies
5
Views
547
Back
Top Bottom