A Quicker Way To Enable/Disable Bar Code Scanning

Robert Galvin -
3 MIN READ
192
2

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';

   "http://www.w3.org/TR/html4/loose.dtd">

          

          Webinar Test

          

          

          

          

 

          

          

                    

                    

                    

                    

                    

 

          

profile

Robert Galvin

Please Register or Login to post a reply

2 Replies

r roberto cottone

I had try above code but i got error : - ReferenceError: Can't find variable: scanner

r roberto cottone

Can't find variable: scanner. PLease.