Skip to Main Content
Centro de soporte de Cognex
LogoLogo

Script - Filter Data Matrix Codes by Length

15/04/2025

Answer

DataMan systems don’t natively filter Data Matrix or QR codes by length, but you can use a sample script to do this.

 

Sample script
'use strict';
const NO_READ = 'No read!';
const DM_SYM = 'Data Matrix';
const DM_LENGTH = 16;
let outputString = '';

function onResult (decodeResults, readerProperties, output){
 outputString = NO_READ;
   if (decodeResults[0].decoded){
     if ((decodeResults[0].symbology.name == DM_SYM) && (decodeResults[0].content.length == DM_LENGTH)){
       outputString = decodeResults[0].content;
     }
     else{
       output.events.system = 2;        
     }
   }
 output.content = outputString;
}

 

Using the Script

  • Functionality: The script checks the length of scanned codes and filters them based on your defined criteria.
  • Customization: You can modify the script to filter codes by specific lengths or ranges, and adapt it for other needs.
  • Further Development: This sample serves as a starting point for more advanced features like integrating it into larger workflows or adding extra filtering logic.

This will allow you to filter Data Matrix and QR codes by their length, and you can easily modify the script for your specific use case.

Recursos relacionados

Loading component...