Details
Solution: Triggering Different Outputs Based on Code Content Using Scripting
Problem Description
Some applications require distinguishing between two (or more) different codes that share the same symbology but can be identified by unique, static substrings within the decoded data.
Example requirement:
- If Pattern 1 is present → activate Output X
- If Pattern 2 is present → activate Output Y
This behavior is not achievable using standard output conditions alone and requires scripting.
Solution overview
DataMan readers support User Events (User1 / User2) that can be triggered from a script based on custom logic. These User Events can then be mapped to digital outputs on fixed-mount DataMan readers.
By searching the decoded string for specific substrings, the script can selectively fire the appropriate User Event.
Example script
The following script checks the decoded result for the presence of specific string patterns and triggers User Events accordingly:
function onResult (decodeResults, readerProperties, output)
{
if (decodeResults[0].decoded)
{
if (decodeResults[0].content.indexOf("07P") != -1)
output.events.user1 = true;
if (decodeResults[0].content.indexOf("05L") != -1)
output.events.user2 = true;
output.content = decodeResults[0].content;
}
}
How it works
- The script executes after each read attempt.
- If decoding is successful:
- The decoded string is searched for predefined substrings (e.g., "07P" and "05L").
- When a pattern is found, the corresponding User Event is triggered.
- User Events can then be routed to digital outputs using standard I/O configuration.
Configuration notes
- Ensure User Event 1 / User Event 2 are correctly mapped to the desired digital outputs in the reader configuration.
- The string comparison is case-sensitive.
- Multiple User Events can be triggered from a single decode if multiple patterns are present.
Summary
- Substring matching allows discrimination between different codes.
- User Events provide a flexible mechanism to control outputs via scripting.
- This method enables content-based output control beyond standard decode conditions.