Replace a non-printable character in the scanned barcode

Version 2

    Replace a non-printable character in the scanned barcode


    Some barcodes can include one or more special characters which are decoded as non-printable characters in a scanned barcode. This script intercepts the scanned barcode data and replaces specific characters with another. You can modify this script as required. Comment are provided next to specific lines of Javascript code.


    • This script looks for a non-printable character 0x29 or and * character in the data. You can change these to to any other hex value or character
    • You can change the replacement character from "." to whatever you prefer. If you want to simply remove the character, you do not have to replace it
    • This script adds an Enter operation postamble


    To download this sample, See attachements



    function OnBarcodeRead( session, data, source, type, date, time ) 
    { // // Look for the non printable GS character(s) in the scanned data var newdata = '';   
    // Uncomment this next line to debug 
    // OS.Alert("Symbology ID = " + type + "\nReceived data: \n" + data);  
    // Go through every character of decoded scan data for (i=0; i < data.length; i++) 
    // You can change the character to any other Hex value 
    // for your non printable character or any other character 
    // TODO: Update next line to match your non-printable or other 
    // character which you want to replace 
    if ((data.charCodeAt(i) == 0x1D) || (data.charAt(i) == "*")) 
    // Replace the non printable character with ".". Comment 
    // this next line if you simply want to remove the non 
    // printable character 
    newdata += '.'; 
    newdata += data.charAt(i); 
    // Add a Carriage Return postamble 
    newdata += "\r";  
    // Send barcode to emulator 
    CETerm.SendText( newdata, session );  
    // Return 0 to handle barcode normally 
    // Return 1 if handled here 
    return 1;