mribbons / cordova-plugin-cipherlab-rs30

Apache Cordova Barcode Scanner Plugin for Cipherlab RS30
MIT License
6 stars 12 forks source link

The scanner scan more than once. #7

Closed gcivicodev closed 7 years ago

gcivicodev commented 7 years ago

Hi @mribbons I am using ionic. html `

` controller

    $scope.scan = function() {
        $ionicPlatform.ready(function() {
            document.getElementById("scan_button").addEventListener('click', function () {
                cordova.plugins.CipherlabRS30CordovaPlugin.requestScan(function () {
                    // MDR 30/11/2015 - This is just a placeholder callback. Results will be handled by setReceiveScanCallback() parameter below
                });
            });

            cordova.plugins.CipherlabRS30CordovaPlugin.initialise(function () {

                cordova.plugins.CipherlabRS30CordovaPlugin.setReceiveScanCallback(function (data) {

                    alert('Barcode ID |> ' + data);
                    /* recordScanHistory */
                });

            });

            window.onbeforeunload = function () {
                cordova.plugins.CipherlabRS30CordovaPlugin.destroy(function () { });
            }
        });
    }

The scanner works fine. But after first scan, it continuing scan several times. For example, the alert is shown 2 to 10 times.

gcivicodev commented 7 years ago

Hi @mribbons

I update the controller like this:

    $scope.scan = function() {
        $ionicPlatform.ready(function() {
                cordova.plugins.CipherlabRS30CordovaPlugin.requestScan(function () {
                    // MDR 30/11/2015 - This is just a placeholder callback. Results will be handled by setReceiveScanCallback() parameter below
                });

            cordova.plugins.CipherlabRS30CordovaPlugin.initialise(function () {

                cordova.plugins.CipherlabRS30CordovaPlugin.setReceiveScanCallback(function (data) {

                    alert('Barcode ID |> ' + data);
                    cordova.plugins.CipherlabRS30CordovaPlugin.destroy(function () { });
                });

            });
        });
    }

But the problem continues. Scans several times before finish. The alert is show 2 to 10 times, so any code inside will be run several times.

gcivicodev commented 7 years ago

Hi @mribbons

I solved the problem as follows: controller

    $scope.scan = function() {
        $ionicPlatform.ready(function() {
            var _scan = true;

            cordova.plugins.CipherlabRS30CordovaPlugin.requestScan(function () {
                // MDR 30/11/2015 - This is just a placeholder callback. Results will be handled by setReceiveScanCallback() parameter below
            });

            cordova.plugins.CipherlabRS30CordovaPlugin.initialise(function () {

                cordova.plugins.CipherlabRS30CordovaPlugin.setReceiveScanCallback(function (data) {
                    /*get the barcode data ie. 45879hg55\n*/
                    if(_scan) {
                        console.log('Barcode ID |> ' + data);
                        _scan = false;
                    }
                    cordova.plugins.CipherlabRS30CordovaPlugin.destroy(function () { });
                });

            });
        });
    }
mribbons commented 7 years ago

Your solution looks a bit short term in that it will only allow one scan.

I don't have an RS30 to test with at the moment.

Can you post a sample project?

I will attempt to reproduce when I have a unit to test with.

mribbons commented 7 years ago

Hi @gcivicodev, Could you kindly provide a logcat output. The logcat should be inclusive of app start, barcode scan and app exit.

It would also be better if the log was made with the bad version of your app where multiple scans occur.

mribbons commented 7 years ago

Closing issue due to no activity.

@gcivicodev has found a work around, but it doesn't look right to me.

gcivicodev commented 7 years ago

Hi @mribbons

Excuse me, I was very busy. Lamentably I do not have the old version to share. But I open a new issue https://github.com/mribbons/cordova-plugin-cipherlab-rs30/issues/8 with a different problem and similar code.