¶ How To Use kiwappLinea.jskiwappLinea.js is a kiwapp.js based labrary which provides you simple methods to use the Linea device. It can not work without Kiwapp.js loaded in your application. You have to initialize kiwapp before using the kiwappLinea methods. ¶ Initialize LineaOnce Kiwapp is initialized, you can create a Linea bridge. |
|
var linea = new KWLinea();
|
|
|
The your linea bridge will try to initialize a connection with the Linea device. This can success : |
linea.enabled === true;
|
|
Or this can fail : |
linea.enabled === false;
|
|
The linea bridge is an event emitter. This means it triggers events when he does something. You also can listen this events : |
linea.on('ready', function(){
console.log();
});
linea.on('error', function(type){
console.log(type);
});
|
|
To be sure of the Linea device enabling, we advice you to test connection before launching any action : |
linea.on('ready', function(){
console.log('You can safely call the linea bridge methods.');
});
linea.on('error', function(type){
if(type === 'connect'){
console.log('You can not call the linea bridge methods.');
}
});
linea.connect();
|
¶ ScanningThe main utility of the Linea device is scanning bar codes. There is options to customize the scan action. |
var configuration = {
|
|
The time in seconds before leaving the scanning mode : |
timeout : 5,
|
|
Enabling sound or not : |
sound : true,
|
|
Enabling the multiscan : |
multiscan : false
};
|
|
Scanning : |
linea.scan(configuration);
|
|
The scanning response is async, so you have to listen the 'scan:success' event to get the response. |
linea.on('scan:success', function(response){
console.log(response);
|
|
Exemple of scanning response : |
response = {
deviceId : '12UO920',
deviceType : 'LINEAV2.1',
deviceInfo : 'TYPE 445537',
|
|
Here is the bar code : |
deviceData : '445688278400058600'
}
});
linea.scan(configuration);
|
|
Like any method in the linea bridge, scanning can fail if the Linea device isn't ready. So you can listen the event 'scan:error' : |
linea.on('scan:error', function(){
console.log('Scan failed');
});
linea.scan(configuration);
|
|
You can stop scanning at any moment using this method : |
linea.stop();
|
¶ Linea managementThe linea bridge provides you some methods to manage the Linea device. |
|
|
To know about the battery current state : |
linea.battery();
|
|
The battery response is async, so you have to listen the 'battery:success' event to get the response. |
linea.on('battery:success', function(response){
console.log(response);
});
linea.battery();
|
|
This can fail if the Linea isn't enabled. So you can listen the event 'battery:error' : |
linea.on('battery:error', function(){
console.log('Getting battery informations failed');
});
linea.battery();
|
|
To enable/disable the physical Linea button on the right, you can use this method : |
var enabled = true;
linea.physicalButton(enabled);
|
|
This can fail if the Linea isn't enabled. So you can listen the event 'physicalButton:error' : |
linea.on('physicalButton:error', function(){
console.log('Enabling physical button failed');
});
linea.physicalButton(enabled);
|