jamie thorndal

Search a array

8 posts in this topic

Hi PLC guys

I am in the middle of a project where i am to search a array that look like this (se pic). i need to search it for the element called .Vogn_ID the second one in the tbl_Ordre.

There is 50 tbl_ordre containing Vogn_ID

array.PNG.4723bcbd4b1725fa9f50c81c3657c1

I have tried a FSC, but in my expression i can only be allowed to write like this (See picrockwell.thumb.PNG.a09a345ca41e6baa9bbb7).

The problem, it will only search that array not all the 49 others.

Anybody have a idea

 

Share this post


Link to post
Share on other sites

You want the code to continuously search a block of arrays or a one-time search of the block?  

Let's say you want to, based on a condition (start of a sequence), scan the block of arrays to find the array with the ID that matches your target.  Your code would need a loop and an indexer.  You already have an indexer in the EXPRESSION; currently, your indexer is [0].  Also, your code needs to do something...what is to be done when you have a match?

1 person likes this

Share this post


Link to post
Share on other sites

The code is to search efter time i trigger it to do so, this ofc is not made yet in the pictures i showed you. But The main problem is that the "vognID_search = tbl_ordre[0].Vogn_ID only searches the [0] and i need it to search the hole array, the [1] [2] etc.

And when they are found then i need to know where to look so i can use the specific arrays part for the info they contain.

Do know if this makes any sense, if not let me know and i will try to do better :-)

Share this post


Link to post
Share on other sites
Just now, jamie thorndal said:

The code is to search efter time i trigger it to do so, this ofc is not made yet in the pictures i showed you. But The main problem is that the "vognID_search = tbl_ordre[0].Vogn_ID only searches the [0] and i need it to search the hole array, the [1] [2] etc.

And when they are found then i need to know where to look so i can use the specific arrays part for the info they contain.

Do know if this makes any sense, if not let me know and i will try to do better :-)

As kaiser_will said, you need an index and a loop. Instead of vognID_search = tbl_ordre[0].Vogn_ID you need vognID_search = tbl_ordre.Vogn_ID where i is an index that gets incremented by 1 every time the loop executes. You'll also want to a iMax so that the loop restarts at 0 once it reaches the maximum value of the array (otherwise your processor will be likely to fault 

Share this post


Link to post
Share on other sites

Michael Lloyd makes a good point...adding error checking to keep your array search from exceeding the dimension of the array.  This WILL fault the processor.

Step back and flowchart what you want your process to be.  A concise flowchart can be directly turned into working code.  

Elements of your flowchart...indexer that steps from 0 to ?; array search that searches one element of the array to be the same as ?; what do you want to have happen when there is a search match (i.e., latch an event tag) or no match (unlatch an event tag); do you need an exit from the loop (i.e., Machine NOT Start).

Share this post


Link to post
Share on other sites

:-) I have the patented "did I do that" questioning stare down thanks to occasionally forgetting to set the max array dimension parameter in a looping routine that we use. :-1 I ended up hard coding it into the structured text routine that maps the IO to tags used in the loop. Line item one of the routine says: Index_Max_Analog := 253; or whatever value needs to be there.

 

Edited by Michael Lloyd
1 person likes this

Share this post


Link to post
Share on other sites
5 hours ago, Michael Lloyd said:

:-) I have the patented "did I do that" questioning stare down thanks to occasionally forgetting to set the max array dimension parameter in a looping routine that we use. :-1 I ended up hard coding it into the structured text routine that maps the IO to tags used in the loop. Line item one of the routine says: Index_Max_Analog := 253; or whatever value needs to be there.

 

Many of us have learned this.  Especially when you unexpectedly shutdown production that is valued at $50K an hour.  Been there.

1 person likes this

Share this post


Link to post
Share on other sites
On 22/08/2016 at 1:44 AM, jamie thorndal said:

Hi PLC guys

I am in the middle of a project where i am to search a array that look like this (se pic). i need to search it for the element called .Vogn_ID the second one in the tbl_Ordre.

There is 50 tbl_ordre containing Vogn_ID

array.PNG.4723bcbd4b1725fa9f50c81c3657c1

I have tried a FSC, but in my expression i can only be allowed to write like this (See picrockwell.thumb.PNG.a09a345ca41e6baa9bbb7).

The problem, it will only search that array not all the 49 others.

Anybody have a idea

 

Try replacing [0] with [Search_array.POS]

 

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now