Skip to Main Content
Cognex 支持中心
LogoLogo

Script-Validation Failure when the Code Read is the Same as Last Time

This article is an example about how to output validation failure when the code read is the same as last time in script.

2025/10/30

Details

  1. Enable Script-Based Formatting.

    Script-Validation Failure When the Code Read Is the Same as Last Time_Image-1
  2. Edit Data Formatting Scripting.

    Script-Validation Failure When the Code Read Is the Same as Last Time_Image-2

    Sample code:
    // Default script for data formatting
    var last_result = "";
    function onResult (decodeResults, readerProperties, output)
    {
       if (decodeResults[0].decoded)
       {
           if(decodeResults[0].content == last_result)
           {
               output.content = ""; //user can set custom output string here
               output.events.system = Event.system.validationFailure;
           }
           else
           {
               output.content = decodeResults[0].content;
               last_result = output.content;
           }
       }
    }

  3. In this example, when the code read is the same as last time, the reader outputs nothing. User can modify the related “output.content” to output custom string.
  4. In this example, the reader outputs three types of Results Status. When the code read is the same as last time, Result Status is “Invalid”.
Script-Validation Failure When the Code Read Is the Same as Last Time_Image-3