Inherits TiProxy.

Public Member Functions

void initialize ()
 
void setTimeout (String fromState, String toState, float timeoutInSeconds)
 
void removeTimeoutFromState (String fromState)
 

Public Attributes

Map< String, Object > scanSettings
 
String state
 
Callback didInitialize
 
Callback didScan
 
Callback didChangeState
 
boolean volumeButtonToScanEnabled
 

Detailed Description

Exposes the scan case API to JavaScript.

The scan case API allows you to conveniently scan barcodes with the Scandit scan case without showing a camera preview.

This functionality is currently only available on iOS.

Since
5.1.0

Minimal example to set up the scan case and start scanning.

// Load the Scandit SDK module.
var scanditsdk = require("com.mirasense.scanditsdk");
// First set the app key and which direction the camera should face.
scanditsdk.appKey = "-- ENTER YOUR SCANDIT LICENSE KEY HERE --";
// create a new scan case which allows to scan EAN13, UPCA and QR codes.
var scanCase = scanditsdk.createScanCase({
didScan : function(event) {
alert('scanned code: ' + event.newlyRecognizedCodes[0].data);
// after a successful scan, put the scanner in standby mode.
return 'standby';
},
didChangeState : function(event) {
console.log(event.newState, event.reason);
},
didInitialize : function() {
// once initialized, activate the scanner by setting its state to
// active.
scanCase.state = 'active';
},
symbologies : ['ean13', 'upca', 'qr' ]
}
});
// Initialize the scan case. This call is required before you can set
// timeouts.
scanCase.initialize();
// Define that the scanner should turn itself off after 5.0 seconds in
// standby mode.
scanCase.setTimeout('standby', 'off', 5.0);

Member Function Documentation

void initialize ( )

Initialize the scan case.

This method must be called before the scan case can be used. It's adviced to call this method only after you have configured all the callbacks and configured the scanner.

Since
5.1.0
void setTimeout ( String  fromState,
String  toState,
float  timeoutInSeconds 
)

Configure automatic state switches after a certain timeout.

By default, the scan case will remain in the current state forever. For certain scenarios it's useful to switch the scan case into standby mode after a timeout to preserve battery.

Parameters
fromStatethe starting state. Must either be 'active', 'off', or 'standby'.
toStatethe new state for the scan case after the timeout. Must either be 'active', 'off', or 'standby'.
timeoutInSecondsTimeout in seconds after which to switch from fromState to toState.
Since
5.1.0
void removeTimeoutFromState ( String  fromState)

Remove a previously set timeout.

Remove a previously set timeout to avoid starting a new timer when the state is change to fromState. In case there is no timeout set for the state, this method has no effect.

Parameters
fromStateThe state from which the timer would start, previously to calling this method.
Since
5.1.0

Member Data Documentation

Map<String, Object> scanSettings

The scan setting to be used for the scan case.

By default, all symbologies are disabled. You need to explicitly enable the symbologies you would like to scan.

Since
5.1.0
String state

The state of the scan case.

This property gives you access to the current state, and allows you to change the scan case state by setting it to a new value. After initialization the default state is 'standby'. You need to switch to 'active' to scan codes.

The scan case is always in one of 3 states. 'off', 'active', or 'standby'.

  • When in 'off' state, the scanner is inactive, the camera and torch are turned off. No scanning is possible.
  • When in 'standby' state, the camera is in standby mode, the torch is turned off. The scanner is ready to quickly switch to 'active' state.
  • When in 'active' state, the camera is running and the scanner is scanning codes.
Since
5.1.0
Callback didInitialize

Method invoked when the scan case has finished initialization.

This callback is invoked as soon as the scan case has completed the initialization process and the scanner is ready to be used. The callback is invoked with zero arguments.

Since
5.1.0
Callback didScan

Method invoked whenever a new code is scanned.

This callback is called when the barcode scanner has recognized new barcodes/2D codes. The callback will receive one object as an argument containing the list of codes recognized in the last frame in newlyRecognizedCodes. By default, scanning continues after a code has been scanned. If you want to pause scanning, you can return the new desired state from this function, e.g. 'standby' to put the scanner in standby state, or 'off' to completely turn off the scanner to conserve battery.

Since
5.1.0
Callback didChangeState

Method invoked whenever the scan case changes state.

This callback is invoked with an event argument whenever the scan case changes state. The event has 2 attributes: newState is the new state that the scan case is in, reason is the reason for the state transition. Possible values for the reason attribute are:

  • 'manual' when the state was switched programmatically through either setting the scan case's state property, or by changing the scan case state from the didScan callback.
  • 'timeout' when the state was switched through one of the timeout timers.
  • 'volumeButton' when the state was switched through pressing the volume button.
Since
5.1.0
boolean volumeButtonToScanEnabled

Whether volume button should be used for controlling the scanning.

When enabled, the scanner automatically switches to 'active' when the volume button is pressed and switches to 'standby' once it is released.

Since
5.1.0