Skip to Main Content
Centro Assistenza Cognex
Logo

Toggle Read Setups using digital input lines

An application may require dynamic selection of Read Setups. This script approach demonstrates a solution which is based on the functionality of the older generations of DataMan Readers such as DataMan 150/260 and DataMan 300/360 and the early versions of DataMan 370/470.

06/02/2026

Details

Solution: Dynamic Selection of Read Setups Using Digital Inputs

Problem Description

Some applications require dynamic selection of Read Setups based on external signals, such as digital inputs from a PLC or sensors. Depending on the active input, a specific Read Setup must be enabled while all others are disabled.

This behavior is commonly required in multi-part or multi-orientation inspection scenarios.

Solution Overview

This solution demonstrates how to dynamically switch between Read Setups using digital input events and scripting.

The approach is based on the functionality of legacy DataMan readers (e.g., DataMan 150/260, DataMan 300/360, and early DataMan 370/470 firmware versions), which require explicit enabling and disabling of individual Read Setups using scripting and DMCC commands.

Note:

On modern DataMan readers, this logic can often be simplified by using the DMCC command:

SETUP.USE-SINGLE <x>
This command replaces the need for manually issuing SETUP.PROG-TARGET and SETUP.ENABLE commands.

Solution Script (Legacy-Compatible Approach)

var resTmp;

registerHandler(Callback.onInput, onInput0, ConstInput.Input0);
registerHandler(Callback.onInput, onInput1, ConstInput.Input1);
registerHandler(Callback.onInput, onInput2, ConstInput.Input2);

function onResult (decodeResults, readerProperties, output)
{
   if (decodeResults[0].decoded)
   {
       output.content = decodeResults[0].content;
   }
}

function onInput0(inputs)
{
   if (inputs & ConstInput.Input0) {
       dmccSet("Setup.Prog-Target", 0);
       dmccSet("Setup.Enable", "ON");
       dmccSet("Setup.Prog-Target", 1);
       dmccSet("Setup.Enable", "OFF");
       dmccSet("Setup.Prog-Target", 2);
       dmccSet("Setup.Enable", "OFF");
   }
}

function onInput1(inputs)
{
   if (inputs & ConstInput.Input1) {
       dmccSet("Setup.Prog-Target", 1);
       dmccSet("Setup.Enable", "ON");
       dmccSet("Setup.Prog-Target", 0);
       dmccSet("Setup.Enable", "OFF");
       dmccSet("Setup.Prog-Target", 2);
       dmccSet("Setup.Enable", "OFF");
   }
}
function onInput2(inputs)
{
   if (inputs & ConstInput.Input2) {
       dmccSet("Setup.Prog-Target", 2);
       dmccSet("Setup.Enable", "ON");
       dmccSet("Setup.Prog-Target", 0);
       dmccSet("Setup.Enable", "OFF");
       dmccSet("Setup.Prog-Target", 1);
       dmccSet("Setup.Enable", "OFF");
   }
}

How It Works

  • Digital input callbacks (Input0, Input1, Input2) are registered.
  • When a specific input becomes active:
    • The corresponding Read Setup is enabled.
    • All other Read Setups are explicitly disabled.
  • Only one Read Setup remains active at any given time.
  • Decoded data is passed through unchanged in the onResult handler.

Modern Reader Alternative

For modern DataMan readers and firmware versions, the same functionality can typically be achieved more efficiently by issuing:

SETUP.USE-SINGLE <x>

This command automatically enables the specified Read Setup and disables all others, reducing script complexity.

Configuration Notes

  • Ensure that the digital inputs are correctly wired and mapped to Input0, Input1, and Input2.
  • This example assumes mutually exclusive inputs.
  • For non-exclusive or noisy inputs, additional debouncing or logic may be required.

Summary

  • Dynamic Read Setup selection can be implemented using scripting and digital input callbacks.
  • Legacy readers require explicit enable/disable logic per Read Setup.
  • Modern readers support a simplified command for single-setup selection.

Risorse correlate