This project has moved. For the latest updates, please go here.

Duplex capability when set throws Data out of range

Oct 8, 2014 at 12:14 AM
Edited Oct 8, 2014 at 1:03 AM
Hello I was trying to enable autofeed and upon running encountered Data Parameter Out of Range Exception

Here is my code in
         If Not Fv.FLAG_OFF.Equals(Me.twain.IsCapSupported(TwCap.Duplex) & TwQC.Get) Then
                Dim duplex As UShort = DirectCast(Me.twain.GetCap(TwCap.DuplexEnabled), UShort)
                If duplex > 0 Then
                    If Not Fv.FLAG_OFF.Equals(Me.twain.IsCapSupported(TwCap.FeederEnabled) & TwQC.Set) Then
                        Me.twain.SetCap(TwCap.FeederEnabled, True)
                        If Not String.IsNullOrEmpty(Me.twain.IsCapSupported(TwCap.XferCount) & TwQC.Set) Then
                            Me.twain.SetCap(TwCap.XferCount, -1) __' Exception occurs here__
                            If Fv.FLAG_OFF.Equals(Me.twain.IsCapSupported(TwCap.DuplexEnabled) & TwQC.Set) Then
                                Me.twain.SetCap(TwCap.DuplexEnabled, True)__' Exception occurs here__

                            End If
                        End If
                    End If
                End If
            End If
Would really appreciate your help on this.
Oct 8, 2014 at 5:31 AM
Hello, kaxe.
Try follow code:
If (Me._twain32.IsCapSupported(TwCap.Duplex) And TwQC.GetCurrent) <> 0 Then
    Dim _duplexCapValue = DirectCast(Me._twain32.GetCurrentCap(TwCap.Duplex), TwDX)
    If _duplexCapValue <> TwDX.None Then
        If (Me._twain32.IsCapSupported(TwCap.FeederEnabled) And TwQC.[Set]) <> 0 Then
            Me._twain32.SetCap(TwCap.FeederEnabled, True)

            'It is not necessarily. Try to uncomment.
            'If (Me._twain32.IsCapSupported(TwCap.XferCount) And TwQC.[Set]) <> 0 Then
                'Me._twain32.SetCap(TwCap.XferCount, -1)

                If (Me._twain32.IsCapSupported(TwCap.DuplexEnabled) And TwQC.[Set]) <> 0 Then
                    Me._twain32.SetCap(TwCap.DuplexEnabled, True)
                End If
            'End If
        End If
    End If
End If

' ...
Friend Enum TwDX As UShort
    None = 0
    OnePassDuplex = 1
    TwoPassDuplex = 2
End Enum
Marked as answer by SARAFF on 10/13/2014 at 12:47 PM
May 5, 2015 at 5:17 PM
Edited May 5, 2015 at 5:19 PM
Not sure why this doesn't work
if ((twain32.IsCapSupported(TwCap.FeederEnabled) & TwQC.Set) != 0)
                        twain32.SetCap(TwCap.FeederEnabled, false);
Exception is thrown.

A first chance exception of type 'Saraff.Twain.TwainException' occurred in Saraff.Twain.dll
An unhandled exception of type 'Saraff.Twain.TwainException' occurred in Saraff.Twain.dll
Additional information: Data parameter out of range.

Twain Spec states Allowed Values are true and false.

The same is true for
            UInt16 test = 5;
            if ((twain32.IsCapSupported(TwCap.IUnits) & TwQC.Set) != 0)
                twain32.SetCap(TwCap.IUnits, test); //UN_PIXELS     
Twain Spec states Allowed Values are 0-5.
Any help will be appreciated.

Thank you.
May 5, 2015 at 7:54 PM
Hello, javamike.
  1. Which version of the Saraff.Twain.NET you use?
  2. Also see TWAIN Specification:

Capabilities Overview

Sources may support a large number of capabilities but are required to support very few. To determine if a capability is supported by a Source, the application can query the Source using a DG_CONTROL / DAT_CAPABILITY / MSG_GET, MSG_GETCURRENT, or MSG_GETDEFAULT operation. The application specifies the particular capability by storing its identifier in the Cap field of the TW_CAPABILITY structure. This is the structure pointed to by the pData parameter in the DSM_Entry( ) call.
DG_CONTROL / DAT_CAPABILITY operations for capability negotiation include:
  • MSG_GET ( object Twain32.GetCap(TwCap) in the Saraff.Twain.NET) - Returns the Current, Default and Available settings for a capability.
  • MSG_GETCURRENT ( object Twain32.GetCurrentCap(TwCap) in the Saraff.Twain.NET) - Returns the Current setting for a capability.
  • MSG_GETDEFAULT ( object Twain32.GetDefaultCap(TwCap) in the Saraff.Twain.NET) - Returns the value of the Source’s preferred Default values.
  • MSG_RESET ( void Twain32.ResetCap(TwCap) in the Saraff.Twain.NET) - Returns the capability to its TWAIN Default (power-on) condition (i.e. all previous negotiation is ignored).
  • MSG_RESETALL - Returns all of the current values to the default settings used when the driver was first installed.
  • MSG_SET ( void Twain32.SetCap(TwCap,object) in the Saraff.Twain.NET) - Allows the application to set the Current value of a capability.
  • MSG_SETCONSTRAINT - Allows the application to set the Current and Default value(s) and restrict the Available values to some subset of the Source’s power-on set of values. Sources are strongly encouraged to allow the application to set as many of its capabilities as possible, and further to reflect these changes in the Source’s user interface. This will ensure that the user can only select images with characteristics that are useful to the consuming application.
TWAIN 2.2 Specification, 10-1

thus, try following code
if((this._twain32.IsCapSupported(TwCap.IUnits)&TwQC.Get)!=0) {

    var _cap=this._twain32.GetCap(TwCap.IUnits) as Twain32.Enumeration;

    for(var i=0; i<_cap.Count; i++) { // show supported values
        System.Diagnostics.Debug.WriteLine(string.Format("{0} {1} {2}",(TwUnits)(ushort)_cap[i],i==_cap.CurrentIndex?"[Current]":"",i==_cap.DefaultIndex?"[Default]":""));
if((this._twain32.IsCapSupported(TwCap.IUnits)&TwQC.Get)!=0) {

    var _cap=this._twain32.Capabilities.Units.Get();

    for(var i=0; i<_cap.Count; i++) { // show supported values
        System.Diagnostics.Debug.WriteLine(string.Format("{0} {1} {2}",_cap[i],i==_cap.CurrentIndex?"[Current]":"",i==_cap.DefaultIndex?"[Default]":""));
so, read the Documentation of Saraff.Twain.NET and TWAIN Specification
May 6, 2015 at 3:46 PM
Thank you Saraff.

Not sure how to tell, where do I look for the version?
May 6, 2015 at 4:04 PM
.dll says
May 6, 2015 at 6:19 PM
Edited May 6, 2015 at 6:21 PM
Hello, javamike.
I think in your case the value of FeederEnabled already is false. Therefore, setting a FeederEnable to a false again causes an error.
Try use following code:
if((_twain32.IsCapSupported(TwCap.FeederEnabled) & TwQC.Set) != 0 && (bool)_twain32.GetCurrentCap(TwCap.FeederEnabled)) {
    _twain32.SetCap(TwCap.FeederEnabled, false);
May 6, 2015 at 8:33 PM
Edited May 6, 2015 at 8:45 PM
I'm thinking the scanner does not support FeederEnabled = false.
returned true.
 var feederCap = twain32.GetCap(TwCap.FeederEnabled) as Twain32.Enumeration; 
returns null

Thank you for updating the Documentation of Saraff.Twain.NET.