Enabled Scan doesn't Work
Hello, sorry for my bad english .... :D
I need help because scan not working for me.
No error message, no Exception .... Just not working in call "
oTWDatasource.Enable(NTwain.SourceEnableMode.NoUI, False, IntPtr.Zero)
I d'ont understand, i'm so tired to looking for resolve my problem.
Here my code, please help me lol
Private _oTwain As NTwain.TwainSession
Public Function ScanImage(p_oForm As Form) As Image
Dim oTwIdentity As NTwain.Data.TWIdentity = NTwain.Data.TWIdentity.CreateFromAssembly(NTwain.Data.DataGroups.Image, Reflection.Assembly.GetEntryAssembly())
_oTwain = New NTwain.TwainSession(oTwIdentity)
_oTwain.SynchronizationContext = WindowsFormsSynchronizationContext.Current
' ajout des événements
AddHandler _oTwain.TransferReady, AddressOf TW_TransfertReady
AddHandler _oTwain.DataTransferred, AddressOf Tw_DataTransfert
_oTwain.Open()
If _oTwain IsNot Nothing AndAlso _oTwain.Count > 0 Then
For Each oTWDatasource As NTwain.DataSource In _oTwain
If oTWDatasource.Name = "EPSON GT-1500" Then
oTWDatasource.Open()
oTWDatasource.Enable(NTwain.SourceEnableMode.NoUI, False, IntPtr.Zero)
oTWDatasource.Close()
Exit For
End If
Next
_oTwain.Close()
End If
' zone de paramètreage
For Each enc As System.Drawing.Imaging.ImageCodecInfo In System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()
If enc.MimeType = "image/tiff" Then
_oTiffCodec = enc
Exit For
End If
Next
End Function
Private Sub Tw_DataTransfert(sender As Object, e As NTwain.DataTransferredEventArgs)
e.ToString()
End Sub
Private Sub TW_TransfertReady(sender As Object, e As NTwain.TransferReadyEventArgs)
e.ToString()
End Sub
Private Sub TW_DataSourceDisable(sender As Object, e As EventArgs)
e.ToString()
End Sub
Comments (4)
-
repo owner -
reporter Thank for your rapid answer.
i have updated my source to obtain that
If oTWDatasource.Name = "EPSON GT-1500" Then oRC = oTWDatasource.Open() If oRC = NTwain.Data.ReturnCode.Success Then oRC = oTWDatasource.Enable(NTwain.SourceEnableMode.NoUI, False, IntPtr.Zero) 'Succes But my scan doesn't work and don't make a mecanic scan If oRC = NTwain.Data.ReturnCode.Success Then oTWDatasource.Close() Else oTWStatus = _oTwain.GetStatus() End If Exit For End If End If
But, alls operations give me a Sucess result. For the close, in fact, doesn't work but it is normal.
I dont understand ... I'm so disapointed by this problem
-
Hello
I'm facing the same trouble.
Before the Enable I'm in state 4, after it I remain in 5 ...
Is there any solution?
Petr Valenta
Possible explanation:
Just wait a few seconds in the code just somewhere near Enable by means of Yield() and Sleep(...);. The scanner seems to need some time to awake the appropriate structures. If the code immediately leaves, the scanner is not contacted.
-
Hi guys. I had the same issue and after many hours of testing I've managed to get it to work with a Thread.Sleep(1000) call just before the Enable call. Now it's all good. Hope this helps.
- Log in to comment
It may help by checking the return code of each call for success before moving onto the next one (and get detailed status if not success).
Also you're trying to close the source right after Enable(), which wouldn't work because Enable does not block. You should only close when source is in state 4 (opened state). The scanner is in this state in both the SourceDisabled event handler and before you successfully enable a source.