DataSource ClassTerminal Works - TwainScanning.Net Library
Class that represent twain device.
Inheritance Hierarchy

SystemObject
  TwainScanningDataSource

Namespace: TwainScanning
Assembly: TwainScanning (in TwainScanning.dll) Version: 1.4.3.0 (1.4.3.0)
Syntax

public sealed class DataSource : IDisposable

The DataSource type exposes the following members.

Methods

  NameDescription
Public methodAcquire(Boolean, Boolean, DataSourceErrorInfo, NullableTwSX, Int32)
Acquires images. Most simple way to scan. Preferred way for scanning in the console applications. Function will not return until scanning is finished.
Public methodAcquire(IImageCollector, Boolean, Boolean, NullableTwSX, NullableInt32)
Allows to acquire images from the scanner synchronously. This function will not return until scanning is finished.
Public methodAcquireAsync(IImageCollector, Boolean, Boolean, NullableTwSX, NullableInt32)
Allows to acquire images from the scanner asynchronously. This function will return immediately.
Public methodAcquireAsync(ImageCollectorOnFinishedDelegate, Boolean, Boolean, NullableTwSX, NullableInt32)
Allows to acquire images from the scanner asynchronously.
Public methodCallCustomTripletT
Public methodCancelCurrentScanning
Cancels the current scanning.

Note: Scanning is aborted, which means that images which the device already scanned but did not transfer yet are discarded. Use StopFeeder when those images have to be kept.

Public methodDispose
Closes source and performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Overrides ObjectFinalize.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodSetupFileTransferParams(TwFF, IEnumerableString, Boolean)
Public methodSetupFileTransferParams(TwFF, String, Boolean)
Public methodStopFeeder
Requests the device to stop feeding new sheets, while all images which were already scanned are still delivered. This is the graceful way to end continuous scanning - unlike CancelCurrentScanning, which aborts the acquisition and discards everything the device did not transfer yet.

Sheets which the feeder already picked up are scanned and transferred to the end, including both sides when duplex is enabled, and scanning finishes on its own once the device reports no more pending transfers - OnBatchFinished and OnScanningFinished are raised as after a complete batch.

Can be called from any thread, including from within OnSingleImageAcquired. The request is not executed immediately - the library sends DG_CONTROL / DAT_PENDINGXFERS / MSG_STOPFEEDER to the device as soon as the transfer in progress ends, because that is the TWAIN state in which data sources accept it.

Do NOT combine with CancelCurrentScanning or with CancelScanning, they would discard the pending images.

Not every device supports this operation. Use SupportsStopFeeder to check in advance and StopFeederAccepted to see whether the device actually accepted the request.

Public methodToString (Inherited from Object.)
Top
Fields

  NameDescription
Public fieldClearPage
Stop scanning all pages from feeder.

Alias for [!:Settings.Feeder.ClearPage].

Public fieldColorMode
Represent color mode.

Alias for [!:Settings.ImageType.PixelType].

Public fieldPageSize
Represent available PageSize.

Alias for [!:Settings.Page.Sizes].

Public fieldPixelDepth
Represent pixel depth for current value.

Alias for [!:Settings.ImageType.BitDepth].

Public fieldResolution
Represent supported resolutions.

Alias for [!:Settings.Resolution.X] and [!:Settings.Resolution.Y].

Public fieldSettings
Data source settings. Abstraction around capabilities of the device represented by the DataSource.
Public fieldTransferMechanism
Represent supported transfer mechanism.

Alias for [!:Settings.Transfer.Mechanism].

Public fieldUseDuplex
If duplex is enable.

Alias for [!:Settings.Duplex.Enabled].

Public fieldUseFeeder
Represent if feeder is enable.

Alias for [!:Settings.Feeder.Enabled].

Top
Properties

  NameDescription
Public propertyHasFeeder
Is feeder supported on Twain Device.
Public propertyIdentity
Get identity of current scanner.
Public propertyLayout
Property layout.
Public propertyStopFeederAccepted
Result of the last StopFeeder request sent to the device.

null when no request was sent to the device during the current scanning (either it was not requested, or the scanning ended before the library could send it), true when the device accepted it and false when the device rejected it, which means the device does not support stopping the feeder this way.

Public propertySupportsStopFeeder
Indicates whether the device is expected to support StopFeeder.

The check is done without touching the device state: it reports whether the data source has a feeder and whether it implements TWAIN 1.9 or newer, which is the version that introduced MSG_STOPFEEDER. Data sources are allowed to reject the operation even so, therefore treat this as an advance check only - the definitive answer for a device is StopFeederAccepted after scanning.

Note: Read it before scanning is started, it reads a capability from the data source.

Top
Events

  NameDescription
Public eventAcquiringEvent
Representing image acquiring events.
Public eventExtendedImageInformation
Public eventOnBatchFinished
Occurs when batch scanning is finish.

Raised after the last image of the batch was delivered, before the data source is disabled and before OnScanningFinished.

Public eventOnDeviceEvents
Public eventOnErrorEvent
Represents errors which occur in Twain device.
Public eventOnMemoryTransferProgressUpdate
Occurs when image chunk is transferred from scanner to this library. Occurs only when using Memory or MemFile as transfer method.
Public eventOnScanningFinished
Occurs when scanning is finish.

Last event of a scanning, raised after the data source was disabled. Reading StopFeederAccepted here is still valid.

Public eventOnSingleImageAcquired
Provides data for the Device.ImageAcquired event.

Raised once per acquired image, on the thread which drives the TWAIN message loop, and it is raised synchronously - scanning of the next image continues only after the handler returns, so keep the handler short and hand the work over to another thread when it takes longer.

Order of the operations for every image: the image is added to the collector, this event is raised, the library ends the transfer (MSG_ENDXFER) and asks the device how many transfers are still pending. The device is therefore still in the transfer state while the handler runs, which is why requests which have to reach the device in a different state - like StopFeeder - are only registered here and sent by the library at the right moment.

Order of the events for the whole scanning: AcquiringEvent and OnSingleImageAcquired per image, then OnBatchFinished when there are no more pending transfers, and finally OnScanningFinished after the data source is disabled.

Top
See Also

Reference

SystemIDisposable