Finding Tags with the same Values

Catgomeow11

Member
Join Date
Jun 2023
Location
Wisconsin
Posts
1
Hello,

I have an array of 300 of UDT. In each UDT is an array of 3 DINT and another array of 3 REAL. I have 10 controllers that pull data from the list of 300 UDT's

Component: ARRAY[1..3] OF DINT
Percent: ARRAY[1..3] OF REAL

I am trying to find all Components with a different value. I also want to find Components with the same value, and then add the Percent of Components / total Components.

Thanks
 
It might help to provide an example set of UDTs - maybe 5. Populate the Component and Percent values to show what you are. Trying to do. Your explanation is not clear to me.

Also mention the PLC and programming software.
 
Last edited:
1) Do you have an expected range of values for the Component[] elements?
2) Do Component[] elements correlate 1:1 with Percent[] elements?
 
I can hardly think of a task more well-suited for an SQL query, and more poorly-suited for a PLC.

I would probably attack the problem by putting all the UDT elements into two 900-element 1-dimensional arrays.

Then execute an SRT instruction on the array; that will sort all the values from lowest to highest.

Then you can index through the array and compare each element to the prior element. If it's the same, add 1 to the "same" total.

That will *count* the number of "same" values in the array of UDTs. It won't identify their locations.
 
I would make an array corresponding to the range of expected Component values, indexed 1:1. Make one pass over all UDT.Component and increment the array value(s) as they are found. No sort needed.
 
Well, I thought this was interesting and it was time for a break from something else, so I came up with this. I am assuming that Percent[x] corresponds to Component[x]. This puts the results in an array with a count for each unique component and the average percent for that component. I made the result array [900] in case every Component is unique. After the screenshot I deleted testDINT and put the indirect referencing in the while loop without testDINT. I’m not updating the screenshot. No guarantees on anything, express, implied, or anything else.

Edit: I think i need parentheses around (ResultArray[k].Count + 1) in line 15.

Another edit: I ran it. It looks like it mostly works except it puts some garbage count in the first result that should be blank. Now I remember why I started with the testDINT. I was going to clear it if duplicate, and then not populate the first blank.

… and not even process if SourceComponent = 0

8A28F65E-4E07-42AA-895F-C262F0C87062.png
 
Last edited:
Welcome to the forum.


Component: ARRAY[1..3] OF DINT
Percent: ARRAY[1..3] OF REAL

I am trying to find all Components with a different value. [different than what?] I also want to find Components with the same value [same as what?], and then add the Percent of Components / total Components.


I am with @bernie_carlton: a more complete problem definition is necessary.


Are we treating each individual Component value, three per UDT, as a single Component value to be compared against all 899 other Component values, or are we treating each UDT's Component triplet as a set of values to be compared against the Component triplets in all 299 other UDTs? If the latter, does the order of components in the UDT matter when doing the compare?

Does the full complement of comparisons need to be performed on every scan cycle, as in @5618's code, which could be nearly half a million compares per scan cycle? Or could this be done in segments, with a limited number of compares per scan cycle to avoid a watchdog timeout?

In @5618's code, lines 25-27 are redundant.
 

Similar Topics

Hello all, I have what has become a complex problem, with what I'm hoping is a simple answer. I am using FactoryTalk Linx Gateway set up as an...
Replies
1
Views
2,381
All, I am going through an existing HMI program that has about 900 tags. I am pretty sure there are multiple tag names referencing the same tag...
Replies
4
Views
2,185
Hi all, I have been using RSLogix for the last couple of months and one thing I miss coming from Schneider Unity Pro is the ability to find tags...
Replies
6
Views
3,792
Howdy all. Should be an easy one but im pulling out my hairs here. I have a motor i want to start with a button on the factorytalk screen...
Replies
2
Views
3,330
Hi all, I figured out how to get my runtime app on my computer to point to the right PLC, but now I am getting a diagnostic error: Item Known to...
Replies
0
Views
3,405
Back
Top Bottom