After my webinar yesterday on the SB1 application development, a co-worker came to me asking if there was a faster way to enable the scanner on the device. Before I get into what we ended up doing, let me discuss the current way most people enable and disable the barcode scanner using RhoElements. In our Scanner API we have the .enable() and .disable() methods. When you do:

 

// Javascript
scanner.enable();

 

Doing the above effectively goes through a series of events to power up and initialize the lower level scanning subsystem on the device. Then when you want to disable the scanner you would typically dp:

 

//Javascript
scanner.disable();

 

Normally this does not take very long, but if you have to constantly turn the scanner on/off between fields on a form or between pages, the time it takes to go through the full "enable" cycle may be too long for certain conditions. Remember, we have the decodeEvent where we process the scanned data. We could just choose to ignore the scanned data when we want in our code, but the user would still be able to scan bar codes and hear the scanner beep. What we really want to do is to keep most of the scanning subsystem "ready" but not allow the user to scan any barcodes or appear that it is capable of scanning. Then when we want it to accept bar codes, we need to make it "ready" faster then the full scanner.enable() method.

 

THE SOLUTION

One way to do this is to not use the scanner.disable() method, but instead disable it's capability from accepting bar codes as well as disable any visual indicators like aimers and illumination. Now on my SB1 it has a 2D imager with just an illuminator (no scan 'aimer'). So basically this is what I would do to 'disable' the scanner instead:

 

//Javascipt
function disableScanner(){
          scanner.illuminationMode="alwaysOff";
          scanner.allDecoders="disabled";       
}

Then when I want to re-enable the scanner I would set the illuminator (the red area that lights up the scan area. This is different then the 'aimer' of the red lines/cross hairs). I would also re-enable the decoders so that the scan engine accepts the bar codes it sees

//Javascript
function enableScanner(){
          scanner.illuminationMode="auto";
          scanner.allDecoders="enabled";     // or just re-enable the symbologies you need for even faster performance

}

 

You just have to make sure you call scanner.enable() once when the application initially loads. Then in your subsequent pages/form fields use the above methods to disable/re-enable.

 

The full page that I used on my SB1 is below. If you rapidly click the scan button on the device as you re-enable the scanner, you will visually see a difference in the illumination coming on and it being 'ready' to scan bar codes. Just remember to touch 'Enable Slow' if you clicked 'Disable Slow' before trying the 'Enable/Disable Fast' buttons. The same concept should apply to other devices (I did not verify this), although you will need to account for other device scanning capabilities. For example, on a MC9500 that has a laser 1D scanner, you would also turn off the aimer by doing scanner.aimMode='none'; and then to turn the aimer back on do scanner.aimMode='slab';

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">


<html lang="en">
<head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
          <title>Webinar Test</title>
          <link href="css/asl.css" rel="stylesheet" type="text/css" media="screen, projection" />
          <script type="text/javascript" src="js/asl.js"></script>
          <script type="text/javascript">


asl.back(function(){
          //do something
          location.reload(true);
          }, 'resources/reload.png');


asl.title("Scanner Demo");


asl.events.subscribe(asl.events.types.loaded, function(){
                              // alert('page is loaded');
                                                            scanner.enable();
                                                            scanner.decodeEvent = 'decodeEvent(%json)';
                                                            document.getElementById('content').innerHTML = 'Scanner Enabled';
                    });
function decodeEvent(jsonObject)
                    {
                              var scandata = jsonObject.data;
                              document.getElementById('content').innerHTML = scandata;


  
                    }


asl.events.subscribe(asl.events.types.cradleInsert, function(e) {
  
                              alert('inserted');
        });


function disableScanner(){
          scanner.illuminationMode="alwaysOff";
          scanner.allDecoders="disabled";
          document.getElementById('content').innerHTML = 'Decode Off';


}


function enableScanner(){
          scanner.illuminationMode="auto";
          scanner.allDecoders="enabled";
          document.getElementById('content').innerHTML = 'Decode On';




}
          </script>
</head>
<body >
          <div class="content" id="content">


  
          </div>
          <div>
                    <button class="button left" onClick="disableScanner();">Disable Fast</button>
                    <button class="button right" onClick="enableScanner();">Enable Fast</button>
                    <br/>
                    <button class="button left" onClick="scanner.enable();document.getElementById('content').innerHTML = 'Scanner Enabled';
">Enable Slow</button>
                    <button class="button right" onClick="scanner.disable();                                                            document.getElementById('content').innerHTML = 'Scanner Disabled';
">Disable Slow</button>
  
          </div>
</body>
</html>