Sign in to follow this  
Followers 0
kcox1980

Need some help with data comparison

4 posts in this topic

I'm working on integrating a Keyence CV-X400 vision system controller in with our PLC, an Allen Bradley 1756-L62. I have the camera controller set up to recognize a character string and pass this information along to the PLC where I will make a comparison to verify that the data in the string is correct. The string is in the format of "XXX-Y-XXXX" most of the time but occasionally it is in the format "XXX-YY-XXXX" the "Y" characters are the only ones I care about for the sake of comparison as those are the only ones that change from day to day via manual user input.

Attached is a screen cap of what I have right now, which works for the first format (The 56 currently stored in the tag represents an 8 in ASCII) but I don't know how I should go about programming for the second format. Basically what I'm doing right now is passing the entire string to the PLC, and then using a NEQ instruction on the 5th character over. This won't work when using the "YY" because in those cases I'll need to compare the 5th and 6th character.

The CV-X by default send the characters individually though I can set it up to send 4 at a time. I'm not sure if that would help here though.

Capture.PNG

Share this post


Link to post
Share on other sites

Hello,

You could consider copying the xxx:I.Data array into a string variable (be aware that the first byte is the string length!) which then  exposes the ASCII String functions such as "FIND" and "MID".

eg, once the data is cast into a STRING data type, you could search for the "-" (hyphens) using "FIND" and then use the located positions and feed into "MID" function to extract the string representation of the product number. The final step would be to use "STOD" instruction to convert from STRING to DINT for use in the NEQ instruction. 

hope this is of some help.. good luck!

vds

StringParsing.jpg

Edited by vds

Share this post


Link to post
Share on other sites
4 minutes ago, vds said:

Hello,

You could consider copying the xxx:I.Data array into a string variable (be aware that the first byte is the string length!) which then  exposes the ASCII String functions such as "FIND" and "MID".

eg, once the data is cast into a STRING data type, you could search for the "-" (hyphens) using "FIND" and then use the located positions and feed into "MID" function to extract the string representation of the product number. The final step would be to use "STOD" instruction to convert from STRING to DINT for use in the NEQ instruction. 

hope this is of some help.. good luck!

vds

StringParsing.jpg

This is definitely not something I would have thought of on my own. Thanks!

Share this post


Link to post
Share on other sites
1 hour ago, vds said:

Hello,

You could consider copying the xxx:I.Data array into a string variable (be aware that the first byte is the string length!) which then  exposes the ASCII String functions such as "FIND" and "MID".

eg, once the data is cast into a STRING data type, you could search for the "-" (hyphens) using "FIND" and then use the located positions and feed into "MID" function to extract the string representation of the product number. The final step would be to use "STOD" instruction to convert from STRING to DINT for use in the NEQ instruction. 

hope this is of some help.. good luck!

vds

 

Thanks again man. I ran into a couple of snags but I was able to figure it all out. This method worked perfectly.

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