F_VN_ReadDataMatrixCode

F_VN_ReadDataMatrixCode 1:

Detect and interpret a data matrix code (ECC200) within the provided image.
Can return partial results when canceled by Watchdog.

Syntax

Definition:

FUNCTION F_VN_ReadDataMatrixCode : HRESULT
VAR_INPUT
    ipSrcImage    : ITcVnImage;
    ipDecodedData : Reference To ITcVnContainer;
    hrPrev        : HRESULT;
END_VAR

F_VN_ReadDataMatrixCode 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image (USINT elements, 1 or 3 channels)

ipDecodedData

Reference To ITcVnContainer

Returns the decoded code (ContainerType_Vector_String_SINT)

hrPrev

HRESULT

HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.)

F_VN_ReadDataMatrixCode 3: Return value

HRESULT

Further information

The data matrix barcode according to IEC 16022 is a 2D code that facilitates storage of large data quantities with minimum space requirements. It is therefore often used for component and product marking.

The function F_VN_ReadDataMatrixCode can only recognize and decode ECC 200 code types in the image. This is based on one code per image. If several Data Matrix Codes are to be recognized and decoded in one image, the function F_VN_ReadDataMatrixCodeExp must be used.

Data Matrix Code structure

The Data Matrix Code consists of rectangles or dots that make up a square or rectangular symbol, which in turn can be divided into three areas:

F_VN_ReadDataMatrixCode 4:
  1. Finder Pattern
    The solid-line locator (L) is used to locate and align the code, while the pattern-line locator (P) is used to determine the cell size and arrangement.
  2. Data area
    The data area is surrounded by the Finder Pattern.
  3. Quiet zone
    The quiet zone is an area at least 1.5 cells wide around the Finder Pattern in the background color of the code.

Flaws / damage in the Finder Pattern or in the quiet zone can prevent detection of the code.

Error correction

Data Matrix Code ECC 200 (ECC = Error Correction Code) is the generally accepted version due to its better error correction. In addition to the actual data, they are coded redundantly based on the Reed-Solomon code. Data matrix codes of this version can be decoded by the function. In case of damage an error correction can be performed.

Code search

The function F_VN_ReadDataMatrixCode searches for a Data Matrix Code in the image, starting from the center line of the image.

Read data from container

If the code was successfully found and decoded, the code content is returned in the container ipDecodedData and can be exported to a string using the function F_VN_ExportSubContainer_String.

hr := F_VN_ExportSubContainer_String( ipDecodedData, 0, sText, nMaxLength, hr);

HRESULT

Like all TwinCAT Vision API functions, this function also returns an HRESULT to indicate whether the execution was successful or not. In the event of success, a distinction can be made between the following success codes in the subsequent handling of the results. To distinguish between these cases, the HRESULT variable can be compared directly with S_OK or S_FALSE.

Code

Name

Description

16#000

S_OK

The function was executed successfully.
The specified number of codes was found in the image.

16#001

S_FALSE

The function was executed successfully.
Fewer codes than indicated in the image were found.

16#256

S_WATCHDOGTIMEOUT

The function was aborted by the watchdog.

Examples

Related functions

Required License

TC3 Vision Code Reading

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1.4024.54 or later

PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU

Tc3_Vision