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

Strongly typed accessing to a capabilities

The Saraff.Twain.NET support strongly typed accessing to a capabilities that specified in a TWAIN 2.3 Specification.
Follow two interfaces provide accessing to a capabilities.

public interface ICapability<T> {
    Twain32.Enumeration Get();
    T GetCurrent();
    T GetDefault();
    void Set(T value);
    void SetConstraint(T value);
    void SetConstraint(params T[] value);
    void SetConstraint(Twain32.Range value);
    void SetConstraint(Twain32.Enumeration value);
    void Reset();
    TwQC IsSupported();
    bool IsSupported(TwQC operation);
}

public interface ICapability2<T> {
    Twain32.Enumeration Get();
    object[] GetCurrentArray();
    object[] GetDefaultArray();
    void Set(T value);
    void Set(params T[] value);
    void SetConstraint(T value);
    void SetConstraint(params T[] value);
    void SetConstraint(Twain32.Range value);
    void SetConstraint(Twain32.Enumeration value);
    void Reset();
    TwQC IsSupported();
    bool IsSupported(TwQC operation);
}

Below shown samples of using some capabilities.

//Brightness
if((this._twain32.Capabilities.Brightness.IsSupported(TwQC.Set))!=0) {
    this._twain32.Capabilities.Brightness.Set(100f); //Allowed Values: -1000f to +1000f; Default Value: 0f;
}

//Contrast
if((this._twain32.Capabilities.Contrast.IsSupported(TwQC.Set))!=0) {
    this._twain32.Capabilities.Contrast.Set(-200f); //Allowed Values: -1000f to +1000f; Default Value: 0f;
}

//Feeder & Duplex
if((this._twain32.Capabilities.Duplex.IsSupported(TwQC.GetCurrent))!=0) {
    if(this._twain32.Capabilities.Duplex.GetCurrent()!=TwDX.None) {
        if((this._twain32.Capabilities.FeederEnabled.IsSupported(TwQC.Set))!=0) {
            this._twain32.Capabilities.FeederEnabled.Set(true);

            if((this._twain32.Capabilities.DuplexEnabled.IsSupported(TwQC.Set))!=0) {
                this._twain32.Capabilities.DuplexEnabled.Set(true);
            }
            this._twain32.Capabilities.XferCount.Set(-1);
        }
    }
}

Last edited Nov 26, 2016 at 6:51 PM by SARAFF, version 1