Page 1 of 1

Scanning Fails after me.close

Posted: Fri Nov 20, 2009 10:54 pm
by jdomkus
I have a scanning application that once I do a me.close on the form and then go back in to try to scan something it gives a error that the computer cannot communicate with the scanner.

If I just do a me.visible=false and then go back in it works fine

Any ideas on why this is happening?

Re: Scanning Fails after me.close

Posted: Sat Nov 21, 2009 12:33 pm
by Loïc

How to reproduce your problem ? The information you gave are not sufficient for investigation.

Maybe you have to unload the TWAIN source manager before calling "me.close" ? See method TwainUnloadSourceManager.

Kind regards,


Re: Scanning Fails after me.close

Posted: Sun Nov 22, 2009 6:18 pm
by jdomkus

I just took your twain sample and created a new form (form2) with two buttons (One scan and one return), Then I copied all of your code from behind the scan all document feeder (adf) into jpeg files and pasted that behind the scan button on form2. I also commented out the initscanconfig, applyimagefilters and check preview routines. Behind the return button I have a me.close and I also make form1.visible=true

When I click the scan button (I created) on form2 the first time it scans all documents fine, then I press the return button to return to the first screen. If I try to go to form2 again to scan, It either just sits at the scanner screen or gives me a error that it cannot connect to the scanner.

Below is the code behind the scan button on form 2, Behind the return button is only me.close and form1.visible=true

'Here we will scan in a 24bpp & 300 DPI from ADF into separate jpeg files
Dim nImageCount As Integer
Dim ImageID As Integer
Dim oGdPictureImaging As New GdPictureImaging

If oGdPictureImaging.TwainOpenDefaultSource(Me.Handle) Then
nImageCount = 0


oGdPictureImaging.TwainSetAutoFeed(True) 'Set AutoFeed Enabled
oGdPictureImaging.TwainSetAutoScan(True) 'To achieve the maximum scanning rate
oGdPictureImaging.TwainSetPixelType(TwainPixelType.TWPT_RGB) 'RGB
oGdPictureImaging.TwainSetBitDepth(8) ' 24 bpp

ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(Me.Handle)
If ImageID <> 0 Then
'Call ApplyImageFilters(ImageID)
'If chkPreview.CheckState = 1 Then Call DisplayImage(ImageID)
nImageCount = nImageCount + 1
Call oGdPictureImaging.SaveAsJPEG(ImageID, My.Application.Info.DirectoryPath & "\image" & Trim(Str(nImageCount)) & ".jpg", 75)
Call oGdPictureImaging.ReleaseGdPictureImage(ImageID)
End If
Loop While oGdPictureImaging.TwainGetState > TwainStatus.TWAIN_SOURCE_ENABLED

Call oGdPictureImaging.TwainCloseSource()
MsgBox("Done !")
MsgBox("can't open default source, twain state is: " & oGdPictureImaging.TwainGetState.ToString)
End If

Thanks for your help

Re: Scanning Fails after me.close

Posted: Sun Nov 22, 2009 6:34 pm
by Loïc

Could you try TwainCloseSourceManager() instead of TwainCloseSource() ?

Kind regards,