12 Replies Latest reply on Nov 8, 2013 12:13 AM by Jonathan George

    MC9190 RHOELEMENTS SCANNER MULTIPLE ENABLE/DISABLE

      Hello

       

      Customer has an application that requires to disable scanner when input fields lose focus and scanner is re-enabled when focus is activating an input field again.

       

      if you try to enable/disable in javascript or with html meta-tags the rhoElements crashes.

       

       

       

      Click 30 to 50 times alternatively on enable/disable button- see result with MC9190-G WM6.5.3

      Speed of Crashes seems related to speed of toggling from enable to disable

       

      Please see and check with sample :

       

      <!DOCTYPE html>

      <HTML>

      <HEAD>

                          <TITLE> Scan Test </TITLE>

      </HEAD>

      <BODY >

       

      <script>

       

      var str1="";

       

      function encodeToHexa(str){

          var r="";

          var e=str.length;

          var c=0;

          var h;

          while(c<e){

              h=str.charCodeAt(c++).toString(16);

              while(h.length<3) h="0"+h;

              r+=h;

          }

          return r;

      }

      function decodeFromHex(str){

          var r="";

          var e=str.length;

          var s;

          while(e>=0){

              s=e-3;

              r=String.fromCharCode("0x"+str.substring(s,e))+r;

              e=s;

          }

          return r;

      }

      function shownormal(str){

                document.getElementById("Data_Normal").innerHTML = str; //show data on page

       

      }

      function showhexa(str){

                document.getElementById("Data_Hexa").innerHTML = str; //show data on page

       

      }

      function showmodified(str){

                document.getElementById("Data_Modified").innerHTML = str; //show data on page

       

      }

       

      function enableScanner(){

                scanner.decodeEvent = 'doScan(%json)';  //setup event handler

                scanner.enable(); //enable the scanner - the first available scanner will be enabled

      }

      function disableScanner(){

                scanner.disable(); //enable the scanner - the first available scanner will be disabled

      }

       

      function replacefunc(str){

       

          var newstr = str.replace(String.fromCharCode(29),"[");

          return newstr;

      }

       

      function doScan(jsonObject){

       

                shownormal(jsonObject.data);

       

                var str2 = encodeToHexa(jsonObject.data);

                showhexa(str2);

       

                //This is the function we need to use new barcode = jsonObject.data.replace(String.fromCharCode(29),"[");

                var str3 = replacefunc(jsonObject.data);

                showmodified(str3);

      }

       

      </script>

       

      </br>

      </br>

      </br>

                <div id="Data_Normal">Barcode goes here</div>

                <div id="Data_Hexa">Barcode in HEXA data goes here</div>

                <div id="Data_Modified">data with char(29) replacement goes here</div>

      </br>

                <button onClick="enableScanner()">  Enable Scanner </button>

      </br>

                <button onClick="disableScanner()">  Disable Scanner  </button>

       

      </BODY>

       

      </HTML>

        • Re: MC9190 RHOELEMENTS SCANNER MULTIPLE ENABLE/DISABLE
          Darryn Campbell

          Thanks for raising this, we saw a similar issue a few days ago with enabling the scanner repeatedly in a tight 300ms loop causing RhoElements to crash.  The latest code (due for release as 1.0.2) will not crash with your example above.

           

          Generally speaking it's not a good idea to be enabling / disabling the scanner as it is initialising / de-initialising scanner hardware, submitting / clearing reads e.t.c so you are adding latency to your program.

          • Re: MC9190 RHOELEMENTS SCANNER MULTIPLE ENABLE/DISABLE

            I am also facing similar issue of barcode gets appended in the text field when the user try to scan data using MC9190 device. But rather using scanner.enable or disable multiple times we are using scanner.alldecoders('enable') or disable.

            We are using Rhomobile 2.0 for our project.

            Any idea about how to prevent this scenario...

              • Re: MC9190 RHOELEMENTS SCANNER MULTIPLE ENABLE/DISABLE

                Hi,

                 

                could you please provide your code snippet.

                 

                scanner.alldecoders = 'enabled' should be mentioned this way


                which enables all the decoders to be decoded.


                and I feel it's good to have separate thread for this issue as the current thread seems to be very old and for 1.0 version of rhoelemnts.


                are you using Rhoelements 2.2 or 2.0??


                Regards,

                Patro

                  • Re: MC9190 RHOELEMENTS SCANNER MULTIPLE ENABLE/DISABLE
                    Glenn Sayer

                    I have seen this with 2.2 and was caused by the page being loaded several times and thus setting several decodeEvent's.  Make sure the decodeEvent is only being set once.

                      • Re: Re: MC9190 RHOELEMENTS SCANNER MULTIPLE ENABLE/DISABLE

                        Hi Glenn,

                        We are using 2.2.

                        For each cycle of scanning barcode and then save the form we call two erb pages and corresponding actions.

                        Header 1Header 2
                        new.erb

                        Scanner.decodeEvent = url_for(:action => :decodeEventNew)

                        Scanner.allDecoders=enabled;

                        edit.erb

                        Scanner.decodeEvent = url_for(:action => :decodeEventUpdate)

                        Scanner.allDecoders=('enable');

                         

                        when the first time page is loaded new action has been called

                         

                        def new

                        Scanner.decodeEvent = url_for(:action => :decodeEventNew)

                        Scanner.allDecoders=enabled;

                        ......

                        render :action => :new, :back =>'/app/Users'

                          end

                        and new.erb has been loaded

                        In new.erb user scan the barcode and submit the form through

                        form.submit();

                        The  page is submitted and it calls the edit action

                         

                        def edit

                        Scanner.decodeEvent = url_for(:action => :decodeEventNew)

                        Scanner.allDecoders=enabled;

                        ......

                        render :action => :edit, :back =>'/app/Users

                          end

                        edit.erb has been loaded

                        In edit.erb user scan the barcode and submit the form through ajax

                        $(form).ajaxSubmit

                        Here only the required field is submitted.
                        So for a complete cycle we are setting the decodeevent twice.
                        Once for new.erb and second for edit.erb. After that we remain on the same page.

                         

                        Any way to nullify the effect of setting decodeEvent multiple times?

                      • Re: MC9190 RHOELEMENTS SCANNER MULTIPLE ENABLE/DISABLE

                        Hi patro,
                        i am using RhoElement 2.2.


                        Code Snippet:


                        Scanner.decodeEvent = url_for(:action => : decodeEventUpdate)

                        Scanner.allDecoders=enabled;

                         

                        --------------------------------------------------------------

                         

                        def decodeEventUpdate

                                barcode = @params['data']

                                WebView.execute_js("scanAndUpdate('"+barcode+"'); ")   

                          end

                        ----------------------------------------------------------------------------------------------------

                         

                        function scanAndUpdate(barcode){

                        check = document.getElementById('Check').value

                        shelf = document.getElementById('Shelf').value.trim()

                        box = document.getElementById('Box').value.trim()

                        if(check =='on'){

                        if(shelf == ''){

                        document.getElementById('Shelf').value = barcode;

                        shelf = barcode;

                        }else if(box == ''){

                        document.getElementById('Box').value = barcode;

                        box = barcode;

                        }

                        if(shelf != '' && box != '' ){

                        document.getElementById('formSubmit').click();

                        }

                        }else{

                        1. document.getElementById('Box').value = barcode;

                        document.getElementById('formSubmit').click();

                        }

                          }




                        In the above code snippet we are submitting the page through ajax call:

                        $(form).ajaxSubmit