Accusoft.TwainPro9.Net
Check Capabilities

TWAIN devices have different capabilities (e.g., levels of resolution, support of color or black and white images, automatic document feeder available, etc.). Applications can check the capabilities available for the TWAIN device, and can also set those capabilities to its desired settings. 

Capabilities can be checked once a TWAIN Session has been opened (OpenSession), and before or after a scanning session has been initiated (StartSession).

Identifying Capabilities

TWAIN specifies some capabilities to be basic (Capability) and some to be advanced (AdvancedCapability). TwainPRO methods are overloaded to support both. An overload is also provided to enable the application to access a capability that is not enumerated in the TwainPRO™ interface, by specifying an integer value.

Check that the Capability is Supported by the Data Source

To determine whether the capability of interest is supported by the TWAIN device, call TwainDevice.IsCapabilitySupported.

Read the Capability Information

If the capability is supported by the TWAIN device, call TwainDevice.GetCapability. TWAIN defines four types of containers used to negotiate values between the application and the source device: 

The GetCapability method returns the container as a CapabilityContainer, which can then be casted to the appropriate child object (e.g. CapabilityContainerOneValue, CapabilityContainerEnum, CapabilityContainerRange, and CapabilityContainerArray) to access the capability information. 

C# Example
Copy Code
// This code demonstrates how to read a value
// Check for support and stop if none
if (twainDevice.IsCapabilitySupported(capability) == false)
{
 labelDefault.Text = "Not Supported";
 labelDefault.Visible = true;
 textBoxCurrent.Enabled = false;
 buttonUpdate.Enabled = false;
 return;
}
else
{
capcontainer = twainDevice.GetCapability(capability);
// What data type is the Cap?  We have to check the data type
// to know which properties are valid
switch (capcontainer.GetType().ToString())
{
 // Type ONEVALUE only returns a single value
 case "Accusoft.TwainProSdk.CapabilityContainerOneValueFloat":
 {
  Accusoft.TwainProSdk.CapabilityContainerOneValueFloat myCap = (CapabilityContainerOneValueFloat)twainDevice.GetCapability(capability);
 
  textBoxCurrent.Text = myCap.Value.ToString();
  textBoxCurrent.Visible = true;
  break;
 }
 case "Accusoft.TwainProSdk.CapabilityContainerOneValueString":
 {
  Accusoft.TwainProSdk.CapabilityContainerOneValueString myCap = (CapabilityContainerOneValueString)twainDevice.GetCapability(capability);
 
  textBoxCurrent.Text = myCap.Value;
  textBoxCurrent.Visible = true;
  break;
 } 
 // Type ENUM returns a list of legal values as well as current and
 // default values.  A list of constants is returned and the CapDesc
 // property can be used to find out what the constants mean
 case "Accusoft.TwainProSdk.CapabilityContainerEnum":
 {
  Accusoft.TwainProSdk.CapabilityContainerEnum myCap = (CapabilityContainerEnum)twainDevice.GetCapability(capability);
 
  textBoxCurrent.Text = ((CapabilityContainerOneValueFloat)myCap.CurrentValue).Value.ToString();
  textBoxCurrent.Visible = true;
 
  labelDefault.Text = "Default  =  " + ((CapabilityContainerOneValueFloat)myCap.DefaultValue).Value.ToString();
  labelDefault.Visible = true;
 
  listBoxCaps.Items.Add("Legal Values:");
 
  for (int nIndex = 0; nIndex < myCap.Values.Count; nIndex++)
  {
   float fResult = ((CapabilityContainerOneValueFloat)myCap.Values[nIndex]).Value;
 
   string strResult = twainDevice.GetCapabilityConstantDescription(capability, nIndex);
 
   if (strResult == null)
   {
    strResult = "";
   } 
   listBoxCaps.Items.Add(fResult.ToString() + " - " + strResult.ToString());
  }
  listBoxCaps.Visible = true;
  break;
 } 
 // Type ARRAY returns a list of values, but no current or default values
 // This is a less common type that many Data Sources don't use
 case "Accusoft.TwainProSdk.CapabilityContainerArray":
 {
  Accusoft.TwainProSdk.CapabilityContainerArray myCap = (CapabilityContainerArray)twainDevice.GetCapability(capability);
  listBoxCaps.Items.Add("Legal Values:");
  for (int nIndex = 0; nIndex < myCap.Values.Count; nIndex++)
  {
   float fResult = ((CapabilityContainerOneValueFloat)myCap.Values[nIndex]).Value;
   listBoxCaps.Items.Add(fResult);
  }
  break;
 } 
 // Returns a range of values as well as current and default values
 case "Accusoft.TwainProSdk.CapabilityContainerRange":
 {
  Accusoft.TwainProSdk.CapabilityContainerRange myCap = (CapabilityContainerRange)twainDevice.GetCapability(capability);
  textBoxCurrent.Text = myCap.Value.ToString();
  textBoxCurrent.Visible = true;
 
  labelDefault.Text = "Default  =  " + myCap.Default.ToString();
  labelDefault.Visible = true;
 
  labelMin.Text = "MinValue  =  " + myCap.Minimum.ToString(); ;
  labelMin.Visible = true;
 
  labelMax.Text = "MaxValue  =  " + myCap.Maximum.ToString();
  labelMax.Visible = true;
  break;
 }
}

 

See Also

 

 


©2014. Accusoft Corporation. All Rights Reserved.

Send Feedback