Constructor
new GrabbaBarcode()
Access Grabba barcode capabilities via grabba.barcode
Members
preferences :GrabbaBarcodePreferences
Grabba barcode preference identifiers.
Type:
Methods
isSupported(onSuccess, onError)
Determines if the currently connected Grabba supports barcode functionality.
Parameters:
Name | Type | Description |
---|---|---|
onSuccess |
function | Called on success with the following parameters: {boolean} Boolean indicating if GrabbaBarcode is supported. |
onError |
function | Called on error with the following parameters: {String} error description. |
Example
//Button to check if the connected Grabba supports barcode functionality.
<button onclick="grabba.barcode.isSupported(function(supported){
alert('Grabba barcode supported is ' + supported);
},
function(errorString) {
alert('on error ' + errorString);
});">Is barcode supported?</button>
registerCallback(callback, onError)
Register callbacks for Barcode related events.
If no callbacks are passed to this function, all present callbacks will be cleared.
If no callbacks are passed to this function, all present callbacks will be cleared.
Parameters:
Name | Type | Description |
---|---|---|
callback |
Object | An object which implements the following functions: triggeredEvent : function(){} Called when the barcode scanner is triggered. timeoutEvent : function(){} Called when the barcode scanner has timed out. stoppedEvent : function(){} Called when the barcode scanner has stopped. scannedEvent : function(barcode){} Called when a barcode is scanned. The returned object contains properties as follows: {String} barcode.data The scanned barcode data. {String} barcode.symbology The scanned barcode's symbology. {int} barcode.symbologyInt Integer representation of the barcode's symbology. |
onError |
function | Called on error with the following parameters: {String} error description. |
Example
//An example of an implemented barcode callback is as follows:
grabba.barcode.registerCallback(barcodeCallbacks, onError);
var barcodeTimeoutFunction = function () {
alert('Barcode timed out');
};
grabba.barcode.registerCallback(barcodeCallbacks, onError);
var barcodeTimeoutFunction = function() {
alert('Barcode timed out');
};
var barcodeCallbacks = {
//Functions may also be declared inline as seen here.
triggeredEvent: function() {
alert('Barcode triggered');
},
//These functions are optional and unimplemented functions will simply not be called.
//stoppedEvent : function () {
//alert('Barcode scanning stopped');
//},
scannedEvent: function(barcode) {
//barcode contains data fields
alert('Barcode scanned event\n Data: ' + barcode.data + '\n' + "Symbology: " + barcode.symbology);
},
//You may create a function separately as seen with barcodeTimeoutFunction here.
timeoutEvent: barcodeTimeoutFunction
};
trigger(onError, enable)
Starts or stops barcode scanning.
To receive the barcode events and scanned data, first register for callbacks using GrabbaBarcode#registerCallback and then call:
To start the barcode scanner and scan the barcode.
To receive the barcode events and scanned data, first register for callbacks using GrabbaBarcode#registerCallback and then call:
grabba.barcode.trigger(onError, true)
To start the barcode scanner and scan the barcode.
Parameters:
Name | Type | Description |
---|---|---|
onError |
function | Called on error with the following parameters: {String} error description. |
enable |
boolean | Pass true to start scanning, false to stop. |
Example
<!--A button which starts the barcode scanning process-->
<button onclick="grabba.barcode.trigger(onError, true)">Trigger</button>