Enabled Scan doesn't Work

Issue #73 new
Rodrigue created an issue

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)

  1. Eugene Wang repo owner

    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).

    // I only know c# but should be similar to vb
    ReturnCode rc = oTWDatasource.Open();
    if (rc == ReturnCode.Success) {
        rc = oTWDatasource.Enable(...);
        if (rc == ReturnCode.Success)
        {
            return;
        }
    }
    
    TWStatus status = oTwain.GetStatus();
    // log status and rc values here
    
    // close source if didn't enable successfully
    if (oTwain.State == 4) { oTWDatasource.Close(); }
    

    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.

  2. Rodrigue 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

  3. Petr Valenta

    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.

  4. Bogdan Anghel

    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.

  5. Log in to comment