Source gets disabled before transfer is complete

Issue #10 resolved
piedar created an issue

Using HP Scanjet Enterprise 7000 s2, I see two problems in TransferLogic at DoTransferRoutine(ITwainSessionInternal session).

First, when xferGroup is None, CapGetCurrent(CapabilityID.ICapXferMech) returns null causing a NullPtrException when you pass it to ConvertToEnum<XferMech>(). Either don't assume Image when xferGroup is None, or check the capability for null:

object capMech = session.CurrentSource.CapGetCurrent(CapabilityId.ICapXferMech);
if (capMech != null)
{
    XferMech mech = capMech.ConvertToEnum<XferMech>();
    switch (mech)
    {
        ...

In this same case where xferGroup is None, EndXfer(pending) returns failure. As a result, we fall out of the loop and disable the source. There are more pages so the transfer routine gets called again, but it fails because the source is disabled. Here's how I fixed it:

if (pending.Count == 0)
{
    session.ChangeState(5, true);
    session.DisableSource();
}

Comments (3)

  1. piedar reporter

    The first change is good, but the change to the while condition makes an infinite loop of

    Trying to raise event TransferReadyEventArgs on thread 10 without sync.
    

    To work for me, it has to fall out of the loop on failure but only disable the source if there's nothing pending.

  2. Log in to comment