How to ignore duplicate values from an array before coping to new array RS Studio5000

boxenough

Member
Join Date
Nov 2023
Location
India
Posts
8
Hello All,

need one help , looking for a example which can help me to write following code in Studio 5000 ladder logic.

I have 2 String Arrays with 1200 String Capacity
Array 1 and Array 2

Array 1 holds raw data with 1200 different string values, some of these values are duplicated multiple times.

I want to copy the the raw data from Array 1 to Array 2, but during this copy operation I want to ensure that I copy only 1 Instance of each value, if the values are duplicated in Array1 , I want to ignore the duplicated values.

So at the end of this operation, I will have Array 2 , with only 1 Entry of each string value from Array 1.

Thanks in advance for the help.
 
Don't want to sort the data, I am using Studio 5000 Ladder Logic,

tried something with FSC by array with k, k+1 as index, and shift all string 1 position up if duplicate is found on any specific location.

it works but takes forever to complete.
 
For each element in array A do file search to see it it is found in array B if not found then move it into array B
I would recommend an AOI
It looks like an interesting little AOI to put together for that
Let us know how you make out
 
it works but takes forever to complete.


Well yeah, that's a O(N²) solution (see here). That's why I suggested sorting - that gets it down to O(NlogN) or so, then O(N) to extract unique elements. Doesn't Logix have a built-in sorting block?

One approach would be to build a sorted array, using insertion sort, of the unique values, because then you can use binary search to do the comparison, so you get O(NlogN).
 
Hello All,

need one help , looking for a example which can help me to write following code in Studio 5000 ladder logic.

I have 2 String Arrays with 1200 String Capacity
Array 1 and Array 2

Array 1 holds raw data with 1200 different string values, some of these values are duplicated multiple times.

I want to copy the the raw data from Array 1 to Array 2, but during this copy operation I want to ensure that I copy only 1 Instance of each value, if the values are duplicated in Array1 , I want to ignore the duplicated values.

So at the end of this operation, I will have Array 2 , with only 1 Entry of each string value from Array 1.

Thanks in advance for the help.


So, you are saying that the result array will be stripped of duplicates, ignoring those that have already been copied ?

If this is the case, I would attack this problem differently.

I would look at how the duplicates get into the source array in the first place, and prevent that happening.

Once you've cracked that, you're good to go ....
 
I was able to bring down the scanning time , I copied entries 1by1 to a temp tag.

Scanned this TempTag with final output Tag.

Still fine tuning the logic, but so far it looks quick, I was able to scan and sort 200 values with 125 unique entries in 7ms. Thanks for the help. :geek:

Copy Unique Entries_Rung1_3.JPG Copy Unique Entries_Rung4_7.JPG
 
Nicely done.

7ms for 200 entries suggests about a quarter second for 1200 entries (7ms x (1200/200)2), assuming a similar ratio of duplicates to total entries.

FYI: the code does not need the PulseforFSC bit:

  • An XIC StartScanning can feed the MOV+FSC on Rung 4 instead,
    • and the RES ModelTempCMP on Rung 5 would ensure the FSC executes on every pass through the loop.
  • It's not critical because the code works either way.
    • So if PulseforFSC is kept, then it does not need to be unlatched twice (Rungs 5 and 7).
 
Also, the Length parameter of the CPS instruction is the number of destination elements to be copied, not the number of bytes*, so its should be 1 on Rung 6, or else the code could theoretically overrun the end of array ModelString.

Since that TempModelCode.LEN value is never greater than 8 in the current example, and also the ModelString array is probably never filled to within 7 elements of its end, it is unlikely that an actual overrrun would ever occur.

* See here, middle of page 426 and top of page 429.

Sidebar: if the CPS Length parameter was the number of bytes, then it would always be too short, because the string length precedes the string data in a string structure; if the CPS Length parameter was the number of 16-bit words, then it would work as long as it was at least 4.
 
I see problems with the way you want to do it i think you result data will not be what yu want
the only way is to use a loop compare the source and it its not found in the destination file then move it over. the destination file should be accessed with an FFL instruction
with the modern processors I don't see where you will see a time delay
the only loop is in the source file.
I would put the transfer program in a subprogram and only call it when you need it
 

Similar Topics

Is there a way to configure a Micrologix 1400 to ignore an I/O configuration mismatch? I have 1400 that I keep here for local debugging it has...
Replies
10
Views
3,494
Good Morning , I just recently did a project with several PowerFlex 525 drives. I just recently started getting a F 73 Fault ( EN Net Loss...
Replies
24
Views
24,463
Hey guys, I'm seeing some odd behavior with some MSG instructions I have set up. Specifically, when I enable the MSG instruction I nearly...
Replies
5
Views
6,015
is there any way to ignore a rung that has an error in it, and let the program run in Rslogix5000?
Replies
11
Views
4,851
Hi I have a CPU 3152PN/DP on which I have 3 IM-151 ET200S stations on profibus. Each station is in a different panel, each panel is seperatley...
Replies
10
Views
9,953
Back
Top Bottom