Data Capture Context

Defined under the namespace Scandit.Datacapture.Core

DataCaptureContextCreationOptions
interface DataCaptureContextCreationOptions

Added in version 6.13.0

deviceName
deviceName?: string

Added in version 6.13.0

The device name allows to optionally identify the device with a user-provided name. This name is then associated with unique identifier of the device and displayed in the online dashboard.

libraryLocation
libraryLocation: string

Added in version 6.13.0

The location of the folder containing the external scandit-datacapture-sdk files.

moduleLoaders
moduleLoaders: ModuleLoader[]

Added in version 6.13.0

An array of modules that will be loaded.

logLevel
logLevel?: Logger.Level

Added in version 6.13.0

The console log level to be used by the library.

settings
settings?: DataCaptureContextSettings

Added in version 6.13.0

Settings will be applied to the newly created context.

DataCaptureContext
class DataCaptureContext

Added in version 6.13.0

Data capture context is the main class for running data capture related tasks. The context manages one or more capture modes, such as BarcodeCapture that perform the recognition. The context itself acts as a scheduler, but does not provide any interfaces for configuring data capture capabilities. Configuration and result handling is handled by the data capture modes directly.

Each data capture context has exactly one frame source (typically a built-in camera). The frame source delivers the frames on which the capture modes should perform recognition on. When a new capture context is created, it’s frame source is null and must be initialized for recognition to work.

Typically a DataCaptureView is used to visualize the ongoing data capture process on screen together with one or more overlays. However it’s also possible to use the data capture context without a view to perform off-screen processing.

Related topics: Get Started, MatrixScan Get Started, Core Concepts <https://docs.scandit.com/core-concepts>.

forLicenseKey(licenseKey, options)
static forLicenseKey(licenseKey: string,
        options: DataCaptureContextCreationOptions): Promise<DataCaptureContext>

Added in version 8.0.0

Constructs a data capture context with the provided license key and options.

Depending on parameters and browser features, any of the following errors could be thrown:

  • NoLicenseKeyError

  • UnsupportedBrowserError

forLicenseKeyInElectronPath(licenseDataPath, options)
static forLicenseKeyInElectronPath(licenseDataPath: string,
        options: DataCaptureContextCreationOptions): Promise<DataCaptureContext>

Added in version 8.0.0

Constructs a data capture context for Electron applications using a license data path. This method handles the Electron-specific license key retrieval logic.

This method can only be used in Electron applications and will automatically retrieve the license key from the specified path.

Path Resolution: The path where the encrypted license key is placed inside the app starting from app.getAppPath(). For example, ./out/renderer/sdc-license.data will be resolved internally like path.join(electronApp.getAppPath(), ‘./out/renderer/sdc-license.data’).

Example Usage: See the electron sample for a complete implementation example.

Depending on parameters and browser features, any of the following errors could be thrown:

  • MisconfigurationError - if not called from an Electron environment

  • NoLicenseKeyError - if the license key cannot be retrieved from the specified path

  • UnsupportedBrowserError

deviceID
static deviceID: string

Added in version 6.13.0

The unique identifier of the device as used by the Scandit Data Capture SDK. This identifier does not contain any device identifying information that would be usable outside of the context of the Scandit Data Capture SDK itself.

getOpenSourceSoftwareLicenseInfo()
static getOpenSourceSoftwareLicenseInfo(): Promise<OpenSourceSoftwareLicenseInfo>

Added in version 7.0.0

The license text and attributions for all third party software used by the Scandit SDK.

sharedInstance
static get sharedInstance(): DataCaptureContext

Added in version 7.5.0

Holds the singleton instance of DataCaptureContext, which is managed by Scandit Data Capture SDK. This instance is unusable until properly configured.

To configure the instance, call forLicenseKey().

setFrameSource(frameSource)
setFrameSource(frameSource: FrameSource | null): Promise<void>

Added in version 6.13.0

Set the frame source of this data capture context.

Frame sources produce frames to be processed by the data capture context. The user typically doesn’t create their own frame sources, but use one of the frame sources provided by the Scandit Data Capture SDK. Typical frame sources are web cams, or built-in cameras of a mobile device.

Setting the frame source to null will effectively stop recognition of this capture context.

frameSource
get frameSource(): FrameSource | null

Added in version 6.13.0

Readonly attribute to get the current frame source. To change the frame source use setFrameSource().

addListener(listener)
addListener(listener: DataCaptureContextListener): void

Added in version 6.13.0

Adds the listener to this data capture context. Context listeners receive events when new data capture modes are added, or the frame source changes.

In case the same listener is already observing this instance, calling this method will not add the listener again.

removeListener(listener)
removeListener(listener: DataCaptureContextListener): void

Added in version 6.13.0

Removes a previously added listener from this data capture context.

In case the listener is not currently observing this instance, calling this method has no effect.

addMode(mode)
addMode(mode: DataCaptureMode): Promise<void>

Added in version 6.13.0

Adds the specified data capture mode to this capture context. Please note that it is not possible to add a mode associated with a context to a different context. If the mode is already associated with this context, this call has no effect.

A data capture context can only be associated with one mode at a time. If multiple modes are associated with the same context, the context will not process any frames and report an error.

setMode(mode)
setMode(mode: DataCaptureMode): Promise<void>

Added in version 7.5.0

Sets the specified data capture mode as the active mode of this capture context. Please note that it is not possible to add a mode associated with a context to a different context. If the mode is already associated with this context, this call has no effect.

A data capture context can only be associated with one mode at a time. If a new mode is associated with the context, the previous mode will be replaced by the new one.

removeMode(mode)
removeMode(mode: DataCaptureMode): Promise<void>

Added in version 6.13.0

Removes the mode from this capture context. If the capture mode is currently not associated to the context, this call has no effect.

removeCurrentMode()
removeCurrentMode(): Promise<void>

Added in version 7.5.0

Removes the currently active mode from this capture context. If the context has no capture mode associated to it, this call has no effect.

removeAllModes()
removeAllModes(): Promise<void>

Added in version 6.13.0

Removes all modes from this capture context. If there currently are no captures modes associated to the context, this call has no effect.

dispose()
dispose(): Promise<void>

Added in version 6.13.0

Disposes/releases this data capture context. This frees most associated resources and can be used to save some memory. Disposed/released contexts cannot be used for recognition anymore, trying will result in a ContextStatus with error code 1025. Data capture modes and listeners remain untouched.

This method may be called multiple times on the same context. Further calls have no effect.

applySettings(settings)
applySettings(settings: DataCaptureContextSettings): Promise<void>

Added in version 6.13.0

Applies the given settings to the data capture context.