RSLogix: Deleting an element from Array

OOPer

Member
Join Date
Jun 2011
Location
CA
Posts
35
I am sure this has been discussed before, but the search didn't turn out anything for me.

I was wondering how someone would delete an element from array. For instance:

Array[0] = 10
Array[1] = 20
Array[2] = 30
Array[3] = 40
Array[4] = 50

I need to delete 30, or element at index 2 (my array is unique). Which should make the array look like:


Array[0] = 10
Array[1] = 20
Array[2] = 40
Array[3] = 50

Any suggestions?

I am thinking about an AOI that basically re-assigns values after doing an FSC, but it doesn't sound very smart :D
 
You can't change the size of an array in the controller, so what you're really doing is performing a shift of all the values in the array.

You'll have to use a routine that indexes through the array and shifts all the values up by 1, then you have to decide whether to put a zero at the end of the array or some other filler.

This is similar to how a FIFO stack works, but the FIFO Unload and LIFO Unload instructions always take the value off the bottom or top of the stack, not an assignable location in the middle.
 
You can't change the size of an array in the controller, so what you're really doing is performing a shift of all the values in the array.

You'll have to use a routine that indexes through the array and shifts all the values up by 1, then you have to decide whether to put a zero at the end of the array or some other filler.

This is similar to how a FIFO stack works, but the FIFO Unload and LIFO Unload instructions always take the value off the bottom or top of the stack, not an assignable location in the middle.

I dont need to change the size of the array. I am okay with making the last element 0.

This array is actually a FIFO queue, but I have exception where I need to pop an element from the middle of an array.

After some more searching COP looks promising. I need to play with that.
 
Here is an attempt of what you asked as an Add-On instruction. This is rough draft is in version 19. It will take an array any size copy the requested element into a destination tag and move elements below requested position up to fill. The last element in the array will be written to 0.

Darren
 
Last edited:
Reread what you said and if this is part of managing a FIFO or LIFO I guess I should embed the control structure so it will update the .POS variable and keep all that in sync. That would also make it to where it can only move what is in the stack instead of shifting the whole array.

Also think if your doing something like this there might also be a case where you would want to insert one somewhere in the stack other than the top or bottom.

Darren
 
I'm not totally sure what will happen when you use the CPS with the Source and Destination arrays the same.

COP instructions work on the array DINT-by-DINT so I think you should not use them when the Source and Destination. CPS locks the source and destination but I'm not sure how it works on the low level.

It would be safe to perform a COP to a storage array, then COP back to the source.
 
I can see the point, but I can say that it works on a L23 processor with current firmware. I guess that does not mean it is supposed to.

My very uneducated understanding of that instruction is that it blocks other instructions from manipulating the source and destination of the CPS instruction, but not the CPS instruction that "locked" that block of memory first.

Like I said, I could be completely mistaken.

I have done copy instructions (COP, not CPS) like that across many of the A-B platforms (PLC5s and SLC) and it has worked for years. Fairly common when shuffling product storage (SRS aisles or powered and free conveyors). Maybe I have just been lucky in doing that.

I was also trying to keep the size down on the AOI and make it flexible to any array size, I guess I could also reference the second array by reference. I'll look at it again.

Darren
 
Last edited:
Also looked at online help and the last example is real similar to my usage, other than it is moving that data down, instead of up. They are also using the COP, but they imply the CPS is also valid.

Darren
 
Here is the revised version that would share the same control structure as the one you are using with a pair of LIFO or FIFO instructions.

Working on another instruction to load in the middle of an array.

As a general disclaimer I have checked several use cases, but I may have missed one. Please check before using if you think it suits a need.

If you use and modify please share back.

Darren
 
We do this very thing in PLC-5s using the FAL instruction set up as a move, the source being one more than the address of the value you wish to delete and the destination being the adress to be written over. Something like: FAL R6:x POS=y (2, in your case) LEN=(file_len(5) - source index(3), yielding 2) Expression=POS+1. You have to set the position and length before triggering the FAL and be sure to fill the last position with a zero when you're done.
 
OK. I digested all the suggestions and code-snippets you guys gave me and came up with the following. Feedback is more than welcome, as I am relatively new to PLC programming/Ladder logic

The code is tested.

Thanks for all the input
 

Similar Topics

This may seem like a really simple question to ask, but I can't seem to find how to delete the last two modules I added to the backplane in...
Replies
11
Views
11,402
I am currently working on a project where IO is not being used but previously was used in the field. In logix for example I have a tag where we...
Replies
4
Views
6,966
Hello Forum, I'm new to the AB family of controllers and software. Most of my experience has been with Mitsubishi FX series controllers. I've...
Replies
5
Views
5,870
I have a little bit of experience with Allen-Bradley. I have a Micrologix 1500 (RSLogix 500) and a PanelView Plus 7 (FactoryTalk View Studio ME)...
Replies
2
Views
80
Back
Top Bottom