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




Stops barcode decoding, turn off camera and free all resources. To start scanner working again need to call Create method.

Syntax
DSScanner.Destroy();
Return Value
No return value.
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




Decodes image file (png, jpg, bmp, etc.) with barcode. To work in this mode you should not pass the ScannerSettings.camera object. In this case the browser will not request the camera access. To avoid the image drawing you can omit the ScannerSettings.viewport object.

Syntax
DSScanner.Create(src);
Parameters
  • src - object that defines the File object or URL string.
Return Value
No return value.
Example
JavaScript
function onBarcodeReady (barcodeResult) {
    var barDataEl = document.getElementById('status');

	for (var i = 0; i < barcodeResult.length; ++i) {
	        var sBarcode = DSScanner.bin2String(barcodeResult[i]);
	        var sPoints = "";
	        for (var j = 0; j < 4; j++)
	            sPoints += "(" + barcodeResult[i].points[j].x + ", " + barcodeResult[i].points[j].y + "),";

	        barDataEl.innerHTML = barcodeResult[i].type + ": " + sBarcode + "|" + sPoints;
	        console.log(barDataEl.innerHTML);
    }
};

function onError(err) {
    var statusElement = document.getElementById('status');
    statusElement.innerHTML = 'Error: ' + err.message;
}

function CreateScanner(device){
    var scannerSettings = {
        scanner: {
            key: '',
        },
        viewport: {
            id: 'datasymbol-barcode-viewport',
        },
        barcode: {
            barcodeTypes: ['EAN13', 'UPCA', 'Code128', 'Code39', 'EAN8', 'DataMatrix', 'QRCode'],
			totalBarcodes: 7,
			uiLinearFindBarcodes: 7,
        },
    };

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

    DSScanner.addEventListener('onScannerReady', function () {
        console.log('HTML onScannerReady');
        var statusElement = document.getElementById('status');
        statusElement.innerHTML = ' ';
    });

    DSScanner.Create(scannerSettings);
}

window.onload = function () {
	CreateScanner();
	document.getElementById('file-input').addEventListener('change', DecodeImage, false);	
}
    
function DecodeImage(e) {
	var file = e.target.files[0];
	if (!file)
		return;

	DSScanner.DecodeImage(file);
	//DSScanner.DecodeImage('/barcode.png');
}

HTML
<p id='status'>Downloading ...</p>
<div id="datasymbol-barcode-viewport" style="display:block;width:640px;height:480px;"></div>
Load File:<input type="file" id="file-input"'/>
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




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);
	});
});




Returns barcode string converted from binary data.

Syntax
var barcodeString = DSScanner.bin2String(barcodeResult [, dataEncoding]);
Parameters
  • barcodeResult - object with barcode properties returned by onBarcode event
  • dataEncoding - encoding type of binary data in barcodeResult, default - 'utf8', possible values:

    'utf-8', 'ibm866', 'iso-8859-2', 'iso-8859-3', 'iso-8859-4', 'iso-8859-5', 'iso-8859-6', 'iso-8859-7', 'iso-8859-8', 'iso-8859-8i', 'iso-8859-10', 'iso-8859-13', 'iso-8859-14', 'iso-8859-15', 'iso-8859-16', 'koi8-r', 'koi8-u', 'macintosh', 'windows-874', 'windows-1250', 'windows-1251', 'windows-1252', 'windows-1253', 'windows-1254', 'windows-1255', 'windows-1256', 'windows-1257', 'windows-1258', 'x-mac-cyrillic', 'gbk', 'gb18030', 'hz-gb-2312', 'big5', 'euc-jp', 'iso-2022-jp', 'shift-jis', 'euc-kr', 'iso-2022-kr', 'utf-16be', 'utf-16le', 'x-user-defined',

Return Value
String value
Example
function onBarcodeReady (barcodeResult) {
	for (var i = 0; i < barcodeResult.length; ++i) {
        var barcodeString = DSScanner.bin2String(barcodeResult[i], 'sjis');
		console.log(barcodeString);
	}
}




Returns value that determines scanner ready state.

Syntax
var bScannerIsReady = DSScanner.IsScannerReady();
Return Value
boolean value
Example
console.log(DSScanner.IsScannerReady());




Returns barcode Web SDK and barcode scanner core versions.

Syntax
var version = DSScanner.getVersion();
Return Value
Object
{ websdk:WEBSDK, coresdk:CORESDK }
Example
console.log(DSScanner.getVersion());




Returns license information. If Barcode Web SDK works in demo mode then all fields are empty.

Syntax
var li = DSScanner.getLicenseInfo();
Return Value
Object
{
    licenseInfo: 'MyCompanyName ...',
    edition: 'professional',	//or 'standard'
    decoders: 'linear,pdf417,datamatrix,qrcode,azteccode',	//or any other combination
    expDate: '2020-02-29'	//year-month-day, epiration date (or empty if for life time)
}
Example
DSScanner.addEventListener('onInitialized', function () {
	var li = DSScanner.getLicenseInfo();
	console.log("licenseInfo:\n" + li.licenseInfo);
	console.log("edition: " + li.edition);
	console.log("decoders: " + li.decoders);
	console.log("expDate: " + li.expDate);
});