Back to Demos List

GSW Scanner Listener

This demonstration will show the ability to enable / disable the scanner.

Interface Detected:


This demo is set to use the listen function and place the scanned data in the field labeled "User ID".







The fields below will contain the extra data captured by the scan.








About This Demo

This demo is using the GSW Scanner plugin. For more information click here:

 
var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};

GSW.Tests.onDeviceReady = function() {
    // Cordova is now initialized. Have fun!
    console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
    navigator.gswscanner.initialize(function(data) {
        console.log('initialize OK');
        document.getElementById("interface").innerHTML = navigator.gswscanner.api.bold();
        navigator.gswscanner.listen(function(result) {
            document.getElementById('userid').value = result.data;
            document.getElementById('character_set').value = result.character_set;
            document.getElementById('code_id').value = result.code_id;
            document.getElementById('aim_id').value = result.aim_id;
            document.getElementById('timestamp').value = result.timestamp;
            document.getElementById('label_type').value = result.label_type;
            document.getElementById('code_type').value = result.code_type;
            console.log('Scanned: ' + result.data + ', character_set: ' + result.character_set + ', code_id: ' + result.code_id + ', aim_id: ' + result.aim_id + ', timestamp: ' + result.timestamp);
        }, function(error) {
            console.log('Unable to listen: ' + error);
        });
        var enabled = true;
        document.getElementById("enable_trigger").disabled = true;
        document.getElementById("disable_trigger").disabled = false;
        document.getElementById('enable_trigger').addEventListener("click", function() {
            navigator.gswscanner.enableTrigger(function(result) {
                enabled = true;
                document.getElementById("enable_trigger").disabled = true;
                document.getElementById("disable_trigger").disabled = false;
                console.log('Trigger enabled');
            }, function(error) {
                console.log('Unable to enable trigger: ' + error);
            })
        });
        document.getElementById('disable_trigger').addEventListener("click", function() {
            navigator.gswscanner.disableTrigger(function(result) {
                enabled = false
                document.getElementById("enable_trigger").disabled = false;
                document.getElementById("disable_trigger").disabled = true;
                console.log('Trigger disabled');
            }, function(error) {
                console.log('Unable to disable trigger: ' + error);
            })
        });
    }, function(error) {
        console.log('Initialize error occured: ' + error);
        document.getElementById("enable_trigger").disabled = true;
        document.getElementById("disable_trigger").disabled = true;
        if (error == "Scanner api is unavailable on this device") {
            let notice = document.getElementById("noticeContainer");
            notice.style.display = "block";
            document.getElementById("error").innerHTML = "This device does not have a compatible scanner present, and is not compatible with this demo."
        } else if (error.indexOf('scanner decode service is unavailable on this device') != -1) {
            let notice = document.getElementById("noticeContainer");
            notice.style.display = "block";
            document.getElementById("error").innerHTML = "This device was not manufactured by a supported manufacturer and is not compatible with this demo."
        } else console.log('Initialize error occured: ' + error);
    });
}
document.addEventListener('gswscannerready', GSW.Tests.onDeviceReady, false);