0% found this document useful (0 votes)
9 views9 pages

CV-X Outputting - String Data EIP

CV-X Outputting_String Data EIP

Uploaded by

laserhaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views9 pages

CV-X Outputting - String Data EIP

CV-X Outputting_String Data EIP

Uploaded by

laserhaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Reference Only

TECHNICAL GUIDE
String Data Output using EtherNet/IP

www.visionsystem.com
Copyright© KEYENCE CORPORATION. All rights reserved.
Reference Only

String Data Output using EtherNet/IP

Outputting Code Reading or OCR Results using EIP


It can be a little tricky dealing with string type data output (1D, 2D and OCR) to a PLC using EtherNet/IP
(EIP) communications. Since EIP does not receive string data directly, code readout data will be sent out
using ASCII decimal values (zero = 48, one = 49…..A = 65, B = 66 etc.) Furthermore, by default, the
character data will be broken up and sent one character per 32-bit Double Integer tag (DINT) to the PLC
when the tool result is output directly to EIP.

The below example shows a 2D code readout result and how the data is output to the PLC using
EtherNet/IP as a default with each decimal ASCII character output to a 32-bit data result. The CV-X lists
the data locations in groups of bytes (8 bits):

Sending one character to each DINT can be inefficient, especially when dealing with a large amount of
data. This technical guide shows how to consolidate the characters and convert them to a string in the
PLC (Using Allen-Bradly Control/CompactLogix type PLC).

Consolidating Character Data


A calculation function can be used to consolidate up to 4 ASCII characters (8 bits) for each CV-X data
result, which can be output to one DINT location at the PLC. The CVX allows up to three answers (ANS)
per calculation – ANS0, ANS1, and ANS2. So, one calculation tool can convert and output up to 12
characters. This will only use three Data Result locations or DINTS on the PLC and will make for easier
conversion to a string data type.

www.visionsystem.com
Copyright© KEYENCE CORPORATION. All rights reserved.
Reference Only

String Data Output using EtherNet/IP


Example:
In this example, 12 characters from an OCR tool will be combined and output to the PLC using EIP as 3
calculation results.

After the code reading tool (1D, 2D, OCR) has been setup on the CV-X program. The next step would be
to add the necessary calculations. Calculations can be added from the “Mathematical Operations”
category in the tool list of the CV-X series.

In a calculation, the measured results of the reference tool are added by selecting “Measured Value”
from the calculation menu.

www.visionsystem.com
Copyright© KEYENCE CORPORATION. All rights reserved.
Reference Only

String Data Output using EtherNet/IP


In the “Measured Value” menu, the required results from the tool can be selected. In this example, the
“1st Candidate Character” results of the OCR tool (T100) are used, which are the best matching
characters that the tool has detected. The first character in the readout result is number “0” and
incrementing up for each character.

The setup for 1D or 2D code readout would be very similar to the OCR, but the nomenclature would be
slightly different. The menu below shows how to find the measured values from a code reading tool.

The calculation uses some basic math functions to shift the characters over by 8, 16 and 24 bits to
combine 4 characters to one single 32 bit answer. Since the calculation has three answers (ANS0, ANS1,
ANS2), 12 characters are combined in this script.

www.visionsystem.com
Copyright© KEYENCE CORPORATION. All rights reserved.
Reference Only

String Data Output using EtherNet/IP

Calculation Script Example:


'Combine first four characters of code reader
@1 = T100.RSLT.CHR1[0]:MS
@2 = T100.RSLT.CHR1[1]:MS * 256 'shift over 8 bits
@3 = T100.RSLT.CHR1[2]:MS * 65536 'shift over 16 bits
@4 = T100.RSLT.CHR1[3]:MS * 16777216 'shift over 24 bits
'Combined 1st four characters to ANS0
ANS0 = (@1+@2+@3+@4)/1000 'divide by 1000 because of fixed decimal EIP output
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'Combine second set of four characters
@1 = T100.RSLT.CHR1[4]:MS
@2 = T100.RSLT.CHR1[5]:MS * 256
@3 = T100.RSLT.CHR1[6]:MS * 65536
@4 = T100.RSLT.CHR1[7]:MS * 16777216
'Combined 2nd four to ANS1
ANS1 = (@1+@2+@3+@4)/1000 'divide by 1000 because of fixed decimal EIP output
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'Combine third set of four characters
@1 = T100.RSLT.CHR1[8]:MS
@2 = T100.RSLT.CHR1[9]:MS * 256
@3 = T100.RSLT.CHR1[10]:MS * 65536
@4 = T100.RSLT.CHR1[11]:MS * 16777216
'Combined 3rd four to ANS2
ANS2 = (@1+@2+@3+@4)/1000 'divide by 1000 because of fixed decimal EIP output

In the above, ANS0 is the first 4 characters, ANS1 is the next 4, and ANS2 is the last 4. More calculations
can be added as necessary, following this same method, depending on how many characters are being
read by the code reading tool.

www.visionsystem.com
Copyright© KEYENCE CORPORATION. All rights reserved.
Reference Only

String Data Output using EtherNet/IP

Editing Calculations in the CV-X Simulator


When using the CV-X Simulator for programming, there is direct input method for calculations where
keyboard typing and copy/paste operations can be used to simplify the input and editing of the script. A
double-click on the script field in the simulator will open a text box. It is particularly helpful in this
example where repetitive functions in the script can be copied as needed. The script can also be pasted
into any other text program, like Microsoft Word.

Double-click here!

Freely edit the


calculation script.

This text edit window is only available when using the simulator, it is not available when programming
directly on the controller or connected to the controller using the CV-X Vision Terminal software.

www.visionsystem.com
Copyright© KEYENCE CORPORATION. All rights reserved.
Reference Only

String Data Output using EtherNet/IP

Data Output to EIP


Once the calculations are complete, the answers need to be output to the PLC via EIP. As long as the
answers are output in the order of the characters (see below), the string can be converted correctly on
the PLC side. Unless the code readout has a fixed number of characters each time, it may be necessary
to output the “Number of Characters” result from the code tool, so the PLC knows how many characters
are detected each time.

The below shows the output setup in this example:

In this setup, the first 4 characters will be output to Result Data 1, the second set of 4 characters to
Result Data 2, and the 3rd set of 4 characters to Result Data 3. The number of characters will be output
to Result Data 4. All of these output results are 32-bit values or DINT on the AB PLC. As seen below, the
character results in the DINT appear as a very large number, but when copied or moved to a “STRING”
tag, they will be converted correctly.

www.visionsystem.com
Copyright© KEYENCE CORPORATION. All rights reserved.
Reference Only

String Data Output using EtherNet/IP


Copy DINT Data to STRING Tag
The STRING tag on the AB PLC can be used to convert decimal ASCII character data to a string. The
“STRING” tag contains a length of the string (.LEN) and the actual character data (.DATA[ ]). Each
character is stored in a SINT array (8 bits). A “STRING” tag that was added to the PLC program is show
below. The tag was labeled “TEXT”.

A “COP” command is used to copy the DINT data from the Data Results into the “STRING” character
location. The command will automatically take the DINT data and put it into the correct number of SINT
tags. In our case, 1 DINT will copy to 4 x SINT (4 characters per DINT).

A screen shot of the actual PLC program for this set up is shown below. The Result Data starts at
“I.Data[12]” as “TEXT.DATA[0].” The length should be the number of SINT’s (characters) to be copied.
This should be set to the maximum number of characters being used (12 in this example). The number
of characters detected are copied to TEXT.LEN, so the string tag will only convert the character that
were actually detected by the inspection tool.

www.visionsystem.com
Copyright© KEYENCE CORPORATION. All rights reserved.
Reference Only

String Data Output using EtherNet/IP


Data Result Examples
Here are a few examples of results from the OCR Tool readout:

Readout = “ABCD12345678”; 12 characters

Readout = “12345678”; 8 characters

Readout = “KEYENCE”; 7 characters

www.visionsystem.com
Copyright© KEYENCE CORPORATION. All rights reserved.

You might also like