Cognex barcode data comparison in PLC

Sean Teague

Member
Join Date
Apr 2020
Location
Tennessee
Posts
69
I have installed a Cognex barcode scanner on a machine. I have a 1769-L18ER CompactLogix processor.

I have communication setup and working.

I have the 4 digits from my barcode scan coming into the PLC as SINT into:

COGNEX:I.ResultData[0] = 1
COGNEX:I.ResultData[1] = 0
COGNEX:I.ResultData[2] = 2
COGNEX:I.ResultData[3] = 5

So my barcode read is "1025" which is correct. The barcode is the current date. (Month and Year)

I want to compare this to two STRING files already in the PLC...

Print.ST16[30] = 10 (current month)
Print.ST16[31] = 25 (current date)

Im having trouble figuring out how to compare this data.. Basically I need to combine COGNEX:I.ResultData[0] and COGNEX:I.ResultData[1] to get my month and COGNEX:I.ResultData[2] and COGNEX:I.ResultData[3] to get my date, then compare each of those to the existing Print.ST16[30] and Print.ST16[31]

any help would be greatly appreciated. I hope i explained it well enough
 
You have to concatenate COGNEX:I.ResultData[0], COGNEX:I.ResultData[1],COGNEX:I.ResultData[2],COGNEX:I.ResultData[3] and convert the whole thing to an integer 1 "1025" in this case, then get month an day from wallclock and concatenate them to get another integer 2 "1025", then compare the two of them.
 
Last edited:
You have to concatenate COGNEX:I.ResultData[0], COGNEX:I.ResultData[1],COGNEX:I.ResultData[2],COGNEX:I.ResultData[3] and convert the whole thing to an integer 1 "1025" in this case, then get month an day from wallclock and concatenate them to get another integer 2 "1025", then compare the two of them.


I have to concatenate COGNEX:I.ResultData[0] and COGNEX:I.ResultData[1] together then concatenate COGNEX:I.ResultData[2] and COGNEX:I.ResultData[3] right?

then concatenate the results from the 1st one and the 2nd one together.

but the data from the barcode scanner is in SINT format. What type of data is the location they go into?
 
I think you will have to convert the SINTS to individual strings first, and then concat them together into one string.
 
I think you will have to convert the SINTS to individual strings first, and then concat them together into one string.

I used the COP instruction to copy the SINT to a STRING but the result is just showing a " symbol. Do i need to be online with the processor for this to show the actual data being moved? Im doing this at my desk right now.
 
You should be able to copy the 4 SINTs to a DINT, then do a DTOS to convert the DINT to String.

Edit just seen you are comparing to 2 strings, you can convert your compare value to 1 string and do the above or convert your 4 SINTs to 2 Strings and compare to the original 2 strings.
 
I did a COP for the SINT to a DINT. Then a DTOS.... but i am not seeing a value in the destination. Do I need to be online with the processor to see this? as i am at my desk and offline right now.

STRING.PNG
 
Copy [0],[1],[2] and [3] at the same time to form a string "1025" ,
Or copy [0] and [1] at the same time to form "10" then convert it to int , then compare to month your get from wallclocktime
Use the same with [2] and [3]
 
Copy [0],[1],[2] and [3] at the same time to form a string "1025" ,
Or copy [0] and [1] at the same time to form "10" then convert it to int , then compare to month your get from wallclocktime
Use the same with [2] and [3]

Could you explain in a little more detail how to do this?
 
I´ll try to do my best , see attached figure

Codigo_Barras means Barcode in spanish, that´s my mother language.
As you can se my code is composed from 14 sints (EAN14), but wait my code is numbered from [0] up to [13], I can copy (COP) just two items [0] and [1] or you can copy the whole thing, I mean 14 sints
Do you know how to do it. ??,

Barcode.jpg
 
You cannot simply COP a SINT into the DATA of a String tag and expect the correct result -- despite the fact that Strings are made up of 'SINT' they are interpreted as ASCII, and the ASCII representation of a number is not the same as the actual value of that number.

For example, if in widelto's screenshot above you were to change the representation from 'ASCII' to 'Decimal', you would see that '1' is actually 49 for the first character of the string. If you copy from a SINT with a 1 in it into the SINT of a String, the resulting ASCII value will be a 'Start of Header' character, (shown as '$01') not a '1' character.

This is why a DTOS is used, to convert the value into the ASCII representation. You could technically add your own math to convert, but why bother when there's an instruction that does the work for you and is less likely to confuse anyone who looks at your code later?

Note that contrary to what the name might suggest you do not need to use an intermediate DINT, the DTOS instruction supports both SINT and INT input).

EDIT: See attached for an example. 'NullString' should be an empty string tag.

DTOS_example.png
 
Last edited:

Similar Topics

We are trying to get rid of triggering and just have the scanner always trigger. The only part I am having trouble figuring out is how to use the...
Replies
3
Views
2,501
Struggling!! I have a Dataman 100 Cognex barcode camera with Cognex I/O board. I have established comunication with the camera and the I/O board...
Replies
7
Views
4,458
We finally replaced our Cognex Checker with an IV-3 and I'm wondering if can replace the s/w in the monitor with anything else. I haven't been...
Replies
0
Views
100
Thank you for any and all responses/help. I have an RSLogix 5000 v20 and a Cognex In-Sight v5.9 spreadsheet (8502P). I can not figure out how to...
Replies
0
Views
128
Which signals do I have to use to get data from camera. For example camera detects a defect and sends signal to controller. Power cable: CCB-PWRIO-05
Replies
1
Views
213
Back
Top Bottom