ScanStream can be easily programmed to perform a variety of tasks. The most common task is to send all input to the active application as keystrokes. More complex tasks such as editing scanned input into multiple inputs or adding prefixes and suffixes to scanned data are easily programmed using JavaScript or VB Script.


 

  • Script to send all scanned data followed by an Enter key directly to application:
Function COMPort_OnInput(byVal sInput)
    Scanner.SendKeys(sInput & "{Enter}")
End Function
 
  • Script to remove preceeding ‘US’ on all scanned data, then send data directly to the application followed by an Enter key:
///////////////////////////////////////////////////////////
// This script checks the first 2 characters of the scanned barcode
// for a match of 'US'.  If found, US is removed from the 
// input before sending it to the active application.  An enter
// key is sent to the active application following the scanned input.
////////////////////////////////////////////////////////////////
function COMPort_OnInput(sInput)
{
  if ( sInput.substr(0,2) == 'US' )
  {
     sInput = sInput.substr(1, sInput.length);
  }
  
  Scanner.SendKeys(sInput + "{Enter}");
}
 
  • Script to streamline receiving and send data to application:
////////////////////////////////////////////////////////////////
// This script allows users to login by scanning their badge bar
// code, keeps track of the number of packages received by this
// user during the login session, and sends the following info to
// the active application anytime a package is scanned:
// User    Date    Time    Bar Code Scanned    Total Pkgs. 
////////////////////////////////////////////////////////////////
 
// global variables
var nTotalPkg = 0; // total packages for this user this shift
var sUser = ''; // user's badge number
var sDate;
var sTime;
 
//////////////////////////////////////////////////
// function COMPort_OnInput
// Parameters:  sInput is the value of the bar code
//   that was scanned.
// Notes:  
// 1)  This function gets called every time something is 
//     scanned on the port assigned to COMPort.  
// 2)  If no user has signed in, no response from
//     function.
// 3)  Total package counter gets reset to 0 when user
//     signs out.
//////////////////////////////////////////////////
function COMPort_OnInput(sInput)
{
  // see if user is signing in
  if ( sUser == '' )
  {
     if ( sInput.length == 8 & sInput.substr(0,1) == 'X' )
     {
        sUser = sInput;
     }
  }
  // see if user is signing out
  else if ( sUser == sInput )
  {
     sUser = '';
     nTotalPkg = 0;
  }
  // must be scanning a receipt package
  else
  {
     nTotalPkg = nTotalPkg + 1;
     GetAndFormatDate();
     Scanner.SendKeys(sUser + "{Tab}");
     Scanner.SendKeys(sDate + "{Tab}");
     Scanner.SendKeys(sTime + "{Tab}");
     Scanner.SendKeys(sInput + "{Tab}");
     Scanner.SendKeys(nTotalPkg + "{Enter}");
  }
 
} // end of function COMPort_OnInput
 
//////////////////////////////////////////////////
// function GetAndFormatDate()
// Notes:  
// 1)  Formats date field to MM/DD/YYYY. 
// 2)  Formats time field to HH:MI.
// 3)  For documentation purposes, several temp
//     variables have been declared.  If RAM memory is
//     an issue, could use just one temp variable.
//////////////////////////////////////////////////
function GetAndFormatDate()
{
     var dDate = new Date();  
     var sTempDay = new String(dDate.getDate());
     var sTempHours = new String(dDate.getHours());
     var sTempMinutes = new String(dDate.getMinutes());
     var sTempMonth = new String(dDate.getMonth() + 1);
 
     /////////////////////////////////////
     // add preceeding zeros where needed
     /////////////////////////////////////
 
     if ( sTempMonth.length == 1 )
     {
        sTempMonth = '0' + sTempMonth;
     }
     if ( sTempDay.length == 1 )
     {
        sTempDay = '0' + sTempDay;
     }
     if ( sTempHours.length == 1 )
     {
        sTempHours = '0' + sTempHours;
     }
     if ( sTempMinutes.length == 1 )
     {
        sTempMinutes = '0' + sTempMinutes;
     }
 
     /////////////////////////////////////
     // now put it all together
     /////////////////////////////////////
 
     sDate = sTempMonth + '/' + sTempDay + '/' +  dDate.getFullYear();
     sTime = sTempHours + ':' + sTempMinutes; 
 
}  // end of function GetAndFormatDate
 
 
///////////////////////////////////////////////////////////
// This script checks the first 2 characters of the scanned barcode
// for a match of 'US'.  If found, US is removed from the 
// input before sending it to the active application.  An enter
// key is sent to the active application following the scanned input.
////////////////////////////////////////////////////////////////
function COMPort_OnInput(sInput)
{
  if ( sInput.substr(0,2) == 'US' )
  {
     sInput = sInput.substr(1, sInput.length);
  }
  
  Scanner.SendKeys(sInput + "{Enter}");
}
  • Script to simulate a time clock and send data to application:
////////////////////////////////////////////////////////////////
// This script works as a time clock.  Users 'punch in/out' 
// by scanning their bar coded employee number. When they punch
// in or out, the timestamp is written to the the active application.
// When an employee punches out, the hours/minutes worked is 
// calculated and sent to the active application.
////////////////////////////////////////////////////////////////
 
// global variables
var aEmployees = new Array();
var sEmployeeIn;
var sHours;
var sMinutes;
 
//////////////////////////////////////////////////
// function COMPort_OnInput
// Parameters:  sInput is the value of the bar code
//   that was scanned.
// Notes:  
// 1)  This function gets called every time something is 
//     scanned on the port assigned to COMPort.  
// 2)  If the employee has not punched in, they will be punched
//     in and a record/timestamp is sent to the active application.
// 3)  If the employee has already punched in, they will
//     be punched out and their hours worked is calculated
//     and sent to the active application.
//////////////////////////////////////////////////
function COMPort_OnInput(sInput)
{
  var bPunchIn = true;
  var dDate = new Date();  
  
  // first lets make sure it was a employee badge that was
  // scanned
  if ( sInput.length != 8 & sInput.substr(0,1) != 'X' )
     return;
 
  // see if an employee is punching in or out
  for (i = 0; i < aEmployees.length; i++)
  {
     if ( sInput == aEmployees[i].substr(0,8) )
     {
        // employee is punching out
        bPunchIn = false;
        break;
     }   
  }
 
  if ( bPunchIn == true )
  {
     // log employee in
     aEmployees.push(sInput + ',' + dDate);
     Scanner.SendKeys(sInput + " arrived on ");
     Scanner.SendKeys(dDate + "{Enter}");
  }
  else
  { 
     // log employee out & calculate hours worked
     sEmployeeIn = new String(aEmployees[i]);
     var sEmpNum = sEmployeeIn.substr(0, sEmployeeIn.indexOf(','));
     Scanner.SendKeys(sEmpNum + " departed on ");
     Scanner.SendKeys(dDate + "{Enter}");
     GetAndFormatHoursWorked();
     Scanner.SendKeys(sEmpNum + " Hours Worked = " + sHours +
         "; Minutes Worked = " + sMinutes +  "{Enter}");
 
     // remove this employee from the array
     aEmployees.splice(i,1);   
  }
 
} // end of function COMPort_OnInput
 
//////////////////////////////////////////////////
// function GetAndFormatHoursWorked
// Parameters:  none
// Notes:  
// 1)  This function gets called when an employee badge is
//     scanned that is already in the aEmployee array (must
//     be punching out).
// 2)  Global variables sHours & sMinutes get set based
//     on time elasped since the employee punched in.
//////////////////////////////////////////////////
function GetAndFormatHoursWorked()
{
   var dInDate = new Date(sEmployeeIn.substr(sEmployeeIn.indexOf(',')
                  + 1, sEmployeeIn.length));
   var dOutDate = new Date();
 
   // calculate the # of seconds worked 
   var sCount = (dOutDate - dInDate)/1000;
  
   // see if they forgot to signout
   var sDays = sCount / (24 * 3600);
 
   if ( parseInt(sDays) > 0 )
   {
      Scanner.SendKeys("Clocked in for " + sDays + " Day(s)! {Enter}");
      sCount = parseInt(sCount) - (24 * 3600 * sDays);
   }
 
   // calculate hours
   sHours = parseInt(sCount) / 3600;  
    
   if ( parseInt(sHours) > 0 )
   {
      sCount = parseInt(sCount) - (3600 * parseInt(sHours));
      sHours - Math.floor(parseInt(sHours));
   }
   else
   {
     sHours = 0;
   }
 
   // calculate minutes
   sMinutes = Math.round(parseInt(sCount) / 60);
     
} // end of function GetAndFormatHoursWorked()