Array and UDT aliasing

JeffKiper

Lifetime Supporting Member + Moderator
Join Date
Jun 2006
Location
Indiana
Posts
2,460
Is there a way to make 1 bit in a BOOL array an alias? I have not had any luck doing this yet.
I have several UDT that I would like to be able to make 1 element of it an alias of a Local:1:I.Data.0. I am using a MOVe to make this happen but I would like a clean way to make this happen.
 
You cannot make aliases to UDTs. The reasons are somewhat complex, but to oversimplify it, its because the UDT doesn't really exist. Its a programming tool to arrange memory for the programmer, not an actual place in memory.

If you are familiar with C programming, the UDT is similar to a structure (struct). It is something that tells the compiler how to handle memory, but it in and of itself doesn't allocate any memory.

An alias also doesn't really exist as a memory location. Its just a nickname defined for another spot in memory, but that spot has to already be allocated to a tag of a defined data type.

Since a UDT doesn't allocate memory itself, there isn't a spot for the alias, which also doesn't allocate any memory, to point to. Resolving the definition at run time would add massive overhead to the PLC.

See technote 29568 for a more detailed description on why.
 
No Jeff, you have the wrong handle on what an alias is.

An alias is a tag, just like any other in the database, which acts as a redirector to where the data is stored. The alias tag is not a container for data.

Take this as an example :-

You have a Start pushbutton for a machine wired to an input at say Local:4:I.Data.5

You could use that addressing in your code without problem, only it makes the code harder to understand.

You can create another tag, called say Start_PB that is an alias to the physical input address Local:4:I.Data.5

When you use Start_PB in your code, the alias information is displayed beneath the Start_PB tag.
 
OK, that tech note confused me. Maybe it was translated or written in a hurry with poor grammer or I may just being thick today. But the reasons given didn't seem to make much sense.

A UDT is a definition. But so is 'DINT' or 'SINT' or 'BOOL'. None of these have a memory assignment until a tag is created and defined with this data type. At that point the tag is assigned a fixed location in memory. Since the Logix platform doesn't dynamically alocate memory for base tags (or does it), the start of a UDT must have a fixed location in memory. Which, by implication, means every element after that must have a fixed offset from that starting location and thus a fixed, known location in memory. We know this is true or COP of a tag defined by a UDT wouldn't work right. This is also why online modification of a UDT is such a PITA for Rockwell and doesn't exist (yet). So given that I don't see how it is any different than a DINT or REAL in terms of memory definition.

Keith
 
Keith, don't confuse the tag with the UDT. The UDT is just the definition.

For example, I can define a UDT named FlowMeter. lets say its 20 words long. Then I can allocate a tag, FM1 of type FlowMeter. A memory location of 20 contiguous words has now been allocated. I can create a alias for FM1, lets say its named Product_1_Flow. The name Product_1_Flow now points to the tag FM1, and Product_1_Flow.Rate names the exact same memory location as FM1.Rate.

What I cannot do however, is include an Alias inside the definition of the FLowMeter UDT. Thats because the UDT definition doesn't have a memory location, it only defines memory organization, so the compiler has absolutely no idea where to make that alias point, and the alias itself isn't a piece of data.
 
I understand that a UDT is just a definition. But, effectively, so is a DINT, which is just as sequence of 4 bytes. The compiler assigns a memory start address + four bytes to the tag typed as a DINT, just like the compiler assigns a memory start address + x bytes to a tag typed as a specific UDT.

So, as you say below:

Originally posted by Alaric:

I can create a alias for FM1, lets say its named Product_1_Flow. The name Product_1_Flow now points to the tag FM1, and Product_1_Flow.Rate names the exact same memory location as FM1.Rate.

So we agree that FM1 has a known, physical start memory location and size, just like a DINT would. However, because of the UDT definition the compiler also knows that FM1.Rate is a REAL starting 16 bytes after the start address of FM1 (REAL and 16 bytes are arbitrary values used for illustration). FM1.Rate occupies a fixed, known memory address. The compiler knows how to find it. Why can't it be aliased to, since the memory definitions are determined at compile time. It's not like the development system can't determine the data type needed for the alias; it's part of the UDT definition.

I guess I am making the distinction between "can't" and "don't". I think this is more of a case of "don't" than "can't". Just like it isn't possible to change a UDT online,...until V18 comes out.

Keith
 
So we agree that FM1 has a known, physical start memory location and size, just like a DINT would. However, because of the UDT definition the compiler also knows that FM1.Rate is a REAL starting 16 bytes after the start address of FM1 (REAL and 16 bytes are arbitrary values used for illustration). FM1.Rate occupies a fixed, known memory address. The compiler knows how to find it. Why can't it be aliased to, since the memory definitions are determined at compile time. It's not like the development system can't determine the data type needed for the alias; it's part of the UDT definition.

It can be aliased to. FM1.Rate is aliased by Product_1_Flow.Rate. Even the element .Rate inside of FM1 can be aliased. I could open up the tag editor, click on FM1, expand it, right click on FM1.Rate, and create an Alias named SyrupGPM that points directly to FM1.Rate. Now FM1.Rate, Product_1_Flow.Rate, and SyrupGPM all name the exact same location in memory.

What I cannot do is embed an Alias inside of the UDT definition.
I cannot define the UDT Flow Meter to contain
Status - DINT
Rate - Real
Alarms - DINT
Input - Alias
where I'm trying to make the element .Input an alias to something that is outside of the UDT, and then have the outside data just show up in my tag by magic.



Look at it this way.

A developer wants to build a tract of spec homes. Each home will have the same floor plan. So he has an architect draw up a plan. The plan specifies a living room, a kitchen, two bedrooms, and a bathroom. The house plan compares to a UDT.

Once the developer has the plans, he secures funds and now goes out and finds a piece of property to build the tract homes on. He finds a stretch of empty land, and build a street called Maple street. Then the developer builds a house at address #1 Maple Street. This is like creating a tag. Now not only is there a house at #1 Maple Street, there is a living room, a kitchen, two bedrooms, and a bathroom. Along comes Bob and buys the house. Now we can call the house Bob's house. This is like an alias. Bob's house has Bob's living room, Bob's kitchen, Bob's bedrooms, and Bob's bathroom. Bob's kitchen is the exact same kitchen as the one at #1 Maple Street. It is not a different kitchen that magically mirrors the kitchen at #1 maple street, it is the same kitchen, we just call it Bob's kitchen because it's a more meaningful name. Meanwhile, Bob and Bob's closes buddies call it the "mess hall" and they all know where it is and they all know that its Bob's, but don't bother to refer to it as Bob's (Kinda like the SyrupGPM alias mentioned above)

But back when the architect drew up the plan, he had absolutely no idea where the house would be built, and he had no idea that it would one day be Bob's house. So he couldn't write Bob's kitchen on the plan, and he couldn't write Bob's bathroom on the plan. So the Alias doesn't exist on the house plan.

Lets carry it one step farther. The builder also builds the same plan house at #2 Maple Street (a tag is defined). Then Jim buys the house (Alias). Now there are two houses that follow the plan (UDT). So while there is a place called #1 Maple Street's kitchen, also known as Bob's kitchen, there is also a place called #2 Maple Street's kitchen, also known as Jim's kitchen. But the plan itself only tell us what the kitchen is, not where it is.

Now in the PLC it gets even more complex, if it were possible to put an alias in the UDT, then the Alias points to a piece of memory that is outside of the UDT. So back to our house plan. lets say we want one of the bedrooms doors to lead to a bedroom in a different city. Now that doesn't make sense at all. But if by some trick of magic, it were possible, how exactly is the architect supposed to know what bedroom in what city so he can write it on the plan, especially since the house hasn't even been built yet, nor does he even know where the house is going to be, much less the magic bedroom. He also doesn't know if the magic bedroom is a tiny 80 sq ft windowless room with a dim light bulb dangling from a cord, or if its a 800 sq. ft. suite with a crystal chandellier, so how does he show it on the plan (what data type is the alias when an alias doesn't even have an inherent data type)?

Now AB could create instructions to fetch the exact memory address of a tag at run time and a data type that could store that memory address in the UDT, and then resolve its data type and location every time it was referenced, but that carries a lot more overhead than just MOVing or COPying the data to the UDT, and you would still have to write code to make it happen, so it doesn't save you anything at all. So it is possible that they could allow it, it just doesn't make any sense to do it.
 
Last edited:
OK, I see what you are saying now. I've never aliased into a structure before because I haven't needed to. I thought you were saying you couldn't use a specific structure element as the base for an alias.

What JeffKiper is talking about isn't aliasing at all. It is kind of like the processor-internal version of produced and consumed tags. He wants to equate two different fixed memory locations automatically and be able to refer to them by either definition. I can understand why he would want to do that. For example, "everything" needs an e-stop status. It would be nice to be able to define that input as part of the UDT and just have it appear in every instance. But the processor would need to do behind the scenes what you mow do explicitly in the program. It would need to copy the values in and out to the appropriate memory location when the UDT defined tag is used. And in any case, you know what it is already. Just use the tag itself.

As was said there is no clean way of doing this at the compiler level. The memory can't be overlapped in such a way that multiple UDTs and individual elements use the same memory location. I suppose the compiler could abstract the user from the minutia of equating the two by burying moves in the compiled code when the elements are used. But at that point, which do you choose as the correct value? Better to do it yourself.

Keith
 
Oldish Thread (?) but sorta relevant - ALIAS's

I am in the middle of modifying a site's hardware config, and am using Prod/Cons between the different processors.

What I was wandering, about what is the best practice, and what is achievable.

Based on what I have read here, an element in a UDT cannot alias another element in a UDT. But, a single tag, can be aliased into any element in any UDT?

What I have done, is setup a Produced 'Faults' DINT. I am 'mapping' each of the required faults into this Faults array, and then aliasing the Faults array (that is consumed) via single BOOL tags.

I was wandering if this is extra code, but as most of the required Produced items are UDT elements, then it is necessary & to a certain extent, easier to follow, as in the Producer, all produced items are grouped together, and in the Consumer, the tags match their originator (almost anyway. ie Valve.FLT = Valve_FLT)
 
lostcontrol,

The cleanest approach to what you are doing is to make all your "faults", and anything else you want to share with other PLCs, into one tag, created as a UDT. Yes you may have some mapping to do from your (eg Valve UDT) fault status's into your inter-PLC UDT statuses, but not a big deal.

Compact as much Produced/Consumed data into User-Defined Tags, each Produced/Consumed tag utilises "connection" resources, which is limited.

Packing network data into UDTs, also makes best use of bandwidth.

Organise your UDT structures to fill as far as possible 500 bytes of data, which is the upper limit for a produced/consumed tag.

When configuring the Consumer tag, "horses for courses" rule applies to the RPI (data-refresh rate). In other words, don't consume a tag every 5mS if the data doesn't change rapidly.

When creating your UDT, keep in mind memory allocation. Either put the smallest data-types first (BOOLS), and largest last, or the other way round, each method optimises the storage capacity of your tag.

Your question
Based on what I have read here, an element in a UDT cannot alias another element in a UDT. But, a single tag, can be aliased into any element in any UDT?
is almost the answer to itself.

An element (member) of a UDT cannot be an alias for anything else.

Nor can an alias be included in a UDType definition, because the alias does not know the data-type of the target, it merely inherits it from the base tag.

A single tag, when configured as an alias tag, can be an alias for whole tags, or members of a tag structure, as you wish.
 
My 2¢ and an attempt to make it clear:

You cannot make a base tag or any part of a base tag an alias for anything else. A base tag is any tag you create as a specific type - whether DINT, Timer, or a custom type defined in a UDT. I/O tags automatically created, e.g. Local:4:I.Data.5, are also base tags.

An alias tag references all or part of a base tag.

Alaric and Keith tied themselves in knots over semantics.
 

Similar Topics

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
203
I received the following message via PM, and am posting here publicly to help others. ============================================ I had a...
Replies
10
Views
1,017
Hello, Wondering if the following setup would work. 1. Local PLC on the network has an array of 25 REALs 2. Supervisory PLC on the network needs...
Replies
14
Views
1,812
I have a task that could easily be solved using a 2-dimensional array using a ControlLogix processor, V32+. Basically it will loop through two...
Replies
23
Views
4,327
Hello Guys, I think I need to use SCL for the following task but am very weak using SCL in tia portal. I have results history data block. It is...
Replies
14
Views
3,041
Back
Top Bottom