Cop from UDT array to different array possible in ST?

TheWaterboy

Lifetime Supporting Member + Moderator
Join Date
May 2006
Location
-27.9679796,153.419016
Posts
1,924
I need to compare an array[128] of bools over time. I intended to just copy the array to a local array and compare them a bit later.

The problem I seem to be facing is that the source array is part of a UDT and the COP command in ST treats it as a different datatype from the local one, which I guess it is, but the array element itself is identical and I didn't expect that.
the line in ST is:
Code:
COP (UDT_TagName.BoolArray[0],ComparePrevious[0],127);
I prefer to keep this in ST for organizational reasons but other than a loop, how can I copy like this?
 
Well, you could create another UDT that is just your Bool Array (UDT_BoolArray). Then make UDT_TagName.BoolArray (which is UDT_BoolArray, not an array of atomic bools).
then your local tag would be LocalBoolArray (type UDT_BoolArray).

then its just a COP(UDT_Tagname.BoolArray, LocalBoolArray,1)
 
Well, you could create another UDT that is just your Bool Array (UDT_BoolArray). Then make UDT_TagName.BoolArray (which is UDT_BoolArray, not an array of atomic bools).
then your local tag would be LocalBoolArray (type UDT_BoolArray).

then its just a COP(UDT_Tagname.BoolArray, LocalBoolArray,1)

I can't create a UDT without member names. so any UDT becomes TagName.Member. But I created one and its still giving me an invalid data type error. on both arguments.
Code:
COP (UDT_TagName.BoolArray,ComparePrevious.Bits,1);
COP (UDT_TagName.BoolArray,ComparePrevious,1);
COP (UDT_TagName.BoolArray[0],ComparePrevious[0],127);

They are of 2 different scopes, one controller and one local but I can't imagine that would be a problem.
 
i'm attaching what I have. I have no errors. I'm not sure what your tag structure actually is, but you're trying to copy an individual element to a UDT struct. It has to be UDT to UDT.

maybe these screenshots will clear it up, or PM me your code.

Capture.JPG Capture2.JPG Capture3.JPG Capture4.JPG Capture5.JPG
 
The only way I could make it work was to make a UDT Called Bool_Array. Which has 1 member named BOOL and a data type that was BOOL[128]

Then make a UDT with Bool_Array as a Data type member.
 
Complete UDT to another complete UDT I can make work.
In my case the first UDT has REALS, DINTS, BOOLS. And All I want to copy is the BOOLS.

But COP a member array from a UDT into anything doesn't work. COP wont work on members of a UDT. Just entire UDTs. At least that's what I'm finding out.

To move forward that's just what I did is to copy the entire thing and then scan the parts I want for changes. It works, just bigger than I was trying for.
 
BOOL is not one of the allowed data types for a COP, although a structure (UDT) is. So if you bury your BOOLs into a structure you could copy the BOOLs as part of the structure.

A COP will allow you to copy starting at an element inside of a UDT. However, if you burrow into the UDT far enough to expose the BOOLs and try to copy from that point you are back to copying BOOLs, which isn't allowed.

Given what a BOOL is, don't ask me why it can't be copied. I don't make the rules; I just follow 'em.

Keith
 

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
200
Hello, I have been looking for a reference for the order that a UDT is copied in the COP instruction. More specifically - I have a set of code...
Replies
5
Views
544
I have used RSLogix5000 in the past to make small code changes but now I need to go deeper. I have a 1794-IE8 over DeviceNet that has all been...
Replies
4
Views
2,361
Hello all. I have a Danfoss VLT feeding an INT into my CpLX program. I need to concatenate the MSB and LSB for position. I used a COP, making sure...
Replies
10
Views
637
I'm having to make an AOI to use with a generic ethernet device because the manufacturer does not provide an AOP. I just want to do a sanity check...
Replies
13
Views
1,256
Back
Top Bottom