This project has moved. For the latest updates, please go here.

Problem with HP Laserjet 1212nf MFP

Jan 19, 2016 at 11:55 AM
Hi..
please help me.. here is my case..
when scanning using wia as datasource i got the result image on flatbed, but not on feeder.
when i use twain as datasource i got the same result too. i try to debug but it seem it didn't pass the AcquireCompleted event.
here is my code :
Dim _xferMech As Twain32.Enumeration

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If cbSource.SelectedIndex < 0 Then
        cbSource.Focus()
        Exit Sub
    End If

    Try
        _Twain32.CloseDataSource()
        _Twain32.SourceIndex = Me.cbSource.SelectedIndex
        _Twain32.OpenDataSource()
    Catch ex As Exception

    End Try

    Try
        _xferMech = Me._Twain32.Capabilities.XferMech.[Get]()
        _Twain32.Capabilities.XferMech.[Set](TwSX.Native)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

    Try
        _Twain32.OpenDataSource()
        _Twain32.Capabilities.PixelType.[Set](TwPixelType.RGB)
        _Twain32.Capabilities.XResolution.Set(150)
        _Twain32.Capabilities.YResolution.Set(150)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

    Try
        If (Me._Twain32.IsCapSupported(TwCap.Duplex) And TwQC.GetCurrent) <> 0 Then
            Dim _duplexCapValue = DirectCast(_Twain32.GetCurrentCap(TwCap.Duplex), TwDX)
            If _duplexCapValue <> TwDX.None Then
                If (_Twain32.IsCapSupported(TwCap.DuplexEnabled) And TwQC.[Set]) <> 0 Then
                    If cbDuplex.Checked = True Then
                        _Twain32.SetCap(TwCap.DuplexEnabled, True)
                    Else
                        _Twain32.SetCap(TwCap.DuplexEnabled, False)
                    End If
                End If
            End If
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

    Try
        If cbFeeder.Checked = True Then
            _Twain32.SetCap(TwCap.FeederEnabled, True)
            If _Twain32.IsCapSupported(TwCap.SupportedSizes) And TwQC.[Set] <> 0 Then
                _Twain32.SetCap(TwCap.SupportedSizes, TwSS.USLegal)
            End If
        Else
            Me._Twain32.SetCap(TwCap.FeederEnabled, False)
            If _Twain32.IsCapSupported(TwCap.SupportedSizes) And TwQC.[Set] <> 0 Then
                _Twain32.SetCap(TwCap.SupportedSizes, TwSS.A4)
            End If
        End If
    Catch ex As Exception
        _Twain32.ShowUI = True
        MsgBox(ex.Message)
    End Try

    _Twain32.Acquire()
End Sub
Private Sub _SetImage(ByVal image As Image)
    If Not Me.pbox1.Image Is Nothing Then
        Me.pbox1.Image.Dispose()
    End If
    Me.pbox1.Image = image
End Sub
Private Sub _twain32_AcquireCompleted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Twain32.AcquireCompleted
    Try
        If Me._Twain32.ImageCount > 0 Then
            Me._SetImage(Me._Twain32.GetImage(0))
        End If
    Catch ex As Exception
        MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub
that code is working fine on kyocera fs-1128mfp and higher version. not working on lower version. i'm still newbie, please help.
Coordinator
Jan 20, 2016 at 5:15 PM
Hello, kairi_ex2.
Your code contains some errors. See TWAIN Specification , namely, CAP_DUPLEX, CAP_DUPLEXENABLED, CAP_AUTOFEED, CAP_FEEDERENABLED, CAP_FEEDERLOADED, CAP_XFERCOUNT capabilities.
The following excerpt from the application code using the ADF.
private void _DeviceChanged() {
    if(this.twain.SourcesCount>0) {
        this.twain.CloseDataSource();
        this.twain.SourceIndex=this.deviceComboBox.SelectedIndex;
        try {
            this.twain.OpenDataSource();

            // ...

            //Duplex
            try {
                this._TwainDuplex();
            } catch(TwainException) {
            }

            //Feeder
            try {
                this._TwainFeederEnabled();
            } catch(TwainException) {
            }

            //XferCount
            try {
                this._TwainXferCount();
            } catch(TwainException) {
            }

            //AutoFeed
            try {
                this._TwainAutoFeed();
            } catch(TwainException) {
            }
        } catch(TwainException) {
            this.duplexCheckBox.Checked=this.feederCheckBox.Checked=this.autofeedCheckBox.Checked=
                this.duplexCheckBox.Enabled=this.feederCheckBox.Enabled=this.autofeedCheckBox.Enabled=this.acquireButton.Enabled=false;
        }
    }
}

private void _EndXfer(Image image) {
    if(image!=null) {

        // ...

        image.Dispose();
    }
}

private void _TwainFeederEnabled() {
    var _isFeederEnabledSupported=this.twain.Capabilities.FeederEnabled.IsSupported();
    this.feederCheckBox.Checked=(_isFeederEnabledSupported&TwQC.GetCurrent)!=0 && this.twain.Capabilities.FeederEnabled.GetCurrent();
    this.feederCheckBox.Enabled=(_isFeederEnabledSupported&TwQC.Set)!=0;
}

private void _TwainAutoFeed() {
    var _isAutoFeedSupported=this.twain.Capabilities.AutoFeed.IsSupported();
    this.autofeedCheckBox.Checked=(_isAutoFeedSupported&TwQC.GetCurrent)!=0 && this.twain.Capabilities.AutoFeed.GetCurrent();
    this.autofeedCheckBox.Enabled=
        (this.twain.Capabilities.FeederEnabled.IsSupported()&TwQC.GetCurrent)!=0 && this.twain.Capabilities.FeederEnabled.GetCurrent() && 
        (_isAutoFeedSupported&TwQC.Set)!=0;
}

private void _TwainXferCount() {
    if((this.twain.Capabilities.FeederEnabled.IsSupported()&TwQC.GetCurrent)!=0&&this.twain.Capabilities.FeederEnabled.GetCurrent()&&(this.twain.Capabilities.XferCount.IsSupported()&TwQC.Set)!=0) {
        this.twain.Capabilities.XferCount.Set(-1);
    }
}

private void _TwainDuplex() {
    var _isDuplexEnabledSupported=this.twain.Capabilities.DuplexEnabled.IsSupported();

    this.duplexCheckBox.Checked=
        (this.twain.Capabilities.Duplex.IsSupported()&TwQC.GetCurrent)!=0&&this.twain.Capabilities.Duplex.GetCurrent()!=TwDX.None&&
        ((_isDuplexEnabledSupported&TwQC.GetCurrent)!=0)&&this.twain.Capabilities.DuplexEnabled.GetCurrent();

    this.duplexCheckBox.Enabled=(_isDuplexEnabledSupported&TwQC.Set)!=0;
}

// ========= EVENT HANDLERS ============

private void acquireButton_Click(object sender,EventArgs e) {
    try {
        this.primaryPanel.Enabled=this.cancelButton.Enabled=false;

        if((this.twain.Capabilities.FeederEnabled.IsSupported()&TwQC.GetCurrent)!=0 && this.twain.Capabilities.FeederEnabled.GetCurrent() && (this.twain.Capabilities.FeederLoaded.IsSupported()&TwQC.GetCurrent)!=0) {
            for(var _isIgnore=false; !_isIgnore&&!this.twain.Capabilities.FeederLoaded.GetCurrent(); ) {
                switch(MessageBox.Show(String.Format("Feeder is empty. {0}Continue?",Environment.NewLine),"Application",MessageBoxButtons.AbortRetryIgnore,MessageBoxIcon.Warning)) {
                    case DialogResult.Abort:
                        this.primaryPanel.Enabled=this.cancelButton.Enabled=true;
                        // ...
                        return;
                    case DialogResult.Retry:
                        continue;
                    case DialogResult.Ignore:
                        _isIgnore=true;
                        break;
                }
            }
        }

        this.twain.Acquire();
    } catch(Exception ex) {
        this.ErrorMessageBox(ex);
    } finally {
        this.cancelButton.Enabled=true;
    }
}

private void twain_AcquireCompleted(object sender,EventArgs e) {
    try {
        // ...
        this.primaryPanel.Enabled=this.cancelButton.Enabled=true;
        // ...
    } catch(Exception ex) {
        // ...
    }
}

private void twain_AcquireError(object sender,Twain32.AcquireErrorEventArgs e) {
    try {
        MessageBox.Show(e.Exception.Message,e.Exception.GetType().Name,MessageBoxButtons.OK,MessageBoxIcon.Error);
    } catch(Exception ex) {
        // ...
    }
}

private void twain_EndXfer(object sender,Twain32.EndXferEventArgs e) {
    try {
        this._EndXfer(e.Image);
    } catch(Exception ex) {
        // ...
    }
}

private void feederCheckBox_CheckedChanged(object sender,EventArgs e) {
    try {
        this.twain.Capabilities.FeederEnabled.Set(this.feederCheckBox.Checked);
        this._TwainXferCount();
        this._deviceChanged=true;
        this._TwainAutoFeed();
    } catch(Exception ex) {
        try {
            this._TwainFeederEnabled();
            this._TwainXferCount();
        }
        // ...
    }
}

private void autofeedCheckBox_CheckedChanged(object sender,EventArgs e) {
    try {
        this.twain.Capabilities.AutoFeed.Set(this.autofeedCheckBox.Checked);
    } catch(Exception ex) {
        try {
            this._TwainAutoFeed();
        }
        // ...
    }
}

private void duplexCheckBox_CheckedChanged(object sender,EventArgs e) {
    try {
        this.twain.Capabilities.DuplexEnabled.Set(this.duplexCheckBox.Checked);
    } catch(Exception ex) {
        try {
            this._TwainDuplex();
        }
        // ...
    }
}

private void deviceComboBox_SelectedIndexChanged(object sender,EventArgs e) {
    try {
        if(!this._isLoading) {
            this._DeviceChanged();
        }
    } catch(Exception ex) {
        // ...
    }
}
Jan 22, 2016 at 10:19 PM
Hi.. thanks for helping me.
i've tried your code but still doesn't work on twain datasource. Here is what i got:
  1. select ds to twain driver and scan using feeder.
  2. when i debug, event acquirecomplete is not passed and no image transfer on event endxfer.
  3. however, when i choose wia driver as datasource, it work, image transfer on event endxfer and i can transfer it to picture object.
    Any help please..
Coordinator
Jan 24, 2016 at 6:50 AM
Hello, kairi_ex2.
Maybe problem is related with the TWAIN driver. Try to other scanners.
Marked as answer by SARAFF on 2/11/2016 at 6:56 AM