Skip to Main Content
Cognex Support Hub
Logo

DataMan Script for Unprintable Characters

This article describes how the unprintable characters can be removed from the reader's output string.

11/29/2024

Details

In some cases, particularly in applications related to data management or supply chain, specific control characters such as RS, GS, and EOT may appear in a DataMatrix code. These characters are used for technical and formatting purposes.

Here’s what they mean:

  1. RS (Record Separator):
    The RS character (ASCII 30) is used to separate records in a data sequence. In a DataMatrix code, it could be used to separate different units of data or fields within the same code. This helps the application reading the code to correctly delimit the data sections and process them properly.
  2. GS (Group Separator):
    The GS character (ASCII 29) is used to separate groups of data. It can be used to delimit subsets of data within a DataMatrix code that is structured hierarchically or contains multiple levels of information. For example, in product labeling, a code might contain information related to the product itself, its packaging, its manufacturing date, etc., and the GS character would separate these details into distinct groups.
  3. EOT (End of Transmission):
    The EOT character (ASCII 4) marks the end of a data stream. In the context of a DataMatrix code, it could be used to indicate the end of the encoded data string. This allows the application reading the code to know that there is no more data to process and to stop the reading process.

Why are they used in a DataMatrix code?

  • Structure control: These control characters help indicate how the data is structured within the code. This is particularly useful when multiple types of information need to be encoded in the same code or when complex data needs to be separated into logical parts.
  • Compatibility with automated processing systems: These characters are used to make DataMatrix codes compatible with systems that require delimiters and end-of-message indicators (such as in inventory management, traceability systems, or logistics).

In summary, the RS, GS, and EOT characters in a DataMatrix code are used to organize and structure the encoded data logically, making it easier to interpret and process within automated systems.

Here is the result from the DataMan Setup Tool, with default settings : 

Placeholder

The DataMan Setup Tool can translate the unprintable characters, by checking the box "Enabled" as per below :

Placeholder

Here is the result : 

Placeholder

Those characters (<RS>, <GS>, <EOT>) can be removed from the output string, by using a script :

  • Go to "Format Data",
  • Go to "Basic",
  • Check the box "Script-Based Formatting",
  • Click on the blue text "Script-Based Formatting" to open the "Data Formatting Script": 

    Placeholder

Use the script below as a "Data Fomrating" Script : 

var RS = "\x1E";
var RSN = "<RS>";
var GS = "\x1D";
var GSN = "<GS>";
var EOT = "\x04";
var EOTN = "<EOT>";
var res = "";

function onResult (decodeResults, readerProperties, output)
{
   if (decodeResults[0].decoded)
   {                
       var convert = decodeResults[0].content.replace(new RegExp(RS,'g'),RSN).replace(new RegExp(GS,'g'),GSN).replace(new RegExp(EOT,'g'),EOTN); 
   }
  
  res = convert.replace(/<RS>|<EOT>/g, '');
  res = res.replace(/<GS>/g, '-');
   
  output.content = res; // without carriage return     
  //output.content = res + "\r\n" ; // with carriage return
}

Placeholder

Here is the result : 

Placeholder