Dynamsoft Home|Product Home

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 TW_ONEVALUE
  • Setting Capability with TW_ARRAY
  • Setting Capability with TW_ENUMERATION
  • Setting Capability with TW_RANGE
  • Reading Value(s) through Capability Negotiation
  •  

    Setting Capability with TW_ONEVALUE

    TW_ONEVALUE capability container type can be used to set or return a single value (item) of a capability.

    To set a capability with TW_ONEVALUE container, the following steps are needed:

  • Call OpenSource() to bring Dynamic TWAIN to the state for capability negotiation;
  • Set the Capability property to the capability to be negotiated;
  • Set the CapType property to TW_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.
  •     

    VB Sample:
    Twain.OpenSource
    
    Twain.Capability = ICAP_UNITS
    Twain.CapType = TWON_ONEVALUE
    Twain.CapValue = 0        'TWUN_INCHES
    
    If Twain.CapSet = True Then
        MsgBox "Successful."
    Else
        MsgBox "Failed." + vbCrLf + Twain.ErrorString, vbCritical + vbOKOnly
    End If

     

     

    Setting Capability with TW_ARRAY

    TW_ARRAY capability container type can be used to set or return a group of associated individual values.

    To set a capabilIty with TW_ARRAY  container, the following steps are needed:

  • Call OpenSource() to bring Dynamic TWAIN to the state for capability negotiation;
  • Set the Capability property to the capability to be negotiated;
  • Set the CapType property to TW_ARRAY;
  • Set the CapNumItems property to indicate how many items are in the array;
  • If the data type of the capability is String, set the values of CapItemsString property. For any other data types, set the values of CapItems property;
  • Call CapSet() to actually set the value.
  •    

    VB Sample:  
    Twain.OpenSource
    Twain.Capability = ICAP_FILTER
    Twain.CapType = TWON_ARRAY
    Twain.CapNumItems = 3    'Set cap values count.
    'Set the cap's values
    Twain.CapItems(0) = 3    'TWFT_NONE
    Twain.CapItems(1) = 1    'TWFT_GREEN
    Twain.CapItems(2) = 2    'TWFT_BLUE
    If Twain.CapSet = True Then
        MsgBox "Successful."
    Else
        MsgBox "Failed." + vbCrLf + Twain.ErrorString, vbCritical + vbOKOnly
    End If

          

     

    Setting Capability with TW_ENUMERATION

    TW_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 TW_ENUMERATION  container, the following steps are needed:

  • Call OpenSource() to bring Dynamic TWAIN to the state for capability negotiation;
  • Set the Capability property to the capability to be negotiated;
  • Set the CapType property to TW_ENUMERATION;
  • Set the CapNumItems property to indicate how many items are in the array;
  • If the data type of the capability is String, set the values of CapItemsString property. For any other data types, set the values of CapItems property;
  • Set the CapCurrentIndex to indicate the index of the current value;
  • Call CapSet() to actually set the value.
  •    

    VB Sample:
    Twain.OpenSource
    Twain.Capability = ICAP_XRESOLUTION
    Twain.CapType = TWON_ENUMERATION
    Twain.CapNumItems = 3    'Set the cap values count.
    'Set the cap's values
    Twain.CapItems(0) = 80
    Twain.CapItems(1) = 100
    Twain.CapItems(2) = 120
    Twain.CapCurrentIndex = 2    'Set the cap's current value's index in the ENEMERATION.
    If Twain.CapSet = True Then
        MsgBox "Successful."
    Else
        MsgBox "Failed." + vbCrLf + Twain.ErrorString, vbCritical + vbOKOnly
    End If
     

     

    Setting Capability with TW_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 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.
  •    

    VB Sample:
    Twain.OpenSource
    Twain.Capability = ICAP_XRESOLUTION
    Twain.CapType = TWON_RANGE
    'Set the cap's values
    Twain.CapMinValue = 80
    Twain.CapMaxValue = 200
    Twain.CapStepSize = 20
    Twain.CapCurrentValue = 120
    If Twain.CapSet = True Then
        MsgBox "Successful."
    Else
        MsgBox "Failed." + vbCrLf + Twain.ErrorString, vbCritical + vbOKOnly
    End If
     

     

    Reading Value(s) from Capability Negotiation

    To read values from a capability:

  • Call OpenSource() to bring Dynamic 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.
  •  

    VB Sample:
    Twain.OpenSource
    
    Twain.Capability = CAP_xxx   
    
    If Twain.CapGet = False Then
        MsgBox "Failed." + vbCrLf + Twain.ErrorString, vbCritical + vbOKOnly
        Exit Sub
    End If
    
    
    If (Twain.CapType = TWON_ONEVALUE) Then 
        
        txtCap = "Container type is TWON_ONEVALUE" + vbCrLf
        txtCap = txtCap + "Current Value:" + Twain.CapValue + vbCrLf
    
    ElseIf (Twain.CapType = TWON_ARRAY) Then
    
        txtCap = "Container type is TWON_ARRAY"+ vbCrLf
        txtCap = txtCap + "Available Values:"
    
        For lngIndex =0 To Twain.CapNumItems - 1
    
            If (lngIndex < Twain.CapNumItems - 1) Then
                txtCap = txtCap + CStr(Twain.CapItems(lngIndex)) + ","
            Else
                txtCap = txtCap + CStr(Twain.CapItems(lngIndex))
            End If
    
        Next
    
    ElseIf (Twain.CapType = TWON_ENUMERATION) Then
    
        txtCap = "Container type is TWON_ENUMERATION"+ vbCrLf
        txtCap = txtCap + "Current Value:" + CStr(Twain.CapItems(Twain.CapCurrentIndex))+ vbCrLf
        txtCap = txtCap + "Default Value:" + CStr(Twain.CapItems(Twain.CapDefaultIndex))+ vbCrLf
        txtCap = txtCap + "Available Values:"
    
        For lngIndex = 0 To Twain.CapNumItems - 1
    
            If (lngIndex < Twain.CapNumItems - 1) Then 
                txtCap = txtCap + CStr(Twain.CapItems(lngIndex)) + ","
            Else
                txtCap = txtCap + CStr(Twain.CapItems(lngIndex))
            End If 
        Next
    
    ElseIf (Twain.CapType = TWON_RANGE) Then 
    
        txtCap = "Container type is TWON_RANGE"+ vbCrLf
        txtCap = txtCap + "Current Value:" + CStr(Twain.CapCurrentValue)+ vbCrLf
        txtCap = txtCap + "Default Value:" + CStr(Twain.CapDefaultValue)+ vbCrLf
        txtCap = txtCap + "Min Value:" + CStr(Twain.CapMinValue)+ vbCrLf
        txtCap = txtCap + "Max Value:" + CStr(Twain.CapMaxValue)+ vbCrLf
        txtCap = txtCap + "Step Size:" + CStr(Twain.CapStepSize)
    
    End If 
    

     

    See Also

    Capability Container Types