2 Replies Latest reply on Jan 11, 2013 5:10 AM by Vinod Shankar K

    Barcode JS API returns empty result with RhoMobile Suite 2.2

      Tried to run the sample JS API project (rho-js-api-samples) after building it with RhoStudio (Suite 2.2) but the Rho.Barcode.take_barcode callback returns empty result instead of the scanned barcode text.

       

      Tested with a clean project too with following in index.erb. Still the same issue. (project code attached)

       

      Sample code:

      function barcodeScan(val)

      {

          alert(JSON.stringify(val));

      }

      <a href="#" onclick="Rho.Barcode.take_barcode(function(){barcodeScan(arguments[0]);}, {});" data-role="button" data-theme="a" style="max-width: 400px;">Scan Barcode</a>

       

      I am testing it on a Motorola Symbol MC55A with Win Mobile 6.5

      Am I missing something?

        • Re: Barcode JS API returns empty result with RhoMobile Suite 2.2
          Benedict Kennedy

          Sorry this isn't a direct answer to your question, but if you are programming for the MC55A I would suggest using the Scanner module rather than the "Barcode" module.

           

          This will allow you to take advantage of the more advanced Motorola barcode scanning engine which is much more customizable and higher performing than the Barcode module.

           

          An example of your code with the scanner module:

           

          var scannerTimeout;
          
          $(function() { //called on page load
               scanner.decodeEvent = 'barcodeScan(%json)'; //sets up the scanner callback
               scanner.enable(); //enables the scanner
          });
          
          function barcodeScan(jsonObject)
          {
               clearTimeout(scannerTimeout);
               alert(jsonObject.data);
          }
          
          function scanBarcode()
          {
               scanner.start();
               scannerTimeout = setTimeout(function(){scanner.stop}, 5000)//Stops the scanner after a period of time
          }
          

           

          and the HTML:

          <a href="#" onclick="scanBarcode()" data-role="button" data-theme="a" style="max-width: 400px;">Scan Barcode</a>
          

           

          This can also be done in Ruby. Details on this set of APIs can be found here: http://docs.rhomobile.com/rhoelements/scanner

           

          Also, by using scanner.enable() this automatically links the yellow scan buttons to the scanner, so that the hardware buttons can be used to initiate a scan as well as this soft button.

           

          My apologies if I am telling you information that you already know.


          Regards,

          Ben

           

          Minor update to a incorrect name in decodeEvent

          • Re: Barcode JS API returns empty result with RhoMobile Suite 2.2

            Hi

             

            I think you can try below code to display the barcode that scanned

             

                 function dumpValue(value, dumpLevel) {

                      dumpLevel = dumpLevel || 0;

                      var str = '';

                      if ("undefined" == typeof value)

                          str = str + 'undefined';

                      else if (null == value)

                          str = str + 'null';

                      else if (value instanceof Date)

                          str = str + value;

                      else if ('object' == typeof value) {

                          var tabStr = tab(dumpLevel);

                          str = str + '{\n'

                          for (var fld in value) {

                              str = str + tabStr + fld + ': ' + dumpValue(value[fld], dumpLevel+1) +'\n';

                          }

                          str = str + tab(dumpLevel-1) + '}'

                      } else {

                          str = str + value;

                      }

                      return str;

                  }

             

             

                  function barcodeScan(value) {

                      alert ('result: ' + dumpValue(value, 1));

                  }

             

            <a href="#" onclick="Rho.Barcode.take_barcode(function(){barcodeScan(arguments[0]);}, {});" data-role="button" data-theme="a" style="max-width: 400px;">Scan Barcode</a>