Skip to Main Content
Centro Assistenza Cognex
Logo

Script Based Match String Validation Using the Input String Feature

Scripting approach for a Data Validation solution when the code contains special unprintable characters that prevent the use of the built in functionality in the reader.

18/02/2026

Details

Resolution: Implementing Dynamic Match String Validation via Script

Issue

The built-in MatchString Data Validation feature may not be usable if the code content contains unprintable characters. In such cases, an alternative approach is required to achieve equivalent functionality.

Solution

Dynamic Match String validation can be implemented through a script, with the expected data provided by a PLC before each decode cycle.

  1. Sending the expected string

    The expected data string is transmitted to the reader using a DMCC command. This can be done via:

  2. Configuring the Input String object
    To enable the Input String mechanism, both a header and a footer must be defined, even if they are not functionally used (as in the data stream method). These parameters become part of the reader configuration and can only be removed with a Reset to Factory Defaults.

    Example commands:

    ||>SET INPUT-STRING.HEADER "...."[CRLF]
    ||>SET INPUT-STRING.FOOTER "...."[CRLF]

    • Use an unlikely combination of characters for “.....” (e.g., §%(/).
  3. Transmitting the expected value

    The PLC (or host system) then sends the expected string before each decode:

    ||>SET INPUT-STRING.VALUE "abcxyz"[CRLF]

  4. Script for validation

    On the reader, insert the following script under Script Based Formatting:

    function onResult (decodeResults, readerProperties, output)
    {
       if (decodeResults[0].decoded)
       {
           var inStr   = readerProperties.inputstr;
           var readRes = decodeResults[0].content;

    if (inStr != readRes) 
               output.events.system = Event.system.validationFailure;

            output.content = decodeResults[0].content;
       }
    }

     

Result

If the decoded result does not match the input string provided by the PLC, the reader triggers the ValidationFailure event. This provides a reliable, script-based replacement for MatchString validation in environments where unprintable characters prevent the use of the built-in feature.

Risorse correlate