Posted 29 Mar 2022 Hi, I need help finding the length of a string. I am using an In-sight 9000 series camera with a compact logix 5380 and communicating over ethernet. Unfortunately, the string length is not provided in the AOP, and the barcode length will constantly change. I told to use the FSC instruction, but I cannot get it to work. Thanks Share this post Link to post Share on other sites
Posted 29 Mar 2022 Compact Logix String Variables consist of two parts. String.LEN and String.Data Are you saying String.LEN is a zero or an 82 and does not match the length of the data? Share this post Link to post Share on other sites
Posted 30 Mar 2022 Bob, No, the camera only provides the string, not the length of the string. Share this post Link to post Share on other sites
Posted 30 Mar 2022 I just rechecked the Cognex site and the 9000 uses the same AOP that the 5000 I worked with uses and the string length is part of what is sent. Can you post what you're seeing when online with the processor? Share this post Link to post Share on other sites
Posted 30 Mar 2022 Sure, i attached two pictures. the second one is the all the inputs from the AOP, and you can see it does not have a length Share this post Link to post Share on other sites
Posted 30 Mar 2022 What is the data type of the InspectionResults tag? Share this post Link to post Share on other sites
Posted 30 Mar 2022 Is it a SINT array? In other words, does it say "SINT[x]" in the datatype? What's the value of the "x"? The Logix 5k STRING datatype is actually a compound datatype consisting of a .LEN element (DINT) and a .DAT element which is a SINT[82] array. If Cognex isn't giving you the length automatically, you can find it pretty easily with a loop that looks for the first element of the SINT array that has a value of zero. Or use the FSC. I threw this together real quick, so you'll want to do some limit/error checks to avoid overflows and such. After a single false-to-true rung condition, the .POS member of the Control tag used in the FSC contains the index of the first zero element of the array, which is also the length of the string. The element before that (element [7]) is the last character of the string. To work with it in the PLC, you can COP the SINT array into the .DAT element of a string tag and then update the .LEN element if the string tag with the .POS member of the FSC control tag. Share this post Link to post Share on other sites
Posted 30 Mar 2022 2 hours ago, Nickyv6363 said: Sure, i attached two pictures. the second one is the all the inputs from the AOP, and you can see it does not have a length So which element of the status data array is the string you are interested in? You mentioned in your original post that the "barcode length will vary" but you don't show the data structure that brings the barcode over. The status array just shows you what the camera is doing not what data it might have available to send. Share this post Link to post Share on other sites
Posted 30 Mar 2022 In the first picture is, camera.inspectionresults, is what I am focusing on. The status does not mention inspection length, nor does camera.inspectionresults. After Talking to Cognex, this is a known issue with the series 9000 AOP, but they helped me get the length using spreadsheet. I would still like to use the FSC function that Joe mentioned in the post above to find a length of a string when it's not provided just in case, I might need it in the future. Thanks for the help!!! Share this post Link to post Share on other sites