BlueFletch / motorola-datawedge-cordova-plugin

This is a Cordova/Phonegap plugin to interact with Motorola ruggedized Android devices' Barcode Scanners and Magnetic Stripe Readers (eg, ET1, TC55, MC40). The plugin works by interacting with the "DataWedge" application configured to output scan and magstripe read events.
35 stars 38 forks source link

Cordova 5.4.0 with MC40 barcode event listener #11

Closed jrock2004 closed 8 years ago

jrock2004 commented 8 years ago

Using the newest version of cordova. I have the datawedge app installed on the phone and configured to point to my app. I am having a hard time building the register for the event listener for when I can a barcode. Any ideas on what I could be missing? Thanks

var resultDiv;

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
        document.querySelector("#startScan").addEventListener("touchend",
            app.startScan, false);
        resultDiv = document.querySelector("#results");

        console.log("Can I see this log !!!!!!!!!!");
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');

        datawedge.registerForBarcode(function(data) {
            console.log("Event!!!!!!!!!!!!!!");
        });
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    },
    startScan: function() {
        cordova.plugins.barcodeScanner.scan(
            function (result) {
                var s = "Result: " + result.text + "<br/>" +
                    "Format: " + result.format + "<br/>" +
                        "Cancelled: " + result.cancelled;
                        resultDiv.innerHTML = s;
            },
            function (error) {
                alert("Scanning failed: " + error);
            }
        );
    }
};

app.initialize();

Looking at logcat, when I do the scan and it finds something, this is what shows in the logs

D/libimgkit(  516): sysflags 35
E/V4LImagerAdapter(  516): Guard failed
E/NotificationService(  291): Ignoring notification with icon==0: Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x1 kind=[null])
E/TimeInterpolator(  123): Error: calling void android::TimeInterpolator::resume()() when not in PAUSED state
W/TimeInterpolator(  123): time is rewinding: -43450 Tf=1 t0=16849656860 pos0=-43480 dt=30 now=16849656890 last=0 now_last=0
D/AudioSpeexSRC(  123): AudioResamplerSpeex::reset()
E/V4LImagerAdapter(  516): Successfully sent 1 VIDIOC_S_EXT_CTRLS ioctl
I/ActivityManager(  291): START u0 {act=com.bluefletch.motorola.datawedge.ACTION flg=0x10000000 cmp=com.eBayEnterprise.picker/.MainActivity (has extras)} from pid 516
E/NotificationService(  291): Ignoring notification with icon==0: Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x1 kind=[null])
D/dalvikvm(30035): GC_CONCURRENT freed 578K, 8% free 9465K/10247K, paused 14ms+3ms, total 42ms
D/dalvikvm(  291): GC_CONCURRENT freed 1232K, 15% free 14785K/17287K, paused 23ms+8ms, total 225ms
alampa commented 8 years ago

Thanks for using our plugin. Did you miss calling start on the datawedge?

...
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);

    if (window.datawedge) {
         datawedge.start(); //uses default
         //datawedge.start("com.yourintent.whatever_you_configured_to_broadcast_in_default_profile");
    }
},
...
jrock2004 commented 8 years ago

I had the code in the wrong place. I had it placed where the code was unreachable because the function returned. It is now working for me.