Use Capability Negotiation

Introduction

Capabilities represent the features that a specified TWAIN source (e.g., a scanner) provides. To make full use of such a source/device, TWAIN applications need to perform the operation called capability negotiation. With the negotiation, TWAIN applications can understand the source and then guide it to provide the images they would like to receive from it.

Capability Containers

Container Data Structure Type of Contents
TW_ONEVALUE A single value whose current and default values are coincident. The range of available values for this type of capability is simply this single value. For example, a capability that indicates the presence of a document feeder could be of this type.
TW_ARRAY An array of values that describes the current logical item. The available values may be a larger array of values. For example, a list of the supported capabilities list returned by the CAP_SUPPORTEDCAPS capability, would use this type of container.
TW_RANGE Many capabilities allow users to select their current value from a range of regularly spaced values. The capability can specify the minimum and maximum acceptable values and the incremental step size between values. For example, the resolution might be supported from 100 to 600 in steps of 50 (100, 150, 200, ..., 550, 600).
TW_ENUMERATION This is the most general type because it defines a list of values from which the Current Value can be chosen. The values do not progress uniformly through a range and there is not a consistent step size between the values. For example, if a Source’s resolution options did not occur in even step sizes, then an enumeration would be used (for example, 150, 400, and 600).

What is involved

To perform capability negotiation, you do two things

  • Get a Capability. It is used to ask the source about a specified capability and get its type, value, etc.
  • Set a Capability. It is generally used to request the source to set/change the value of a capability.

Now we’ll talk about how to perform capability negotiation

Before doing any capability negotiation, please keep in mind that it can only take place when the source is open (DataSourceStatus is 1). You need to use the methods SelectSource() and OpenSource() to select a TWAIN source and get it ready for the negotiation. The related APIs are

Get

To get information about a capability, you can use the following code snippet by specifying the capability.

DWObject.OpenSource();
DWObject.Capability = EnumDWT_Cap.***;
DWObject.CapGet();
var tempValue = '';
DWObject.CapValueType > 8 ?
/*STR*/tempValue = DWObject.CapValueString
    :
/*NUM*/tempValue = DWObject.CapValue;
/*
* Special for BOOL
*/
if (DWObject.CapValueType == EnumDWT_CapValueType.TWTY_BOOL) {
    tempValue == 0 ? tempValue = 'FALSE' : tempValue = 'TRUE';
}
alert('The type of the capability is ' + DWObject.CapType); /*More info*/
alert('The value of the capability is ' + tempValue);

Set

Please NOTE that the TWAIN source vendor generally dictates the container type and available values for a capability. When you try to set a capability, you are just trying to change it so that it uses a different but available value. Therefore, you should try to get the capability before you set it.

The code to set capabilities is different if they have different container types.

TW_ONEVALUE

DWObject.OpenSource();
DWObject.Capability = EnumDWT_Cap.***; /*Make sure this Capability is TW_ONEVALUE*/
DWObject.CapGet(); /*Recommended*/
DWObject.CapType = EnumDWT_CapType.TWON_ONEVALUE;
DWObject.CapValueType > 8 ?
/*STR*/DWObject.CapValue = someStringValue;
:
/*NUM*/DWObject.CapValue = someNonStringValue;
DWObject.CapSet();

TW_ARRAY

DWObject.OpenSource();
DWObject.Capability = EnumDWT_Cap.***; /*Make sure this Capability is TWON_ARRAY*/
DWObject.CapGet(); /*Recommended*/
DWObject.CapType = EnumDWT_CapType.TWON_ARRAY;
DWObject.CapNumItems = *;
if (DWObject.CapValueType > 8) {
/*STR*/
    DWObject.SetCapItemsString(0, someStringValue);
    DWObject.SetCapItemsString(1, someStringValue);
    …
} else {
/*NUM*/
    DWObject.SetCapItems(0, someNonStringValue);
    DWObject.SetCapItems(1, someNonStringValue);
    …
}
DWObject.CapSet();

TW_RANGE

DWObject.OpenSource();
DWObject.Capability = EnumDWT_Cap.***; /*Make sure this Capability is TWON_RANGE*/
DWObject.CapGet(); /*Recommended*/
DWObject.CapType = EnumDWT_CapType.TWON_RANGE;
DWObject.CapMinValue = 80;
DWObject.CapMaxValue = 200;
DWObject.CapStepSize = 20;
DWObject.CapCurrentValue = 100;
DWObject.CapSet();

TW_ENUMERATION

DWObject.OpenSource();
DWObject.Capability = EnumDWT_Cap.***; /*Make sure this Capability is
TWON_ENUMERATION*/
DWObject.CapGet(); /*Recommended*/
DWObject.CapType = EnumDWT_CapType.TWON_ENUMERATION;
DWObject.CapNumItems = *;
if(DWObject.CapValueType > 8 ){
/*STR*/
    DWObject. SetCapItemsString (0, someStringValue);
    DWObject. SetCapItemsString (1, someStringValue);
    …
} else {
/*NUM*/
    DWObject. SetCapItems(0, someNonStringValue);
    DWObject. SetCapItems(1, someNonStringValue);
    …
}
DWObject.CapCurrentIndex = 1;
DWObject.CapSet();

results matching ""

    No results matching ""

    results matching ""

      No results matching ""