This demonstration will show the ability to enable / disable the Datalogic scanner.
This demo is set to use the listen function and place the scanned data in the field labeled "First Name".
This demo is using the GSW Datalogic Scanner plugin.
var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};
GSW.Tests.onGswScannerReady = function() {
// Cordova is now initialized. Have fun!
console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
navigator.gswdatalogicscanner.initialize(function(data) {
console.log('initialize OK');
navigator.gswdatalogicscanner.listen(function(result) {
document.getElementById('userid').value = result.data;
document.getElementById('code_type').value = result.code_type;
document.getElementById('timestamp').value = result.timestamp;
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.gswdatalogicscanner.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.gswdatalogicscanner.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);
})
});
navigator.gswdatalogicscanner.getSymbologyState("UPCA", function(enabled) {
var el = document.getElementById('chk_upca');
el.checked = enabled;
el.addEventListener("change", function(e) {
navigator.gswdatalogicscanner.setSymbologyState("UPCA", e.target.checked, function(result) {
console.log("UPCA set to " + (e.target.checked ? "on" : "off"));
}, function(error) {
console.log('Unable to configure UPCA: ' + error);
});
});
}, function(error) {
console.log('Unable to configure UPCA: ' + error);
});
navigator.gswdatalogicscanner.getSymbologyState("Code128", function(enabled) {
var el = document.getElementById('chk_code128');
el.checked = enabled;
el.addEventListener("change", function(e) {
navigator.gswdatalogicscanner.setSymbologyState("Code128", e.target.checked, function(result) {
console.log("Code128 set to " + (e.target.checked ? "on" : "off"));
}, function(error) {
console.log('Unable to configure Code128: ' + error);
});
});
}, function(error) {
console.log('Unable to configure Code128: ' + error);
});
}, function(error) {
console.log('Initialize error occured: ' + error);
document.getElementById("enable_trigger").disabled = true;
document.getElementById("disable_trigger").disabled = true;
if (error == "datalogic scanner decode service is unavailable on this device") {
let notice = document.getElementById("noticeContainer");
notice.style.display = "block";
document.getElementById("error").innerHTML = "This device was not manufactured by Datalogic and is not compatible with this demo."
} else console.log('Initialize error occured: ' + error);
});
}
document.addEventListener('gswscannerready', GSW.Tests.onGswScannerReady, false);