RSLogix5000: MOV UDT to element of another UDT - error

ryangriggs

Lifetime Supporting Member
Join Date
Jun 2016
Location
USA
Posts
198
Hello, I'm trying to copy the entire value of a UDT base tag to an element of an array of another UDT containing an element of the first UDT:





MyFirstUDT:
- SomeElement(DINT)
- AnotherElement(REAL)




MySecondUDT:
- AnElement(DINT)
- AnElement2(BOOL)
- ...
- DATA(MyFirstUDT)




Tags:
TemporaryTag (MyFirstUDT)
ArrayOfElements[10] (MySecondUDT)




I want to copy the entire UDT from "TemporaryTag" to "ArrayOfElements[0].DATA", so I am doing this:




---[true]-------| MOV |---
| Source: TemporaryTag |
| Dest: ArrayOfElements[0].DATA |






However, RSLogix5000 throws the following two errors on verifying the rung:


Error: Rung 1, MOV, Operand 0: Invalid data type. Argument must match parameter data type.
Error: Rung 1, MOV, Operand 1: Invalid data type. Argument must match parameter data type.




Why can't I MOV the UDT tag's values into the element of the destination tag? And how would this be accomplished, other than MOVing each member of the DATA element individually (there are about 50 members of this UDT).





Thanks for any insight.
 
Last edited:
MOV does not work with UDTs. Use a COP (or CPS) with length 1.


OK that's great to know. I was wondering if COP would work, but I wasn't sure of the length to input (was assuming it was the length of the UDT itself).



So to confirm, the length == number of UDT records to copy.


Thanks!!!
 
'Length' is the number of [elements] that are going to be copied, where [element] is the type of the destination.

Going by your example, the destination is 'ArrayOfElements[0].DATA' which is of type 'MyFirstUDT'. Since you want to copy a single 'MyFirstUDT' tag, the length will be 1.



The most common cause for non-1 lengths is dealing with arrays. Another common reason is needing to access parts of a tag -- for example if you are pulling data from another device that uses INTs but the data is packed as DINTs as it comes in. You can do a COP from the DINTs to an array of INT with a length of 2 to split the lower and upper words and extract the original INT data.

Whenever you have a length >1 (or COP with dissimilar types) it's important to understand that the processor will not actually look at the data it is copying -- it will copy a number of bytes equal to the size of the destination type * the length, starting at the beginning of the source. If the source is smaller than the destination, the processor will just keep copying from whatever comes after that in memory when it reaches the end of the source (effectively junk data). If the source is larger than the destination then once the end of the destination has been reached any further data from the source is discarded.
 
Correct me if I'm wrong, but a length > 1 is used for copying STRINGs too, right? When I've done this in the past, I would COP the string and set the length to [SourceString].LEN.
 
Correct me if I'm wrong, but a length > 1 is used for copying STRINGs too, right? When I've done this in the past, I would COP the string and set the length to [SourceString].LEN.

If you address the string itself (eg COP sourceString destinationString), a length of 1 should work. If you go deeper and address the actual data directly (eg COP sourceString.data[0] destinationString.data[0]) then you would indeed need to set the length to at least the actual length used.

As a side note, recent revisions of Logix allow MOV with strings :)
 
Last edited:
As a side note, recent revisions of Logix allow MOV with strings :)

Small clarification: recent revisions of Logix on certain versions of hardware support MOV with strings. 5380 Compact Logix and 5580 Control/GuardLogix will do it; 5730 CompactLogix and 5570 Compact/GuardLogix and earlier will not.
 

Similar Topics

Hi Guys, Is there an instruction in RSLogix5000 that I can easily move a value into a member of a UDT? I.e on first scan move 0 into...
Replies
4
Views
3,152
Hello every one.. How can I mov analoge data come from 1756-IF16..in RSLogix5000??? I used mov instruction source (Local:8:i.ch0data)and dest...
Replies
4
Views
4,796
Hi! So my problem is a little funky, I had Studio 5000 v 24 and 30 installed, but forgot to install RSLogix (which I cannot go without). Is there...
Replies
2
Views
123
So I had an odd request from a customer for the above. I have written the logic and tested it all in one PLC with only using 7 outputs and 7...
Replies
15
Views
428
Hello everyone, I have an RSLogix5000 project which is running live in the factory but I need to make some changes to the logic. I want to test...
Replies
0
Views
1,124
Back
Top Bottom