initialize (or erase the data in) User-defined data types - RSLogix 5000

ViperDaSnake

Member
Join Date
Mar 2010
Location
Texas
Posts
45
Is there a command that you can use against a UDT that will fill it with zeros? Of course the UDT has dint, bool and strings...

EX: FLL UDT_test_one 99999
 
Just make another tag withe the same data type (UDT). It will be created with zero in every element. Then use that to copy over the tag you want "zeroed" out.
 
Sure - make another tag of the same UDT, don't ever populate it with any data.

Then use COP to copy the blank tag to the one you want to erase
 
Yeah right, it cant be that simple..... O wait it is...!!!!

I must of tried to fill, copy.... a hundred ways, it was looking pretty scary...

Thanks.
 
The method suggested by the instruction help is what I use. Create a single instance tag and zero everything in it. Then use COP to copy that zeroed tag into any others of the same type.
 
Nulling out an array of UDT's

Sorry to resurrect this post from the dead, but I was trying to do something similar to what is said here with an array of UDT's using a COP command, and it faulted out my controller by putting a lot of garbage in the array.

Based on search of Rockwell site, that might be expected behavior since COP does 32 bit chunks and my UDT has strings and bools in it so it sounds like it gets misaligned. So I think what is mentioned here in the post is zeroing out a single element.

Am I missing something here, should a COP where you have a source which is a single UDT instance to a destination of an array work or is it expected for that to fail? If it's expected to fail, what is the best way to do a write like this to an array of UDTs? I'm looking to initialize my array...do I need to use a FOR loop and cycle through the elements one by one?
 
I'm probably not understanding what you're trying to do, are you trying to clear the UDT? You can use the FLL instruction with the source = 0, destination = theUDT and the length to 1

You can use the same instruction on arrays, just modify the length
 
Sorry to resurrect this post from the dead, but I was trying to do something similar to what is said here with an array of UDT's using a COP command, and it faulted out my controller by putting a lot of garbage in the array.

Based on search of Rockwell site, that might be expected behavior since COP does 32 bit chunks and my UDT has strings and bools in it so it sounds like it gets misaligned. So I think what is mentioned here in the post is zeroing out a single element.

Am I missing something here, should a COP where you have a source which is a single UDT instance to a destination of an array work or is it expected for that to fail? If it's expected to fail, what is the best way to do a write like this to an array of UDTs? I'm looking to initialize my array...do I need to use a FOR loop and cycle through the elements one by one?

The technique described works fine. Please show us the offending code. You did something wrong, but with no code to discuss, we can't help you figure it out.
 
FLL 0 works. Example of my logic that causes faults

I tried the FLL 0 and that does the trick.

This is a copy of the code that's causing my faults. const_NullItem is same UDT data type as the MasterList_Array. The array is defined [120] in the tag list, so highest index is 119 and that's the value I have for the Last_List_Index tag referenced in the instruction. When I run the COP statement, the array gets filled with junk and then my code crashes out elsewhere when trying to use the garbage values.

Any tips on what I'm doing wrong appreciated. And thanks to Raffles for the FLL trick.

Array_reset.png
 
You aren't understanding what a COP does.

the way your code is written you assume that a COP will apply the number of copies of const_NullItem to successive array locations of MasterList_Array starting at MasterList_Array[0] and continuing for the next Last_List_Index locations in MasterList_Array.

What is in fact happening is that COP is taking a byte-for-byte memory copy starting at the memory location containing the first byte of const_NullItem and copying it to the memory locations starting at the first byte of MasterList_Arrray[0] for the number of byte equal to Last_List_Index times the number of byte in the UDT.

You have control of what is in const_NullItem. After that you get the values from whatever tags the development software saw fit to place after the memory occupied by const_NullItem. If you look at MasterList_Array[0] after the COP I suspect it looks just fine. It is everything after that that is a mess.

Keith
 
I realized after posting this, that using the last index for the length param does not clear out the last value of the array, so have fixed my logic to account for that.
 
Correct way to fill an UDT array with a preset UDT instance

So is there a way to do what I was trying to do (ie take a sample UDT instance and copy it's values into a UDT array) using a single instruction? The FLL 0 works well for zeroing everything out, but if I wanted to initialize to something other than 0/blank it wouldn't have worked. Would I need to use a FOR loop with a COP statement to initialize based on an instance, or is there some other variant of COP that doesn't copy bytes from beyond the address space of the UDT instance being used as the source?
 
Someone else may chime in but the only way I know to initialize a UDT array with a "base" UDT is use the COP command and bump the array index. That would mean a loop if you need it done in one scan.

Keith
 

Similar Topics

"Failed to Initialize the service {3F883B87-2208-11D4-B0E7-001083022E04}" Along with "Failed to load HMI Server Service" Hello, I am getting...
Replies
2
Views
611
Hey all, I have a local STRING tag inside of an AOI. I want to initialize it with a value INSIDE of the AOI. For example, @ First scan...
Replies
9
Views
1,616
Hello Everyone! New guy here posting first time. I'm kind of lost with this, when I open my excel file I got this error message. Any one that can...
Replies
0
Views
1,327
Hello, PLC rookie here working with an AB CompactLogix LI6ER in RSlogix 5000. So far I've only used structured text. I'm working on an...
Replies
9
Views
2,649
Hi folks, I'm new to connected components and I have some projects coming up that require it. I am trying to initialize an array I created using...
Replies
1
Views
2,385
Back
Top Bottom