Sign in to follow this  
Followers 0
Difool

String searching function

6 posts in this topic

Hello, I'm working with a CJ2M CPU and I need to search for a 14 characters long ASCII string stored on the PLC memory that match with a barcode ascii string. I know that it have tracking instructions (RSRCH=, RSRCH2= and RSRCH4=) but how to do with seven-word (14 characters long ASCII string) record ? Maybe by splitting records in two four-word and verify that matching address are correct ? Any ideas would be much appreciated. Thanks Edited by Difool

Share this post


Link to post
Share on other sites
How is the comparison table structured? One would think that it is done in 7x word blocks? Do you have the address setup?

Share this post


Link to post
Share on other sites
Nothing is done yet. For now, we can think that it is done in 7x word blocks. Obviously there will be data related to the reference (the 14 characters long ASCII string), but it should be ignored for the moment.

Share this post


Link to post
Share on other sites
Have you looked at the Find$(660) instruction. It will return a the equals flag if the two strings are an exact match.

Share this post


Link to post
Share on other sites
Does this solution seems to be acceptable for you ? It would search for the string stored in D3000 in every 100 words from D10000 to D11000. D1000.02 become 1 if the string is not found D1000.03 become 1 if the string is found Can there be any problem with this ? I think that the P_EQ flag can be a problem maybe I can remove it ? Thanks Edited by Difool

Share this post


Link to post
Share on other sites
Whether that would work will depend on what the data in D10000-11000 actually looks like. The FIND$ instruction is a string search so it will only find data up to the first null character (#00 byte) imbedded in the target array. The null character marks the end of the string so the FIND$ instruction stops searching at the first null it encounters. Also .... If the first string contains the second string the FIND$ instruction will return a pointer to the beginning of the second string within the first string. Example: A search for string "456" in string "123456789" will return a value of 4. IF you format your data table correctly you can search up to 2047 bytes at a time. Since your data is 14 bytes (7 words) you should be able to pack it so that there are no imbedded nulls. That would allow you to search blocks containing up to 146 barcodes at a time. It probably easier to format the data in 1000 word blocks so you could search through 142 at a time with 6 words of #0000 at the end of each block. The pointer returned by the FIND$ instruction will tell you which barcode matched the search string. Edited by Mendon Systems

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
Sign in to follow this  
Followers 0