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>

Jonathan George
I am also facing similar

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...

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Nrusingha Patro
Hi,could you please provide

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

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jonathan George
Hi patro,i am using

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




Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Glenn Sayer
I have seen this with 2.2 and

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.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jonathan George
Hi Glenn,We are using 2.2.For

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 1 Header 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?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Thanks for raising this, we

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.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Pavol Bigos
Thanks Darryn, Please whene

Thanks Darryn,

Please whene will be the 1.0.2 avalieble ?

Unfortunately we found scenarios where an operator on site could scan 2 barcodes in a single input field which was causing operational issue.

Once we read the barcode we have to disable the scanner.

Thanks

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Chris Misztur
Do your barcodes start and

Do your barcodes start and end with a control character? If so, you could focus on the next field when you come across a control character, preventing the user from scanning two barcodes w/o moving to the next field.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Chris Eudy
Yes, that’s the post I was

Yes, that’s the post I was talking to you about on the way home the other day.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Pavol Bigos
No control character in these

No control character in these SSCC EAN128 code

We have to add the ENTER when needed and first we replace one char(29) with a new char ([ )…

By the time the focus moves (javascript) the asynchronous callback function of scanner is faster and 2 barcodes can be entered in first input field…

Thanks for advice anyway.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Chris Misztur
I agree that toggling the

I agree that toggling the hardware continuously is bad practice.  The below code works for me (w/o toggling hardware between reads).  There is no reason why a double scan should happen.

function doScan(json)

{

     if ( $('#box1').is(":focus") )

     {

          $('#box1').val(json.data);

          $('#box2').focus().select();

     } else {

          $('#box2').val(json.data);

          $('#box1').focus().select();

     }

}

You will need to implement logic to either only scan into the focused textbox or some other method to keep track of what has been scanned.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
1.0.2 has currently just

1.0.2 has currently just completed Test and Validation and is due for release in the coming weeks.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments