6/29/2012 5:04 AM | |
Joined: 10/7/2005 Last visit: 4/18/2024 Posts: 3003 Rating: (1046)
|
Hello DLittlejohn412
You most definitely can assign a DB variable that references aUDT as a Parameter for an FC or FB (there is no need to make a local copy of it first as suggested by manmeet). The "trick" is that you must do so symbolically and of course have the UDT declared it as an IN, OUT or IN_OUT Parameter of the FC/FB. For example, your DB name ismy_DB and the variable name inside the DB that referenceslets say UDT1 is called data_1. You FC has an IN_OUT parameter that also references UDT1. You now type in "my_DB".data_1as the actual Parameter for the FC call (note that the DB name is surrounded by Quotation marks, followed by a dot, followed by the variable name). Attached is a pic which should help in making sense out of the above (it's a bit of a "silly" example where UDT's are referenced by other UDT'sand then used in a DB followed by usage as an FC IN-OUT Parameter and simply shows that anything is possible/allowed concerning this).
Just because the above is possibledoes notnecessarily mean it makes sense. Using UDT's can lead to a nicely structured program, but canalso lead to rather convuluted code that is hard to troubleshoot and/or maintain. This is a call you have to make and if you would ask 10 people about their UDT usage opinion, you'd probably get 12 different answers. One thing you should bear in mind though is that usage of UDT's (or other complex data types for that matter) asblock Parameters will lead to memory consumption and cycle time increase. Have a look atShall UDT make the difference in CPU Scan Time?thread for more on this. The FC in the attached example pic which contains very simple example logic and uses only three Elements from the UDT parameter, is already 202 Bytes in size. if you'd were to use all UDT Elements inside of it (which you'd normally more or less would), it will esaily grow into multiple kB size. This by itself is not the real problem (after all, the FC exists only once in the CPU memory). Let's say you end up with an FC that is 4 kB in size and you now callit 200 times in your program, your CPU will have to crunch through a total of 800 kBof logicevery scan (e.g. the cycle time impact can be considerable).
It'll certainly save from passing on the UDT as a Parameter, but you'll end up with indirect addressing as the result (it's horses for courses as say they and hard to say which is the best way to skin this cat). I hope this helps |
Cheers |
|
This contribution was helpful to2 thankful Users |
7/9/2012 10:40 AM | |
Joined: 1/3/2006 Last visit: 2/19/2024 Posts: 726 Rating: (71) |
Hi Fritz, The reason why i suggested the local copy of UDTwas DB is already opened using the statement OPN [#INDEX] and then you have have to supply only UDT of the DB. With respect to your attachment "my_DB" is already opened using indirect way, and then in the following FC you need to supply UDT of type "Main_UDT".How to do this without local copy? Sorry for very late reply !! |
Follow us on