S7 UDT question...

uptown47

Lifetime Supporting Member
Join Date
Feb 2008
Location
Over there, next to those boxes
Posts
1,146
Hi all,

I'm trying to teach myself UDT's and I've got myself a bit bogged down...

Can someone clear up the point of having UDT's for me please? I'm struggling to get my head around the concept.

I understand 'classes' in C and so I've a good idea of what a UDT is trying to achieve but I'm just struggling to 'join the dots' at the moment.

Here's where I'm up to...

I created a UDT 10 (Valve Commands) that contained 2 BOOLs. They were:
Open_Valve
Close_Valve

I created a UDT 11 (Valve State) that contained 2 BOOLs. They were:
Valve_Is_Open
Valve_Is_Closed

I created a UDT 1 (Valve) that contained 2 UDT's. They were:
UDT 10
UDT 11.

I then created a DB based on UDT 1.

So far, so good I thought....

I could see that UDT's would be very handy when creating a lot of valves as you could just create DB's and call them Valve 1, Valve 2, etc etc.

My problem came when I started trying to use them in the code...

Presumably, I have to 'map' real world inputs/outputs on to the DB addresses that I've used?

So something like this:

Code:
A I 0.0
= "Valve 1".Valve_Commands.Open_Valve

Is this how they are used??

I began to wonder whether there is any point to UDT's but suddenly thought that they would make the job of 'updating' all the instances of "Valve" much easier perhaps??

To test my theory I opened up UDT 11 (Valve State) and added an INT so UDT 11 now looked like:
Valve_Is_Open BOOL
Valve_Is_Closed BOOL
Valve_Position INT

All this did was give me some 'interface' errors in UDT 1 so I did a "Check and Update" accesses.

This cleared the 'interface' errors but now my DB 1 and DB 2 (i.e. Valve 1 and Valve 2) only show STAT0.STAT1 instead of "Valve_Commands.Open_Valve" as it used to be....

So, in short, I'm struggling to understand the practical advantages of using UDT's and also how to 'map' IO on to the UDT's values...

Any help would be very much appreciated.

Cheers

;-)
 
UDT's are good to structure and manage the data format.

When using UDT's I find it better to ensure that the program is set to 'Symbolic Programming' and after changing a used UDT to re-compile, this will bring your DB's back. A download would be necessary then, especially in the case you created where the Data area would be offset.

I wouldn't always map IO direct into this area, instead the inputs would be the conditioned bits, outputs I would normally update in an output block, maybe with bits from the DB.
 
UDT's are good to structure and manage the data format.

I wouldn't always map IO direct into this area, instead the inputs would be the conditioned bits, outputs I would normally update in an output block, maybe with bits from the DB.

Hi Peter,

Thanks for getting back to me. I can see how UDT's are great for managing the data format and keeping a structure to your data that is specific to a 'class'.

I'm still not too sure how to interact with a UDT in a real world example?

I'm struggling to see any advantage with a UDT over an FB utilising the Variable Declaration Table and passing in the values ??

I feel like I must be missing something here....

:)
 
I'm still not too sure how to interact with a UDT in a real world example?

I'm struggling to see any advantage with a UDT over an FB utilising the Variable Declaration Table and passing in the values ??

I feel like I must be missing something here....

:)

Make up a sample UDT, declare the UDT a couple times in a DB. Now build an FB/FC with the UDT as an input or output.

It is nice for blocks with a lot of I/O and the need for repetition - without it some can take quite awhile to type in all of the variables. It's nice to just use a pointer to the DB where you declared the UDT.

Couple screenies below.

I could have made the input side of the FC a UDT as well and just used two pointers...It does require you to keep track of things a bit more and it makes monitoring online kind of a PITA but it does have its uses

I like using them in conjunction with faceplates in WinCC Flex because I can declare my UDT as a structure and not have to manually type out all of the tags needed. Just declare the structure (identical to UDT layout) and then add tags for 1,2,3,etc with the structure name as the data type.

example.jpg example_2.jpg
 
I have been having a play about with your example and have re-created the 'valve' example that you have used.

Please excuse my ignorance but I'm still struggling to see the point of UDT's.

In your example, you pass in the IO into an FC and then you have a UDT as an output (P#DB1.DBX0.0).

However, those DB bit addresses would still need to be mapped to 'real world' outputs (assuming you wanted them to go to outputs).

So why not just pass the outputs of the FC directly into real world outputs and have different FC's to represent different valves ?

I suppose I'm asking... what does a UDT give you that you can't do with FCs or FBs using the Variable Declaration Table ?

Many thanks for everyones patience while I get my head around this.

;-)
 
Use them when there is often needed data structure, if you need some structure just once, there is no big benefit for using udt.

For example you have conveyor system that moves "containers" container can have more than one type of items in it (for simplicity only one type at the time) and different amount of items in one container.

Now you need maybe for sorting or some else function which amount and type of items container has.

Think now, which one is easier to maintain and pass on and use in programming one UDT or same structure copypasted in many places?
 
TU,
Thanks for the explaination. I think I understand what you are trying to say.

UDT's are good for tracking many objects that have more than one variable associated with them.

Will continue my experimentation into them until the penny fully drops!

Many thanks

;-)
 
Thats one, now try think what are the pros in using them in that one usage case. Then try find other places where same kind of pros are achieved.

I would not use udt with valve block. FB is for that. I would relate FB to Class in C not UDT. UDT has no function, it just describes some data like int or bool etc. just more complex data. FB has function in it.
 
One other advantage of UDTs is that if you upload a DB from a running system and it has timestamp differences with the offline version, you retain your UDT naming instead of finishing up with the dreaded "STRUCT_1", "STRUCT_2", etc.
 
I would relate FB to Class in C not UDT.

I think that's where I went wrong initially. I had read that a UDT was like a class but, as you say, it doesn't have the code to go with it and that's what threw me.

One other advantage of UDTs is that if you upload a DB from a running system and it has timestamp differences with the offline version, you retain your UDT naming instead of finishing up with the dreaded "STRUCT_1", "STRUCT_2", etc.

I didn't realise that. Although yesterday when I was experimenting I managed to lose all my naming by adding another variable to a UDT. The DB's I had created using that UDT all lost their naming...

Thanks for all the continued help.

;-)
 
One important advice.
Using UDTs means that you are probably organising your programs with symbolic naming. In that case be sure to have symbolic address priority selected.

I created a UDT 10 (Valve Commands) that contained 2 BOOLs. They were:
Open_Valve
Close_Valve

I created a UDT 11 (Valve State) that contained 2 BOOLs. They were:
Valve_Is_Open
Valve_Is_Closed

I created a UDT 1 (Valve) that contained 2 UDT's. They were:
UDT 10
UDT 11.
This sounds as if you are still thinking in absolute adresses.
You should start to think like this:
I created a UDT "Valve_commands" (UDT10) that contained 2 BOOLs. They were:
Open_Valve
Close_Valve

I created a UDT "Valve_state" (UDT11) that contained 2 BOOLs. They were:
Valve_Is_Open
Valve_Is_Closed

I created a UDT "Valve" (UDT1) that contained 2 UDT's. They were:
"Valve_commands"
"valve_state".
 
Here's a simple example of UDT usage. Unfortunately, UDT's give you the flexibility to structure your program any way you like.
 
One important advice....

Thanks Jesper, duly noted. ;-))

Here's a simple example of UDT usage. Unfortunately, UDT's give you the flexibility to structure your program any way you like.

Hi LD,

Many thanks for the example you posted. I've had a look through it and, in the interests of trying to learn more about it, I have a few questions. (to me, it was by no means a "simple" example :rolleyes: but extremely useful none-the-less).

Some of these may be stupid questions but please be patient :)

You have declared the 'Zones' in DB1 as an 'array'. Why have you used an array as oppose to just listing them as UDT's in the DB?

In FB2 you have declared STATs of the type 'FB 1' (I didn't even know you could declare Function Blocks as a data type!). You have some blocks in the code which I thought initially were 'calls' but if I drag a call_FB block in it's different. What are those blocks?

In FB2 all the blocks are referring to #fbZone1 and the other zones (2-10 inc) aren't referenced. Is this just a typo or is there a reason for this?

Why do you have the FB 1's as STAT's in FB 2. Is this something to do with preserving their data so they don't lose it everytime FB 2 is called ??

I've been playing around with UDT's all morning and have been experimenting with my own example. I created a UDT with 3 BOOL's called "Milkshake Flavour". The 3 BOOLs are Chocolate, Strawberry, Vanilla.

I then created another UDT called "Main Course" and had 3 BOOLs of Beef_Pie, Lasagne, Pizza.

I then created another UDT and it contained the 2 UDT's inside it.

I then created a DB and put in 3 of these UDT's called BobsMeal, JimsMeal, JohnsMeal.

I have then written just a bit of code and I'm messing around with how UDT's are used, addressed etc etc...

If you have any other UDT examples I'd be very interested to look at them.

Many thanks for all your help so far...

;-)
 
Thanks Jesper, duly noted. ;-))



Hi LD,

Many thanks for the example you posted. I've had a look through it and, in the interests of trying to learn more about it, I have a few questions. (to me, it was by no means a "simple" example :rolleyes: but extremely useful none-the-less).

Some of these may be stupid questions but please be patient :)

You have declared the 'Zones' in DB1 as an 'array'. Why have you used an array as oppose to just listing them as UDT's in the DB?

Think about having 2000 zones, who wants to copypaste that, not me. Why not use array?

In FB2 you have declared STATs of the type 'FB 1' (I didn't even know you could declare Function Blocks as a data type!). You have some blocks in the code which I thought initially were 'calls' but if I drag a call_FB block in it's different. What are those blocks?

Multi-instance calls.

In FB2 all the blocks are referring to #fbZone1 and the other zones (2-10 inc) aren't referenced. Is this just a typo or is there a reason for this?

I think its typo (there seems to be "catch" in it tough it does look like it would work like that too but then fbZone2-10 would not be needed).

Why do you have the FB 1's as STAT's in FB 2. Is this something to do with preserving their data so they don't lose it everytime FB 2 is called ??

Multi-instance.

I've been playing around with UDT's all morning and have been experimenting with my own example. I created a UDT with 3 BOOL's called "Milkshake Flavour". The 3 BOOLs are Chocolate, Strawberry, Vanilla.

I then created another UDT called "Main Course" and had 3 BOOLs of Beef_Pie, Lasagne, Pizza.

I then created another UDT and it contained the 2 UDT's inside it.

I then created a DB and put in 3 of these UDT's called BobsMeal, JimsMeal, JohnsMeal.

I have then written just a bit of code and I'm messing around with how UDT's are used, addressed etc etc...

If you have any other UDT examples I'd be very interested to look at them.

Many thanks for all your help so far...

;-)
 

Similar Topics

Hi All, I'm fairly new to Proficy and perhaps the problem is that I'm trying to get it to do some of the same things I'm used to doing with...
Replies
2
Views
3,186
Anyone how knows how many levels deep UDT'a may used. DB1 contains UDT1 UDT contains UDT2 and so on. Same question for Structures. And to make...
Replies
2
Views
1,837
I'm not sure if you guys still remember this project template, I'm reading it. If you can't remember, it's here (Thanks RMA). Q1: I noticed in...
Replies
14
Views
4,252
Afternoon all, I'm working on setting up a large excel recipe table for porting updates through the Linx Gateway RTD/DDE function into my recipe...
Replies
2
Views
87
I am trying to copy an array of real numbers into a UDT with a real data type element. I have attached a snip below showing my COP instruction...
Replies
4
Views
194
Back
Top Bottom