Using Data Tree

MavEric

Member
Join Date
Mar 2008
Location
Ohio
Posts
15
The next system that we are building will be sorting through as many as 2000 barcodes. Using Control Logix, a barcode will be recieved, and that barcode will need to be found in the list. I was looking at a "Tree" structure to find the code in the least number of scanns or loops. This is normaly done in VB, but has anyone ever attempted to do this in Ladder Logic?
 
Phew... that would be an interesting task for a PLC...
One big problem that I see, is that BTrees generally rely heavily on pointers and dynamic allocations. That can be rough on a PLC, but could be gotten around perhaps just by allocating some huge data tables to begin with.

Second problem would still be traversal, you will have to deal with non-contiguous iterators... Possible, maybe.

I'd offer that if you really want to try this, your best bet is to do the programming in structured text, but even so.... the potential for errors would be huge.

If you really really really want to do this integral to the PLC, I'd suggest getting one of the Prosoft Module's, and programming the app within that, and use the CIP Backplane interface to send data to the module, query it back, etc.
 
I disagree. A search through the 2,000 or so barcode array with a FSC instruction, can be done in one scan, and I estimate quicker than passing the search target to a co-processor, then waiting for a result.

How fast do you need the answer ?
 
We've done a similar thing in ladder logic but only for about 150 barcodes, so on a much smaller scale than you are needing.
We used the FSC instruction, but did come across one problem when one of our barcodes was an element shorter than all the others when it was scanned (11 instead of 12 digits on this occasion), so this is something you may want to be aware of, as it is a DIRECT comparison with whatever you compare to in your array of references.
With only 150 comparisons we didn't notice any impact on scan time, but I would imagine that 2000 compares would probably have some impact.

Just my 2c worth.
 
My understanding was that the FSC compares until it finds a match then bails out of the instruction and tells you where it found the match (I'm going to go and double check all this in a minute).

Therefore the worst case sceanrio would be that it's the last record that you compare meaning it could go through all 2000 records, and I just assumed (yes I know how bad that is) that this will take longer with more records.

I personally agree that it can be done in a plc, I only wondered what impact it would have on scan time and if that is a critical part of the process or not.

I'm off now to read up on the FSC!
 
daba said:
I disagree. A search through the 2,000 or so barcode array with a FSC instruction, can be done in one scan, and I estimate quicker than passing the search target to a co-processor, then waiting for a result.

How fast do you need the answer ?

My reply was directed at creating a BTree for the barcodes to keep them traversally sorted, NOT using an FSC on a linear data block.
 
Yes, the attached RSLogix program sorts 255 numbers very quickly. It should not be hard to modify to pick out a match from 2000 numbers.
 
MavEric, if you keep the numbers sorted you should be able to find the correct number in 11 compares. 2^11=2048. You do this as if you were trying to gues a number between 1 and 100. Start with 50 and then try 25 or 75 depending on whether the number is higher or lower than 50. This is called a binary search.
 
If I were you,I could go with the ST since you can program in similar C style, and there are a lot of sorting and search algorithms around, just make sure there is No pointer but only array in Controllogix...
 
9 msec

daba said:
I disagree. A search through the 2,000 or so barcode array with a FSC instruction, can be done in one scan, and I estimate quicker than passing the search target to a co-processor, then waiting for a result.

How fast do you need the answer ?

I did a quick test using an array of 2000 14-character strings with the target in the last position.
Time for the search was 9 msec on a rev 15 L61.
 
Gerry said:
I did a quick test using an array of 2000 14-character strings with the target in the last position.
Time for the search was 9 msec on a rev 15 L61.

I think that's pretty quick, for a PLC, and interesting to know, thanks for that Gerry.
 
Impressive - what about other positions? Were there any values in the other registers?

Gerry said:
I did a quick test using an array of 2000 14-character strings with the target in the last position.
Time for the search was 9 msec on a rev 15 L61.
 
surferb said:
Impressive - what about other positions? Were there any values in the other registers?
As you might expect, finding the target at position 1000 took 4.5 msec.
The rest of the array had null strings - I did say quick test.
 

Similar Topics

Hi all so i have a robot project im working on were i need to set the layers. using the hmi screen i would like to use the numeric data display to...
Replies
11
Views
821
We have a product we are now building and are planning on using RFID tags to ID trays of product as they move through the process (5 individual...
Replies
6
Views
1,432
I'm currently working on a messaging system and Ive been having issues with trying to message over a REAL Data Type from one PLC to another. Has...
Replies
2
Views
1,280
I work at a cheese factory and we recently ran into a problem where in an older controller they where able to use a REAL Data type in OTU and XIC...
Replies
13
Views
2,587
Hello all. Would anyone have sample code that uses a wall clock to move the CTU.ACC to a another variable in the PLC after 24-hours has elapsed? I...
Replies
2
Views
1,929
Back
Top Bottom