chrisb4748

Function block for indexing and look up

17 posts in this topic

Hi,

I am using a CJ2H PLC.

I am looking for a way to index string [10] and also be able to do a look up.

What I am wanting to do is - Add a new Magazine ID into E6_00[10] and add that magazine weight into E7_00[10]. I will be using upto E6_9999 and E7_9999.

If that Magazine ID is already in the table, I want to be able to find that Magazine ID and compare the weight with the previous weight within the table.

Many Thanks

Share this post


Link to post
Share on other sites

If you want to perform math and comparisons on the data then you'll need to convert it to a number.

First have a look at the Text String Processing instructions. There are various instructions to extract only the numeric characters from your string. Which you use will depend on what your sting looks like. (MID$, LEFT$, RGHT$). If you know the character you are looking for then use the FIND$ instruction. FIND$ will return the index number.

Next use the NUM instruction to convert it to a number.

Share this post


Link to post
Share on other sites

Don't index the string, leave it alone. Rather index a pointer!

The string is represented by numbers by a group of 10 words, so IMHO there is absolutely NO need to Text Processing Instructions. 

Enter the new magazine ID into a temporary area [ID_NEW]. This could be any unused area in the PLC you choose.

Use a for/next loop that indexes the pointer starting at the first Magazine ID location E6_00.

Compare the 10 Words of [ID_NEW] to the 10 words of the pointer ID location using five LD=L [Double words] comparison instructions to achieve this. 

IF all ten words match copy them to a second temporary area  [ID_FOUND] break out of the for/next loop.

IF all ten words don't match THEN increment the pointer to the next Magazine ID.

Continue for/next.

IF ID is found you now have two temporary memory areas [ID_NEW] and[ID_FOUND] to work with and manipulate as required.

 

Done this MANY times for similar applications.

Share this post


Link to post
Share on other sites

That would have been my preferred method.  :shrug:

Share this post


Link to post
Share on other sites

Brilliant.

Thanks for the advice.

Clears a lot up for me. 

Share this post


Link to post
Share on other sites

Bits N Bytes,

I have been really struggling to write my code that you have recommended.

By any chance would you have a sample program that I could understand further what you mean?

I rarely use Omron, only reason I'm working with it is because it is the only PLC that Nissan UK use.

Many Thanks   

Share this post


Link to post
Share on other sites
8 hours ago, chrisb4748 said:

Bits N Bytes,

I have been really struggling to write my code that you have recommended.

By any chance would you have a sample program that I could understand further what you mean?

I rarely use Omron, only reason I'm working with it is because it is the only PLC that Nissan UK use.

Many Thanks   

Ill be glad to help, but first.

How many characters is the Magazine ID?

How many characters is the Magazine weight?

Where in E6 memory is the first Magazine ID and where in E6 memory is the second Magazine ID?

Where in E7 memory is the first Weight for first Magazine ID and where in E7 memory is the Weight for the second Magazine ID?

Share this post


Link to post
Share on other sites

Hi,

Both Magazine ID and Magazine weight are going to be 10 character strings.

My E6 and E7 memory are going to start at E6_00, E7_00

Then the second position is going to be E6_01, E7_01

Many Thanks  

Share this post


Link to post
Share on other sites
4 hours ago, chrisb4748 said:

Hi,

Both Magazine ID and Magazine weight are going to be 10 character strings.

My E6 and E7 memory are going to start at E6_00, E7_00

Then the second position is going to be E6_01, E7_01

Many Thanks  

A 10 Character string uses 5 words. So first ID occupies E6_00 thru E6_4 and first weight E7_00 thru E7_4.

So if first ID and Weight are in E6_00 and E7_00 then I assume you mean second ID and Weight are in E6_10 and E7_10?

Share this post


Link to post
Share on other sites
Just now, BITS N BYTES said:

A 10 Character string uses 5 words. So first ID occupies E6_00 thru E6_4 and first weight E7_00 thru E7_4.

So if first ID and Weight are in E6_00 and E7_00 then I assume you mean second ID and Weight are in E6_10 and E7_10?

Yes, my mistake.

Share this post


Link to post
Share on other sites

Attached is example with 100 iterations of FOR/NEXT:-

ID String to search for is entered in D0-D4.

Once entered turn ON W0.0.

IF ID is Found THEN ID it is shown in D10-D14 and Weight is shown in D20-24.

 

Indexing with Lookup.cxp

Share this post


Link to post
Share on other sites
22 minutes ago, BITS N BYTES said:

Attached is example with 100 iterations of FOR/NEXT:-

ID String to search for is entered in D0-D4.

Once entered turn ON W0.0.

IF ID is Found THEN ID it is shown in D10-D14 and Weight is shown in D20-24.

 

Indexing with Lookup.cxp

Thank you so much.

Share this post


Link to post
Share on other sites

You are welcome. Always like a challenge and this one was easy!

Share this post


Link to post
Share on other sites
Just now, BITS N BYTES said:

You are welcome. Always like a challenge and this one was easy!

I see that now. 

Learning for future reference :-) 

Share this post


Link to post
Share on other sites
On 2017-5-15 at 7:39 PM, BITS N BYTES said:

You are welcome. Always like a challenge and this one was easy!

Hi, Hope you are well?

The program that you have sent me is purely for an index lookup.

How am I able to add the Magazine ID and weight to the table if not found?

At the moment my table is empty.

What I am wanting to do is add a magazine ID and the weight each time a new magazine comes round on the conveyor system.

Many Thanks,

Chris

Share this post


Link to post
Share on other sites

Per your first post, the program I posted was to lookup a matching Magazine ID and IF found display its Weight.

To continue the process of adding a Magazine ID and Weight you would implement a new index search to find the first record that is empty [contains no data].

In the example I posted there are 100 records every 10 words. IF the initial search found no matching ID then then DR0 have a value of 1000 at completion of the existing FOR/NEXT loop.

Add new ladder below posted example [VERY, VERY SIMILAR!!]

This will reset DR0 to 0 and start a new indexed search using FOR/NEXT.l

When a record with no data is found, copy the new Magazine ID to location DR0,IR0 and its Weight to location DR0,IR1 and BREAK out of the FOR/NEXT loop.

 

 

 

 

 

Share this post


Link to post
Share on other sites
11 hours ago, BITS N BYTES said:

Per your first post, the program I posted was to lookup a matching Magazine ID and IF found display its Weight.

To continue the process of adding a Magazine ID and Weight you would implement a new index search to find the first record that is empty [contains no data].

In the example I posted there are 100 records every 10 words. IF the initial search found no matching ID then then DR0 have a value of 1000 at completion of the existing FOR/NEXT loop.

Add new ladder below posted example [VERY, VERY SIMILAR!!]

This will reset DR0 to 0 and start a new indexed search using FOR/NEXT.l

When a record with no data is found, copy the new Magazine ID to location DR0,IR0 and its Weight to location DR0,IR1 and BREAK out of the FOR/NEXT loop.

 

 

 

 

 

Brilliant, got that sorted.

Thanks so much for the help.

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