Datalogic Cordova Plugin
Library that exposes the Datalogic Android (Java) SDK as a Cordova plugin. It lets you receive barcode data from the scanner, as well as configure various scanner and device settings. It is available as a npm package for easy consumption here: @datalogic/cordova-plugin-datalogic.
Installation
You can install the plugin from the npm
registry as follows:
npm i @datalogic/cordova-plugin-datalogic
...or use the following Cordova CLI command:
cordova plugin add @datalogic/cordova-plugin-datalogic
or, if you are using ionic, this ionic command:
ionic cordova plugin add @datalogic/cordova-plugin-datalogic
or, if you are using PhoneGap CLI, this phonegap command:
phonegap plugin add @datalogic/cordova-plugin-datalogic
## Publish new version
Install and use the [np tool](https://github.com/sindresorhus/np):
``` bash
npm install --global np
np
Sample apps
Several Ionic sample applications are provided to demonstrate using the plugin. You can find them here.
API Reference
All functions are asynchronous. All functions will, at a minimum, include successCallback
and errorCallback
parameters, both of which are callback functions.
-
successCallback
will be called in normal cases, and will return an appropriate JSONobject
. -
errorCallback
will be called when there was an error, and will return a single errorstring
.
Namespaces
Namespace | Description |
---|---|
barcodeManager | receive barcode data |
autoScanTrigger | work the the autoscan features |
keyboardManager | set usable device triggers |
ledManager | control device LEDs |
scannerProperties | define availabled symbologies |
barcodeManager
Function | Description |
---|---|
addReadListener | Register to recieve barcode data on each scan. |
pressTrigger | Simulate a trigger button press. |
releaseTrigger | Simulate a trigger button release. |
successCallback
, errorCallback
): Object
.addReadListener(Register to recieve barcode data on each scan. successCallback
will be called every time a barcode is successfully scanned. Therefore, you will typically only need to call barcodeManager.addReadListener()
once in your application.
Response
-
barcodeData
:string
- the barcode data scanned. -
barcodeType
:string
- will be one of theBarcodeID
values defined in the BarcodeID class in the Datalogic Android SDK.
{
"barcodeData": "EUG2997",
"barcodeType": "CODE128"
}
Example
declare let barcodeManager : any;
...
barcodeManager.addReadListner(
(data) => {
parsedData = JSON.parse(data);
alert(parsedData.barcodeData + ", " + parsedData.barcodeType);
},
(err)=>{ alert(err); }
);
successCallback
, errorCallback
): Object
.pressTrigger(Call this method to simulate a trigger button press. The method does not always immediately start a capture; instead it behaves like pressing a physical scan button.
Response
string
with success message
Example
barcodeManager.pressTrigger(
(data) => { alert(data); },
(err) => { alert(err);}
);
successCallback
, errorCallback
): Object
.releaseTrigger(Call this method to simulate a release of a trigger button. The method does not always immediately stop a capture; instead it behaves like releasing a physical scan button.
Response
string
with success message
Example
barcodeManager.releaseTrigger(
(data) => { alert(data); },
(err) => { alert(err);}
);
autoScanTrigger
Function | Description |
---|---|
isAvailable | Determine if the auto scan feature is available on this device. |
getSupportedRanges | Get the supported ranges of the autoscan feature. |
getCurrentRange | Get the current range of the autoscan feature. |
setCurrentRange | Set the current range of the autoscan feature. |
successCallback
, errorCallback
): Object
.isAvailable(Determine if the auto scan feature is available on this device.
Response
-
available
:boolean
- indicates if autoscan is supported or not on this device.
{ "available": true }
Example
declare let autoScanTrigger : any;
isAvailable : boolean = false;
...
autoScanTrigger.isAvailable(
(data) => {
this.isAvailable = JSON.parse(data).available;
alert(this.isAvailable);
},
(err) => { alert(err); }
);
successCallback
, errorCallback
): Object
.getSupportedRanges(Get the supported ranges of the autoscan feature.
Response
supportedRanges
: array
- provides array of ranges device supports. The array will be empty if device deos not support autoscan. Each object in the array contains:
-
id
:integer
- unique value for a step in the supported ranges -
name
:string
- descriptive text related to theid
If AutoScan is not supported by device:
{ "supportedRanges":[] }
If AutoScan is supported:
{
"supportedRanges":[
{
"id":0,
"name":"Near"
},
{
"id":1,
"name":"Intermediate"
},
{
"id":2,
"name":"Far"
}
]
}
Example
declare let autoScanTrigger : any;
autoScanTrigger.getSupportedRanges(
(data) => {
alert(JSON.parse(data).supportedRanges);
if(this.supportedRanges.length == 0)
alert("Device does not support Auto Scan");
},
(err) => { alert(err); }
);
successCallback
, errorCallback
): Object
.getCurrentRange(Get the current range of the autoscan feature.
Response
currentRange
: object
- contains 2 fields:
-
id
:integer
-
name
:string
If AutoScan is not supported by device:
{ "currentRange":null }
If AutoScan is supported:
{
"currentRange":
{
"id":1,
"name":"Intermediate"
}
}
Example
declare let autoScanTrigger : any;
autoScanTrigger.getCurrentRange(
(data) => {
alert(JSON.parse(data).currentRange);
},
(err) => { alert(err); }
);
id
, successCallback
, errorCallback
): Object
.setCurrentRange(Set the current range of the autoscan feature.
id
: integer
- should match one of the id
values retrevied by the getSupportedRanges function.
Response
string
with success message
Example
Set current range to "Intermediate"
autoScanTrigger.setCurrentRange(
0,
(data) => { alert(data); },
(err) => { alert(err); }
);
keyboardManager
Function | Description |
---|---|
getAllAvailableTriggers | Get all the available triggers of the device. |
setAllAvailableTriggers | Set all the devices triggers on or off. |
setTriggers | Set one or more triggers on or off. |
successCallback
, errorCallback
): Object
.getAllAvailableTriggers (Get all the available triggers of the device.
Response
triggers
: array
- each object in the array contains:
-
enabled
:boolean
-
id
:integer
-
name
:string
Typical resopsnse:
{
"triggers":[
{
"enabled":true,
"id":3,
"name":"Front Trigger"
},
{
"enabled":false,
"id":4,
"name":"Auto Scan Trigger"
},
{
"enabled":false,
"id":5,
"name":"Motion Trigger"
}
]
}
Example
keyboardManager.getAllAvailableTriggers(
(data) => { alert(JSON.parse(data).triggers); },
(err) => { alert(err); }
);
enable
, successCallback
, errorCallback
): Object
.setAllAvailableTriggers(Set all the devices triggers on or off.
Response
string
with success message
Example
Turn all triggers on.
keyboardManager.setAllAvailableTriggers(
true,
(data) => { alert(data); },
(err) => { alert(err); }
);
config
, successCallback
, errorCallback
): Object
.setTriggers(Set one or more triggers on or off. You will likely call getAllAvailableTriggers
, edit the enabled
flags of each returned object as desired, and then resubmit by calling setTriggers
.
config
: array
- each ojbect in the array represents an individual trigger. Each object in the array contains:
-
id
:integer
-
enabled
:boolean
Response
string
with success message
Example
//an array os supported triggers
triggers:{id: number, name: string, enabled: boolean}[] = [];
...
keyboardManager.getAllAvailableTriggers(
(data) => {
this.triggers = JSON.parse(data).triggers;
this.triggers[0].enabled = false;
keyboardManager.setTriggers(
this.triggers,
(data) => { alert(data); },
(err) => { alert(err);}
);
},
(err) => { alert(err); }
);
ledManager
Function | Description |
---|---|
setLed | Set various device LEDs. |
ledConfig
, successCallback
, errorCallback
): Object
.setLed(Set the various device LEDs. A list of enum values for LEDs can be found here.
Response
string
with success message
Example
ledManager.setLed({"led": "LED_GOOD_READ", "enable": false}, null, null);
scannerProperties
Function | Description |
---|---|
edit | Get a list of supported properties along with the state of each (enabled or disabled). |
store | Apply changes to one or more properties with the values supplied. |
successCallback
, errorCallback
): Object
.edit(Get a list of supported scanner properties along with the state of each (enabled or disabled).
Response
A single JSON object containing an object for each of the available symbologies. Each symbology contains, at a minimum, these fields:
-
enable
:boolean
- if scannner is set to detect this barcode type or not -
supported
:boolean
- if the scanner supports the given barcode type or not
{
"keyboardWedge":{"enable":true,"supported":true},
"aztec":{"enable":true,"supported":true},
"codabar":{"enable":true,"supported":true},
"code128":{"enable":true,"supported":true},
"code39":{"enable":true,"supported":true},
"code93":{"enable":false,"supported":true},
"composite":{"enable":false,"supported":true},
"datamatrix":{"enable":true,"supported":true},
"digimarc":{"enable":false,"supported":false},
"discrete25":{"enable":false,"supported":true},
"ean13":{"enable":true,"supported":true},
"ean8":{"enable":true,"supported":true},
"gs1DataBar_14":{"enable":true,"supported":true},
"gs1DataBar_Expanded":{"enable":true,"supported":true},
"gs1DataBar_Limited":{"enable":true,"supported":true},
"interleaved25":{"enable":true,"supported":true},
"matrix25":{"enable":false,"supported":true},
"maxicode":{"enable":false,"supported":true},
"microQr":{"enable":false,"supported":true},
"micropdf417":{"enable":false,"supported":true},
"msi":{"enable":false,"supported":true},
"p4State":{"enable":false,"supported":true},
"pAus":{"enable":false,"supported":true},
"pJap":{"enable":false,"supported":true},
"pKix":{"enable":false,"supported":true},
"pPlanet":{"enable":false,"supported":true},
"pPostnet":{"enable":false,"supported":true},
"pRM":{"enable":false,"supported":true},
"pdf417":{"enable":true,"supported":true},
"qrCode":{"enable":true,"supported":true},
"upcA":{"enable":true,"supported":true},
"upcE":{"enable":true,"supported":true}
}
Example
properties : any = {};
...
scannerProperties.edit(
(data) => {
this.properties = JSON.parse(data);
this.aztec = false;
this.codabar = false;
this.code128 = true;
this.keyboardWedge = false;
},
(err) => { alert(err); }
);
properties
, successCallback
, errorCallback
): Object
.store(Apply changes to one or more symbologies with the values supplied in properties
.
Response
string
with success message
Examples
Enable UPC-E symbology
scannerProperties.store({"upcE":{"enable":true,"supported":true}}, null, null);
Disable keyboard wedge feature
scannerProperties.store({"keyboardWedge":{"enable":false}}, null, null);