CPS - Question rs5000

Control Logix - L8

CPS Array[1], Array[0], 30.

What I want to do is move everything up one. It is an Array of 31.

IE Array[30] goes to Array[29]. I can do this with the CPS individually but I was hoping to find a way to not have 30 CPS in a rung.

Any help is much appreciated.
 
Welcome to the forum.

I always use a temporary array of equal size that can be used for the transfer.

CPS Array[1] tempArray[0] 30

then

CPS tempArray[0] Array[0] 31
 
This is ugly, but it works (substitute 30 for 10 in Length and Dest, and 29 for 9 in Expression). Personally, I would go with the intermediate array suggested earlier.


Reverse FAL.jpg
 
I should have clarified better. These Arrays are utilizing a UDT control, that makes theM 4 dimensional I believe. I am still learning the UDT's and Data structure so bare with me.

Its an Array, with 4 dimensions if it's like this? Array[0].one, Array[0].two, Array[0].three, Array[0].four
Array[0]- Array[30].

I looked into FAL before I made this post and thought I saw it did not utilize multidimensional arrays.
 
If you are shifting UDT array elements, I think the only option will be a FOR loop where the working subroutine will use a COP instruction to move up the previous element.

For example: COP Source: Array[index - 1], Dest: Array[index], Length 1

and then your FOR instruction would use a step size of -1, initial 30, terminal 1.
 
Does the UDT consist of only four elements, one, two, three and four? If so then an array based on that UDT will copy fine. If the UDT has elements in addition to those then the CPS won't work.
 
Just one small point...

I'm not sure which way you're ultimately going with your solution, so it may or may not apply - but to take your original example of...

COP Array[1] Array[0] 30

...where "Array" is an array tag of 30 elements, from Array[0] to Array[29]. For the sake of simplicity, I'll assume an array of DINT's; I know that you're actually using UDT's but the principle is the same.

The first copy will copy Array[1] to Array[0]
The second copy will copy Array[2] to Array[1]
...
...
The twenty-ninth copy will copy Array[29] to Array[28]
The thirtieth copy will copy whichever 32 bits of data just happen to come after Array[29] in the PLC memory into Array[29].

You have no way of knowing what these 32 bits are. It could be another DINT, it could be three BOOL's and empty space, it could be part of a UDT, it could be four SINT's. In the case of your UDT, if your UDT size is 27 bytes, you will get 27 bytes of gibberish copied into the last element of your UDT array.

The point of all this is simply that when you execute this instruction, you will not just shift everything down one array element and end up with a nice blank DINT/UDT in Array[29]. It will be full of unpredictable data. So, it's important to clear this out once you're done.

If the very next thing you intend to do is to put some meaningful data into Array[29], then this might not cause you any problems. But just be mindful of copying the entire UDT structure over, so as to completely overwrite any "garbage" data - not just the bits that you particularly need to set.
 
Right - sorry! For some reason I missed the fact that your array length is 31.

So yes, you're right - the only thing of course being that Array[30] (i.e. the 31st element) will at the end of the COP process, still have the same data as what was there previously (and copied into Array[29]) - it will not be "blank".

Carry on!
 
You could use the following code in a Structed Text routine and just call it for one scan to shift all of your array elements. Change the ArrayCount-1 from the first part of the COP instruction to the second part if you want to shift the other way.

Code:
for ArrayCount := 30 to 1 by -1 do
	COP(Array[ArrayCount-1],Array[ArrayCount],1);
end_for;
 

Similar Topics

I was having an issue where I would use the CPS instruction to copy a sint value to a string value( len=decimal , data= sint[82]) The data values...
2
Replies
3,789
Views
So I'm trying to do some arithmetic with arrays of DINTs. However, I'm running into a problem. I’m trying to create a copy of let’s call it...
2
Replies
6,922
Views
Anyone have a cj1m_cpu12 cps file? I am using cx programmer 9.75 and when I go to the IO table it has an error saying I need to install the cps file.
3
Replies
1,278
Views
Good afternoon, I have some old QuickPanels from Total control Products that need repair. Does anyone recommend any company which can repair these...
1
Replies
605
Views
I very rarely work with STRINGS and can't remember the last time. I've attached a l5k file that contains four rungs where I'm simulating...
6
Replies
2,587
Views
Top