Twain Duplex (Visual Basic)

Take the following steps to start a project and to add some code that acquires the images using Fast Twain:

1.

Start Visual Basic.

2.

Add the LEAD RasterTwain Object Library and LEAD Raster Variant Object Library to your project.

 

On the Project pull-down menu, use the References option, and select the LEAD RasterTwain Object Library.

 

On the Project pull-down menu, use the References option, and select the LEAD Raster Variant Object Library.

3.

Add the LEAD Raster IO Object Library to your project. On the Project pull-down menu, use the References option, and select the LEAD Raster IO Object Library.

4.

Add the following code to the general declarations section of your project:

Public TwainCap As New LEADTwainCapability
Public WithEvents RasterTwain As LEADRasterTwain

5.

Add the following code to the main form's Load procedure:

Set RasterTwain = New LEADRasterTwain
RasterTwain.InitSession hWnd
RasterTwain.EnableMethodErrors = False

6.

Add the following code to the main form's Unload procedure:

RasterTwain.EndSession

7.

Add the following button:

 

Name

Caption

 

cmdAcquire

Acquire

8.

Code the Acquire control's Click procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

Private Sub cmdAcquire_Click()
   Dim nRet As Integer
   RasterTwain.SelectSource
   
   TwainCap.CapInfo.Capability = L_CAP_DUPLEX
   TwainCap.CapInfo.ConType = L_TWON_ONEVALUE

   nRet = RasterTwain.GetCapability2(TwainCap, L_LTWAIN_CAPABILITY_GETVALUES) 
   If nRet = 0 Then
      ' check if the selected driver supports duplex capability
      If TwainCap.CapOneValue.OneValItemType <> L_TWTY_UINT16 Then
         RasterTwain.EndSession
         Exit Sub
      End If

      Dim item As Integer
      item = TwainCap.CapOneValue.OneValCapValue.LongValue

      Select Case item
      Case L_TWDX_NONE
         MsgBox "Duplex capability is not supported in the selected driver"
      Case L_TWDX_1PASSDUPLEX
         MsgBox "1 Pass Duplex capability is supported in the selected driver"
      Case L_TWDX_2PASSDUPLEX
         MsgBox "2 Pass Duplex capability is supported in the selected driver"
      End Select

      ' make sure the duplex capability is enabled
      If item <> L_TWDX_NONE Then
         Dim bEnable As Boolean
         bEnable = True
         
         TwainCap.CapInfo.Capability = L_CAP_DUPLEXENABLED
         TwainCap.CapInfo.ConType = L_TWON_ONEVALUE
         
         Dim RasVar As New LEADRasterVariant
         RasVar.Type = VALUE_BOOLEAN
         RasVar.BooleanValue = bEnable
         
         TwainCap.CapOneValue.OneValItemType = L_TWTY_BOOL
         TwainCap.CapOneValue.OneValCapValue = RasVar
         
         nRet = RasterTwain.SetCapability2(TwainCap, L_LTWAIN_CAPABILITY_SET) 
         If nRet = 0 Then
            MsgBox "The duplex capability is enabled"
         Else
            MsgBox "Can't enable duplex capability"
         End If
      End If
   Else
      MsgBox "Duplex capability is not supported in the selected driver"
   End If

   ' try to acquire pages using duplex capability
   RasterTwain.Acquire L_LTWAIN_SHOW_USER_INTERFACE Or L_LTWAIN_MODAL_USER_INTERFACE
End Sub