Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: rockhead on November 09, 2016, 10:53:02 AM

Title: Implement a table search in Do-More
Post by: rockhead on November 09, 2016, 10:53:02 AM
I'm working on my 1st project with Do-More. I have a memory address setup to hold a number entered from a touchscreen (Part Number). I have a table of 40 values (Part Number List) that will be searched for a match to the entered value. I need to know the index position of the match (Position 10 in the table). I was able to accomplish this easily using the FIND instruction in DS5. I see there is no equivalent to this instruction in Do-More right now. I was thinking I might be able to accomplish this using a FOR-NEXT loop but was wondering if there might be other alternatives.
Title: Re: Implement a table search in Do-More
Post by: BobO on November 09, 2016, 11:26:02 AM
We are definitely adding table functions in the future, but for now the best bet is some form of loop iterator.

One big benefit of looping in Do-more is the yielding mechanism: all looping instructions test the execution time at the bottom of the loop, and if it exceeds the specified time slice for that task or program block, it suspends the operation and picks up next scan. If the time slice value for a task or program block is 65535 (the max), it does not do the yield test. By default, only $Main's slice is 65535 (it can be changed) and all others will yield. So with that in mind, the preferred way to do a search is to put the search code into a dedicated task, and one-shot enable the task any time you need to do the search.

If your table is always small, it's no big deal to put it inline and not do the task thing...however...loops can hit scan time pretty hard, and do so much quicker than you expect.

Sorry for the inconvenience. We understand the importance of table functions and had hoped to get them into our next release, but the new hardware under development has been a monumental effort for us and forced certain features further into the future.
Title: Re: Implement a table search in Do-More
Post by: plcnut on November 09, 2016, 11:49:20 AM
Here is how I do it.
(https://forum.hosteng.com/proxy.php?request=http%3A%2F%2Fi761.photobucket.com%2Falbums%2Fxx256%2Fplcnut%2FPLCs%2FFindPartSample_zpsvkmghtu9.png&hash=9fed70944607d5c0df8dbb54ffd42167976aa0a0) (http://s761.photobucket.com/user/plcnut/media/PLCs/FindPartSample_zpsvkmghtu9.png.html)
Title: Re: Implement a table search in Do-More
Post by: rockhead on November 09, 2016, 01:34:31 PM
Thanks for the replies guys.

BobO: I was planning on putting this in a task since it will only need to run occasionally. I will keep the time slice feature in mind as I work things out. And this is really not an inconvenience. A little challenge for the brain is never bad. As you know, in programming there is always more than one way to skin a cat. I understand everything can't get done at once and that some things must take precedence over others.

plcnut: Your code looks even simpler than what I was thinking of doing. (Even simpler than using FIND in DS5) Thanks for the example.
Title: Re: Implement a table search in Do-More
Post by: Controls Guy on November 14, 2016, 01:07:17 PM
Or you can either sort the table and use COUNTIFxx, or create a one-column index table.   This doesn't save you anything if you have to continuously reindex, but someone suggested doing a CHECKSUM on the table data to tell when it had changed (in another application).  If you do that, then you only reindex or resort when needed.