This plugin has a known issue on Marshmallow devices & above where the scanner will not re-enable after the device has gone into and out of standby mode. Some developers have disabled & re-enabled the scanner in the onPause() / onResume() functions to get around this however I would recommend using a different approach to this problem as demonstrated in my DataWedgeCordova repository and accompanying blog post
This plugin defines an enterpriseBarcode
object which provides an API for interacting with the hardware scanner on Zebra devices. The enterpriseBarcode object is not available until after the deviceready
event.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(enterpriseBarcode);
}
cordova plugin add https://github.com/darryncampbell/EnterpriseBarcodePoC.git
Requires Cordova 5.0 or higher otherwise your application will get build errors. When updating from a previous Cordova version it is necessary to re-add this plugin
Returns the available hardware scanners on the device
enterpriseBarcode.enumerate(enumerateSuccess, enumerateFailure);
The enterpriseBarcode.enumerate
function queries the device hardware for available scanners and returns them through the success callback
Barcode functionality is only available for Zebra mobile devices.
Output the available scanners to the console
enterpriseBarcode.enumerate(
function(scannersObj)
{
for(scanner in scannersObj.scanners)
{
console.log("Scanner: " + scanner.friendlyName);
}
},
function(status)
{
console.log("Failed to Enumerate Scanners: " + status.message);
}
);
The Scanners are also available through the enterpriseBarcode.scanners
property after the device ready event.
for(scanner in enterpriseBarcode.scanners)
{
console.log("Scanner: " + scanner.friendlyName);
}
Optional parameters to customize the Scanner settings can be provided either through the setProperties
method or through the enable
method. These settings will persist until the application is closed.
{ code11Enabled : true,
code128Enabled : true,
code39Enabled : false,
code93Enabled : false,
dataMatrixEnabled : false,
ean8Enabled : true,
ean13Enabled : true,
upcaEnabled : true,
upce1Enabled : false,
pdf417Enabled : true,
friendlyName : '2D Barcode Imager'};
Not all barcode scanners will support all symbologies, for instance 2D symbologies like PDF417 will not be supported on 1D laser scanners.
Enables the barcode scanner hardware and the associated trigger, so pressing the hardware trigger will initiate a scan.
enterpriseBarcode.enable(enableSuccess, enableFailure, barcodeOptions);
The Enable method will instruct the scanning hardware to initialise and attach the trigger that can subsequently be used to initiate a scan. The success callback is called firstly to indicate that the scanner has successfully enabled and subsequently on each barcode scan (see example)
enterpriseBarcode.enable(
function(scannedObj)
{
if (scannedObj.status == "enabled")
console.log("Scanner has successfully enabled");
else
{
console.log("Scan Data: " + scannedObj.data);
console.log("Scan Symbology: " + scannedObj.type);
console.log("Scan Time: " + scannedObj.timestamp);
}
},
function(status)
{
console.log("Enable Failure: " + status.message);
},
{
'friendlyName':'2D Barcode Imager'
}
);
Disables the currently enabled barcode scanner hardware and disconnects the associated trigger.
enterpriseBarcode.disable(disableSuccess, disableFailure);
The Disable method will instruct the currently enabled scanning hardware to deinitialise. Calling disable
without having previously enabled a scanner will have no effect.
enterpriseBarcode.disable(
function(status)
{
console.log("Disable Success: " + status.message);
},
function(status)
{
console.log("Disable Failure: " + status.message);
}
);
Sets any of the properties listed under barcodeOptions to the currently enabled scanner. If there is no currently enabled scanner then this method has no effect.
enterpriseBarcode.setProperties(
function(status)
{
console.log("Set Properties Success: " + status.message);
},
function(status)
{
console.log("Set Properties Failure: " + status.message);
},
{
'code11Enabled':true,
'code39Enabled':false
}
);
Retrieves the properties listed under barcodeOptions from the currently enabled scanner. If there is no currently enabled scanner then this method has no effect.
enterpriseBarcode.getProperties(
function(props)
{
document.getElementById("code11Check").checked = props.code11Enabled;
document.getElementById("code39Check").checked = props.code39Enabled;
},
function(data)
{
console.log("Get Properties Failure: " + status.message);
}
);