DSScanner Methods


Creates and initializes barcode scanner object. This method creates a video element (and others) inside the HTML element with the ID "ScannerSettings.viewport.id", initializes all inside variables of the DSScanner object, initializes the WebAssembly library (datasymbol-sdk.wasm). After the scanner is created (onScannerReady event), you can start scanning (StartScanner).

Syntax
DSScanner.Create(scannerSettings);
Parameters
  • scannerSettings - ScannerSettings object that defines all scanner properties
Return Value
No return value.
Example
var scannerSettings = {
	viewport: {
		id: 'datasymbol-barcode-viewport',
		width: 640,	//null means 100% width
	},
	camera: {
		resx: 640,
		resy: 480,
	},
	barcode: {
		barcodeTypes: ['Code128', 'DataMatrix'],
	},
};

DSScanner.addEventListener('onError', onError);
DSScanner.addEventListener('onBarcode', onBarcodeReady);

DSScanner.addEventListener('onScannerReady', function () {
	DSScanner.StartScanner();
});

DSScanner.Create(scannerSettings);
Note




Starts the scanning cycle of frames. To save energy (especially it is important for mobile devices), there is a pause between scanning frames that is specified by the parameter "ScannerSettings.scanner.FrameTimeout". By default the pause makes 100ms, you can change this value depending on your requirements.

Syntax
DSScanner.StartScanner();
Return Value
No return value.
Note




Stops the frame scanning cycle. The object of the scanner itself DSScanner is completely ready for use, and you can immediately restart scanning (StartScanner method).

Syntax
DSScanner.StopScanner();
Return Value
No return value.
Note




Adds handlers for various events

Syntax
DSScanner.addEventListener(type, listener);
Parameters
  • type - A case-sensitive string representing the event type to listen for. Find available events here
  • listener - The function which receives a notification
Return Value
No return value.
Example

DSScanner.addEventListener('onScannerReady', function () {
	DSScanner.StartScanner();
});




Changes any scanner settings

Syntax
DSScanner.setScannerSettings(scannerSettings);
Parameters
  • scannerSettings - ScannerSettings object that defines all scanner properties
Return Value
No return value.
Example

var scannerSettings = {
	camera: {
		resx: 800,
	},
};

DSScanner.setScannerSettings(scannerSettings);
Note




Returns the copy of ScannerSettings object contained inside DSScanner object.

Syntax
var scannerSettings = DSScanner.getScannerSettings();
Return Value




Sets various barcode parameters (see barcode object of ScannerSettings).

Syntax
DSScanner.setBarcodeSetings(barcodeSettings);
Parameters
Return Value
No return value.
Example

var barcode = {
	barcodeTypes: ['Code128', 'DataMatrix'],
	totalBarcodes: 2,
};

DSScanner.setBarcodeSetings(barcode);




Returns cameras that can be used on this device.

Syntax
DSScanner.getVideoDevices(func);
Parameters
  • func - the function which receives the video devices
Return Value
No return value.
Example

DSScanner.getVideoDevices(function (devices) {
	devices.forEach(function (device) {
		console.log("device:" + device.label + '|' + device.id);
	});
});