Details
Solution: controlling the number of read codes via RS-232 input
Problem description
Some applications require external control over how many Data Matrix codes a DataMan reader should read per trigger event. For example, a PLC or host system may need to dynamically switch between reading one code or multiple codes based on process state.
Solution overview
This solution uses a communication script to monitor the RS-232 (COM1) interface of the DataMan reader.
Based on simple ASCII commands received over RS-232 ("1" or "2"), the script adjusts the Multi-Code configuration and triggers a read accordingly.
Solution script
function CommHandler()
{
return {
onConnect: function (peerName)
{
my_name = peerName;
if (my_name != "COM1")
return false;
this.send(my_name + ": connected\r\n");
return true;
},
onDisconnect: function ()
{
},
onError: function (errorMsg)
{
},
onExpectedData: function (inputString)
{
if (inputString == "1") {
dmccSet("MULTICODE.NUM-CODES", 1);
dmccCommand("TRIGGER", true);
}
else if (inputString == "2") {
dmccSet("MULTICODE.NUM-CODES", 2);
dmccSet("MULTICODE.MAX-NUM-CODES", 2);
dmccCommand("TRIGGER", true);
}
return true;
},
onUnexpectedData: function (inputString)
{
return true;
},
onTimer: function ()
{
},
onEncoder: function ()
{
}
};
}
How it works
- The script listens for incoming data on COM1 (RS-232).
- When a command is received:
- "1" → Configure the reader to read one Data Matrix code
- "2" → Configure the reader to read two Data Matrix codes
- After configuration, a software trigger is issued.
- The Multi-Code settings are updated dynamically before each trigger.
Configuration notes
- Ensure RS-232 communication parameters (baud rate, parity, stop bits) match the host system.
- The input commands are case-sensitive and must exactly match "1" or "2".
- This approach can be extended to support additional commands (e.g., "3", "4") if required.
Summary
- RS-232 input can be used to dynamically control Multi-Code behavior.
- Simple ASCII commands allow flexible runtime configuration.
- This method is well suited for PLC- or host-controlled reading scenarios.