Skip to main content

BarcodeScanner

Namespace: Wisej.Web.Ext.Dynamsoft

Assembly: Wisej.Web.Ext.Dynamsoft (4.1.0.0)

A Dynamsoft Barcode Reader Integration.

public class BarcodeScanner : DSBase

The control shows the video stream of the camera and continuously scans it for barcodes using the Dynamsoft JavaScript Barcode Reader. The scanner is created only after ProductKey is set; until then the control shows a message. The results are returned through the UniqueRead and FrameRead events.

Example:

The following example adds a barcode scanner to a form and shows each new barcode in a text box.

var scanner = new BarcodeScanner();
scanner.ProductKey = Environment.GetEnvironmentVariable("DYNAMSOFT_DBR_KEY");
scanner.UniqueRead += (s, e) =>
{
this.textBoxCode.Text = e.Data;
};
scanner.Dock = DockStyle.Fill;
this.Controls.Add(scanner);

Constructors​

Instance member BarcodeScanner()​

Constructs a new instance of the BarcodeScanner class.

Example:

The following example creates a scanner in a panel; the camera starts as soon as the product key is set.

var scanner = new BarcodeScanner();
scanner.Dock = DockStyle.Fill;
this.panelCamera.Controls.Add(scanner);

scanner.ProductKey = this.dynamsoftKey;

Properties​

Instance member InitScript​

String: Returns the script that creates the Dynamsoft barcode scanner in the browser.

The value is always the script embedded in the extension (Wisej.Web.Ext.Dynamsoft.BarcodeScanner.js); assigning a different script doesn't change the returned value.

Instance member ProductKey​

String: Gets or sets the JS Dynamsoft Barcode Reader product key to use for the scanner.

The key is passed to the browser in the productKey field of Options and assigned to the Dynamsoft license. The scanner is not created while the key is empty, and changing the key recreates it.

Example:

The following example reads the license key from an environment variable.

this.barcodeScanner1.ProductKey = Environment.GetEnvironmentVariable("DYNAMSOFT_DBR_KEY");

Methods​

Protected member Dispose(disposing)​

Clean up any resources being used.

ParameterTypeDescription
disposingBooleantrue if managed resources should be disposed; otherwise, false.

Protected member OnWidgetEvent(e)​

ParameterTypeDescription
eWidgetEventArgs

Events​

Instance member FrameRead​

EventHandler<WidgetEventArgs> Fires after the library finishes scanning a frame.

The event is fired only when at least one barcode is found in the frame. Data is the array of Dynamsoft results found in the frame, including the duplicates.

Example:

The following example shows the format and the text of the barcodes found in the last frame.

this.barcodeScanner1.FrameRead += (s, e) =>
{
this.listBoxFrame.Items.Clear();
foreach (var result in e.Data)
this.listBoxFrame.Items.Add($"{result.barcodeFormatString}: {result.barcodeText}");
};

Instance member Played​

EventHandler<WidgetEventArgs> Fires when the video stream starts playing.

Instance member UniqueRead​

EventHandler<WidgetEventArgs> Fires when a new, unduplicated barcode is found.

The library keeps each barcode result (type and value) in the buffer for a period of time (can be set with duplicateForgetTime) during which if a new result is an exact match, it’s seen as a duplicate and will again be kept for that period of time while the old result is removed and so on.

Data is the text of the barcode.

Example:

The following example adds each new barcode to a list.

this.barcodeScanner1.UniqueRead += (s, e) =>
{
string code = e.Data;
this.listBoxCodes.Items.Add(code);
};

Instance member Warning​

EventHandler<WidgetEventArgs> Fires when the resolution is not ideal (< 720P).

Data is the warning object received from the Dynamsoft scanner.

Implements​