Skip to Main Content
Cognex Support Hub
LogoLogo

Script - Match String Validation

This sample script shows how the Match String Validation can be implemented in a script

02/28/2025

Details

The following Data Formatting Script can be used for Match String Validation. The value of the match string can be changed with the below DMCC command:

||>SET INPUT-STRING.VALUE "TEST"<CR><LF>

(TEST is the new match string value in this example, and <CR><LF> are the CarriageReturn and LineFeed control characters).

 


Data Formatting Script

dataman-script-match-string-validation-img1

Reset Configuration of the device and enable Script-Based Formatting, then copy and paste the below code into the Data Formatting Script, overwriting any existing code there:

 

var myStartup = 0;
var myInputString = "";
function onResult (decodeResults, readerProperties, output) {
   if (myStartup == 0) {
       dmccSet("INPUT-STRING.ENABLE", 1);
       dmccSet("INPUT-STRING.HEADER", "[");
       dmccSet("INPUT-STRING.FOOTER", "]");
       dmccSet("INPUT-STRING.MODE", 0);
       myStartup = 1;
   }
   if (readerProperties.inputstr.length > 0) {
       myInputString = readerProperties.inputstr;
   }
   if (decodeResults[0].decoded) {
       if (decodeResults[0].content == myInputString) {
           output.content = decodeResults[0].content + "\r\n";
       }
       else {
           output.events.system = Event.system.validationFailure;
           output.content = decodeResults[0].content + " (INVALID)\r\n";
       }
   }
   else {
       output.content = "(NOREAD)\r\n";
   }
}

Related Resources

Loading component...