Dynamic String Size

3 posts in this topic

I have a Cognex Insight Camera that is reading a barcode and sending it to my PLC (Logix 5000).  I am using Cognex add on profile for communication.  I have the first 32 bits of the

TAG:"camera.I.InspectionResults" designated for the read barcode.  

I then copy this data into a local TAG "Read_String" for further processing.

Typically the barcode is a fixed length of 24 characters.  In this case I adjust the length of my "Read_String" TAG to 24 and everything works fine.  If I set the length to more than 24 then I get Null characters included on the end of my "Read_String" which causes me issues later.  So I need to make certain to set the length correctly.

Recently, my customer is starting to change the barcode length.

I am wondering what my options are for a more dynamic method of determining the barcode length.

I was going to experiment with an FSC instruction to find where the first null character is (Based on a previous tip I was given). 

However, I am curious about using a SIZE instruction.  Would the size instruction tell me the length of all characters including the Null characters?  Or would it just give me the length of the string and not count the Null characters.  That would be nice.

I would experiment with this myself but I do not have a access to PLC at the moment.

Does anyone have a thought on this potential solution path.




Share this post

Link to post
Share on other sites

I used Cognex bar code reader with AB. I copy the bar code string in a string tag by using the .ResultLength variable (see picture). As you can see in the screen shot .LEN or ResultLength does not include null.



Scan sample bar code result.PNG

Share this post

Link to post
Share on other sites

That is a really great way to handle it when you are using a handheld barcode reader.  I plan to use that method in the future.

However, in my case I have an Cognex Insight (fixed scanner).  The AOP for Insight does not have a member for  TAG.ResultLength.  At least not that I can find.

In the case of Insight I believe you have to pre-define the length of data that you will be sending out even if you do not end up using each reserved character.  This is why I need to analyze the read data to determine how many characters are valid (not null).






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