How to Negotiate Capability with Different Capability
Container Types
Topics included in this article that describe how to negotiate capability
with different capability container types are:
Setting Capability with TWON_ONEVALUE
Setting Capability with TWON_ARRAY
Setting Capability with TWON_ENUMERATION
Setting Capability with TWON_RANGE
Reading Value(s) through Capability Negotiation
Setting Capability with TWON_ONEVALUE
TWON_ONEVALUE capability container type can be used to set or return a single value (item)
of a capability.
To set a capability with TWON_ONEVALUE container, the following steps are
needed:
Call OpenSource() to bring
Dynamic .NET TWAIN to the state for capability
negotiation;
Set the Capability property to the capability to be negotiated;
Set the CapType property to TWON_ONEVALUE;
If the data type of the capability is String, set the value of
CapValueString property. For any other data types, set the value of
CapValue property;
Call CapSet() to actually set the value.
C# Sample:
Twain.OpenSource();
Twain.Capability = Dynamsoft.DotNet.TWAIN.Enums.TWCapability.ICAP_UNITS;
Twain.CapType = Dynamsoft.DotNet.TWAIN.Enums.TWCapType.TWON_ONEVALUE;
Twain.CapValue = (double)Dynamsoft.DotNet.TWAIN.Enums.TWICapUNits.TWUN_INCHES; // TWUN_INCHES
if (Twain.CapSet())
MessageBox.Show("Successful.");
else
MessageBox.Show("Failed.\r\n" + Twain.ErrorString);
|
Setting Capability with TWON_ARRAY
TWON_ARRAY capability container type can be used to set or return a group of associated individual values.
To set a capabilIty with TWON_ARRAY container, the following steps are
needed:
Call OpenSource() to bring
Dynamic .NET TWAIN to the state for capability
negotiation;
Set the Capability property to the capability to be negotiated;
Set the CapType property to TWON_ARRAY;
Set the CapNumItems property to indicate how many
items are in the array;
If the data type of the capability is String, use the
CapItemsString()
method to set the values. For any other data types, use the
SetCapItems() method to set the values;
Call href="../html/M_Dynamsoft_DotNet_TWAIN_DynamicDotNetTwain_CapSet.htm">CapSet() to actually set the value.
C# Sample:
Twain.OpenSource();
Twain.Capability = Dynamsoft.DotNet.TWAIN.Enums.TWCapability.ICAP_FILTER;
Twain.CapType = Dynamsoft.DotNet.TWAIN.Enums.TWCapType.TWON_ARRAY;
Twain.CapNumItems = 3; //Set cap values count.
// Set the cap's values
Twain.SetCapItems(0, (double)Dynamsoft.DotNet.TWAIN.Enums.TWICapFilterType.TWFT_NONE);
Twain.SetCapItems(1, (double)Dynamsoft.DotNet.TWAIN.Enums.TWICapFilterType.TWFT_GREEN);
Twain.SetCapItems(2, (double)Dynamsoft.DotNet.TWAIN.Enums.TWICapFilterType.TWFT_BLUE);
if (Twain.CapSet())
MessageBox.Show("Successful.");
else
MessageBox.Show("Failed.\r\n" + Twain.ErrorString);
|
Setting Capability with TWON_ENUMERATION
TWON_ENUMERATION capability container type can be used to set or return a group of associated individual
values describing a capability. The values are ordered from the lowest to highest values, but the step size between
every two values is probably not uniform.
To set a capability with TWON_ENUMERATION container, the
following steps are
needed:
Call OpenSource() to bring
Dynamic .NET TWAIN to the state for capability
negotiation;
Set the Capability property to the capability to be negotiated;
Set the CapType property to TWON_ENUMERATION;
Set the CapNumItems property to indicate how many
items are in the array;
If the data type of the capability is String, use the
SetCapItemsString() method to set the values. For any other data types, use the
SetCapItems() method to set the values;
Set the CapCurrentIndex to indicate the index of the
current value;
Call CapSet() to actually set the value.
C# Sample:
Twain.OpenSource();
Twain.Capability = Dynamsoft.DotNet.TWAIN.Enums.TWCapability.ICAP_XRESOLUTION;
Twain.CapType = Dynamsoft.DotNet.TWAIN.Enums.TWCapType.TWON_ENUMERATION;
Twain.CapNumItems = 3; //Set the cap values count.
// Set the cap's values
Twain.SetCapItems(0, 80);
Twain.SetCapItems(1, 100);
Twain.SetCapItems(2, 120);
Twain.CapCurrentIndex = 2; //Set the cap's current value's index in the ENEMERATION.
if (Twain.CapSet())
MessageBox.Show("Successful.");
else
MessageBox.Show("Failed.\r\n" + Twain.ErrorString);
|
Setting Capability with TWON_RANGE
TW_RANGE capability container type can be used to set or return a range of individual values describing a capability. The values are uniformly distributed between a minimum and a maximum value. The step size between
every two values is constant.
To set a capability with TW_RANGE container, the
following steps are
needed:
Call OpenSource() to bring
Dynamic .NET TWAIN to the state for capability
negotiation;
Set the Capability property to the capability to be negotiated;
Set the CapType property to TW_RANGE;
Set the CapMinValue,
CapMaxValue,
CapStepSize and
CapCurrentValue
properties;
Call CapSet() to actually set the value.
C# Sample:
Twain.OpenSource();
Twain.Capability = Dynamsoft.DotNet.TWAIN.Enums.TWCapability.ICAP_XRESOLUTION;
Twain.CapType = Dynamsoft.DotNet.TWAIN.Enums.TWCapType.TWON_RANGE;
// Set the cap's values
Twain.CapMinValue = 80;
Twain.CapMaxValue = 200;
Twain.CapStepSize = 20;
Twain.CapCurrentValue = 120;
if (Twain.CapSet())
MessageBox.Show("Successful.");
else
MessageBox.Show("Failed.\r\n" + Twain.ErrorString);
|
Reading Value(s) from Capability Negotiation
To read values from a capability:
Call OpenSource() to bring
Dynamic .NET TWAIN to the state for capability
negotiation;
Set the Capability property to the capability to be negotiated;
Call CapGet() to get the data;
Get the data according to the returned capability container type.
C# Sample:
Twain.OpenSource();
Twain.Capability = Dynamsoft.DotNet.TWAIN.Enums.TWCapability.CAP_xxx;
if (!Twain.CapGet())
{
MessageBox.Show("Failed.\r\n" + Twain.ErrorString);
return;
}
string txtCap;
if (Twain.CapType == Dynamsoft.DotNet.TWAIN.Enums.TWCapType.TWON_ONEVALUE)
{
txtCap = "Container type is TWON_ONEVALUE\r\n";
txtCap = txtCap + "Current Value:" + Twain.CapValue + "\r\n";
}
else if (Twain.CapType == Dynamsoft.DotNet.TWAIN.Enums.TWCapType.TWON_ARRAY)
{
txtCap = "Container type is TWON_ARRAY"+ "\r\n";
txtCap = txtCap + "Available Values:";
for (int lngIndex = 0; lngIndex < Twain.CapNumItems; lngIndex ++)
{
if (lngIndex < Twain.CapNumItems - 1)
txtCap = txtCap + Twain.GetCapItems(lngIndex) + ",";
else
txtCap = txtCap + Twain.GetCapItems(lngIndex);
}
}
else if (Twain.CapType == Dynamsoft.DotNet.TWAIN.Enums.TWCapType.TWON_ENUMERATION)
{
txtCap = "Container type is TWON_ENUMERATION" + "\r\n";
txtCap = txtCap + "Current Value:" + Twain.GetCapItems(Twain.CapCurrentIndex)+ "\r\n";
txtCap = txtCap + "Default Value:" + Twain.GetCapItems(Twain.CapDefaultIndex)+ "\r\n";
txtCap = txtCap + "Available Values:";
for (int lngIndex = 0; lngIndex < Twain.CapNumItems; lngIndex ++)
{
if (lngIndex < Twain.CapNumItems - 1)
txtCap = txtCap + Twain.GetCapItems(lngIndex) + ",";
else
txtCap = txtCap + Twain.GetCapItems(lngIndex);
}
}
else if (Twain.CapType == Dynamsoft.DotNet.TWAIN.Enums.TWCapType.TWON_RANGE)
{
txtCap = "Container type is TWON_RANGE"+ "\r\n";
txtCap = txtCap + "Current Value:" + Twain.CapCurrentValue+ "\r\n";
txtCap = txtCap + "Default Value:" + Twain.CapDefaultValue+ "\r\n";
txtCap = txtCap + "Min Value:" + Twain.CapMinValue+ "\r\n";
txtCap = txtCap + "Max Value:" + Twain.CapMaxValue+ "\r\n";
txtCap = txtCap + "Step Size:" + Twain.CapStepSize;
}
|
See Also
Capability Container Types