View on GitHub

SARAFF SOFTWARE

All products / Saraff.Twain.NET / Contents

Strongly typed accessing to a capabilities

The Saraff.Twain.NET support strongly typed accessing to a capabilities that specified in a TWAIN 2.4 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)) {
    this._twain32.Capabilities.Brightness.Set(100f); //Allowed Values: -1000f to +1000f; Default Value: 0f;
}
//Contrast
if(this._twain32.Capabilities.Contrast.IsSupported(TwQC.Set)) {
    this._twain32.Capabilities.Contrast.Set(-200f); //Allowed Values: -1000f to +1000f; Default Value: 0f;
}
//Feeder & Duplex
if(this._twain32.Capabilities.Duplex.IsSupported(TwQC.GetCurrent)) {
    if(this._twain32.Capabilities.Duplex.GetCurrent()!=TwDX.None) {
        if(this._twain32.Capabilities.FeederEnabled.IsSupported(TwQC.Set)) {
            this._twain32.Capabilities.FeederEnabled.Set(true);

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