soukoku / ntwain

A TWAIN lib for dotnet.
MIT License
116 stars 46 forks source link

Scanning from ADF returning only first page #58

Open jaidan22 opened 3 months ago

jaidan22 commented 3 months ago

Hi @soukoku ,

I am currently using an HP LaserJet Pro printer with an ADF. While using the TWAIN driver, I issue encountered was - only the first page is returned to the application, even though all pages pass through the feeder. Interestingly, when I switch to the WIA Driver, everything works as expected, and all pages are returned.

The sample project are also showing the same behavior. However, when I tested an alternate package, it worked fine. Based on this, it seems less likely that the scanner itself is the problem.

Below are the capability values:

CapAutomaticSenseMedium = False 
CapPaperDetectable = True 
ICapFeederType = General 
CapFeederEnabled = True 
ICapPixelType / Depth = BlackWhite 
CapAutoFeed = True 
CapAutoScan = False 
CapAutoScan.CanSet = False 
CapXferCount = -1 
CapFeederLoaded = True 
CapFeedPage = False 
CapClearPage = False 
CapRewindPage = False 
jaidan22 commented 3 months ago

The following code snippet is from TransferLogic.cs file

// some poorly written scanner drivers return failures on EndXfer, so also check for the pending count now.
// this may break with other sources but we'll see
if (//pending.Count == 0 && 
    session.State > 5)
{
    session.ChangeState(5, true);
    session.DisableSource();
}

Why is pending.Count == 0 commented? Could this be the reason behind this error?

fuchuba commented 3 months ago

Hi @jaidan22 , I encountered the same issue when using the HP scanjet 2000 scanner with ADF. I comment "//pending.Count == 0 &&" off, and test again. There is still only the first page returned to the application. May I ask if you have resolved it? If it's resolved, can you tell me how it was resolved?

jaidan22 commented 2 months ago

No. It hasn't been resolved yet.

fuchuba commented 2 months ago

I edited the source code file that name "NTwain\Internals\TransferLogic.cs". I replaced the line “rc = session.DGControl.PendingXfers.Get(pending);” with code snippet below:

ReturnCode rc = ReturnCode.Failure;
if (session.CurrentSource.Identity.ProductName.IndexOf("scanjet", StringComparison.OrdinalIgnoreCase) > -1 || session.CurrentSource.Identity.ProductName.IndexOf("HP", StringComparison.OrdinalIgnoreCase) > -1)
{
    rc = ReturnCode.Success;
}
else
{
    rc = session.DGControl.PendingXfers.Get(pending);
}

I compiled on x86 architecture and tried again. The HP scanjet 2000 scanner seemed to work ok for ADF. But I compiled on x64 architecture and tried again. The HP scanjet 2000 scanner seemed not to work good for ADF. Advice to use on x86 architecture. Good luck!

abhinavshrivastavabpk commented 1 month ago

Hello,

I am also facing the same issue with HP Scan Jet Pro 2600 f1 ( Twain 2.4) and HP Pro M478f-9f TW (Twain 2.1).

I added debug statements inside Internals\TransferLogic.cs file in DoTransferRoutine() function and figured out that rc = session.DGControl.PendingXfers.EndXfer(pending); returns pending.count as 0 after first page is scanned even though there are more pages in the ADF.

When pending.count =0 , the below while statement fails and execution comes out of this while responsible for scanning multiple pages from ADF. while (rc == ReturnCode.Success && pending.Count != 0 && !session.CloseDSRequested);

This means session.DGControl.PendingXfers.EndXfer(pending) is not returning the correct value of pending.

Any help will be highly appreciated.

Thanks.

abhinavshrivastavabpk commented 1 month ago

Hello,

I printed all capabilities. Out of all capabilities in the list, "ICapPhysicalHeight: 122" and "ICapFrames: L=0, T=0, R=8.5, B=122" caught my attention. The page length is coming as 122 inches. According to HP user manual, 8.5 by 122 inches is an Extra Long Page Size, and, "Only one page can be scanned when using a long or extra long page setting". I think this is why I am not able to scan more than one page.

I changed the page length through SupportedSizes = USLetter. I again printed the list of all capabilities. Now "ICapPhysicalHeight: 122" and "ICapFrames: L=0, T=0, R=8.266663, B=11.67999". But still I am not able to scan more than one page.

If "ICapPhysicalHeight: 122" restricting me from scanning more than one page, why is HP Twain driver sending Physical width as 122 ?

Any Suggestions.

Thanks