Cannot read second page scanned via ADF
Asked Answered
E

4

6

I have a Brother mutlifunction networked printer/scanner/fax (model MFC-9140CDN). I am trying to use the following code with WIA, to retrieve items scanned in with the document feeder:

const int FEEDER = 1;

var manager=new DeviceManager();
var deviceInfo=manager.DeviceInfos.Cast<DeviceInfo>().First();
var device=deviceInfo.Connect();
device.Properties["Pages"].set_Value(1);
device.Properties["Document Handling Select"].set_Value(1);

var morePages=true;
var counter=0;
while (morePages) {
    counter++;
    var item=device.Items[1];
    item.Properties["Bits Per Pixel"].set_Value(1);
    item.Properties["Horizontal Resolution"].set_Value(300);
    item.Properties["Vertical Resolution"].set_Value(300);

    var img=(WIA.ImageFile)item.Transfer();
    var path=String.Format(@"C:\Users\user1\Documents\test_{0}.tiff",counter);
    img.SaveFile(path);

    var status=(int)device.Properties["Document Handling Status"].get_Value();
    morePages = (status & FEEDER) > 0;
}

When the Transfer method is reached for the first time, all the pages go through the document feeder. The first page gets saved with img.SaveFile to the passed-in path, but all the subsequent pages are not available - device.Items.Count is 1, and trying device.Items[2] raises an exception.

In the next iteration, calling Transfer raises an exception -- understandably, because there are now no pages in the feeder.

How can I get the subsequent images that have been scanned into the feeder?

(N.B. Iterating through all the device properties, there is an additional unnamed property with the id of 38922. I haven't been able to find any reference to this property.)

Update

I couldn't find a property on the device corresponding to WIA_IPS_SCAN_AHEAD or WIA_DPS_SCAN_AHEAD_PAGES, but that makes sense because this property is optional according to the documentation.

I tried using TWAIN (via the NTwain library, which I highly recommend) with the same problem.

Except answered 14/12, 2014 at 19:25 Comment(2)
Pure speculation: TIFF supports multiple pages, could the second page be contained in that single file? Maybe check it out with Irfanview. Also if this is C# normally 1 is .Items[0] and 2 is .Items[1].Kuchen
@Kuchen (1) The additional pages are not contained in the TIFF file. This is also an impossibility, as control is returned to the next line of code before the scanner has finished scanning the next pages. (2) The first item being Items[0] is a .NET convention, not a C# convention -- in VB.NET I also have to write Dim l As New List(Of Integer): Dim firstInt = l(0). WIA for some reason has the alternate convention of the first item being .Items[1].Except
E
3

This is a networked scanner, and I was using the WSD driver.

Once I installed the manufacturer's driver, the behavior is as expected -- one page goes through the ADF, after which control is returned to the program.

(Even now, when I use WIA's CommonDialog.ShowSelectDevice method, the scanner is available twice, once using the Windows driver and once using the Brother driver; when I choose the WSD driver, I still see the issue.)

Except answered 9/8, 2015 at 20:54 Comment(2)
This also fixed the same problems with a Brother DCP-L2540DN. Might be a common problem with WSD-drivers.Veats
That fixed my problem! My device was HP Color LaserJet Pro MFP M478-M479 seriesScirrhous
W
3

I have recently experienced a similar error with a HP MFC.

It seems that a property was being changed by the driver. The previous developer of the software I'm working on just kept reinitalisating the driver each time in the for loop.

In my case the property was 'Media Type' being set to FLATBED (0x02) even though I was doing a multi-page scan and needed it to be NEXT_PAGE (0x80).

The way I found this was by storing every property before I scanner (both device and item properties) and again after scanning the first page. I then had my application print out any properties that had changed and was able to identify my problem.

Wenonawenonah answered 7/1, 2015 at 1:11 Comment(4)
At what point did you reset Media Type? Right after the call to Transfer is too late, as the rest of the pages have already started to go through the feeder.Except
@ZevSpitz In my case and in the example above the transfer is only set to pull in 1 page at a time through the feeder. So I was resetting the flags between subsequent calls to Transfer in the loopWenonawenonah
Apparently, my issue is different -- with the code above when I run Transfer all the pages go through the document feeder, not just one.Except
There's also a setting for that in some scanners, and some just ignore it :-( WIA itself is nice, but it's implementation in some OEM's drivers isn't completeWenonawenonah
E
3

This is a networked scanner, and I was using the WSD driver.

Once I installed the manufacturer's driver, the behavior is as expected -- one page goes through the ADF, after which control is returned to the program.

(Even now, when I use WIA's CommonDialog.ShowSelectDevice method, the scanner is available twice, once using the Windows driver and once using the Brother driver; when I choose the WSD driver, I still see the issue.)

Except answered 9/8, 2015 at 20:54 Comment(2)
This also fixed the same problems with a Brother DCP-L2540DN. Might be a common problem with WSD-drivers.Veats
That fixed my problem! My device was HP Color LaserJet Pro MFP M478-M479 seriesScirrhous
A
0

This bug did cost me hours... So thanks a lot Zev.

I also had two scanners shown in the dialog for physically one machine. One driver scans only the first page and then empties the feeder without any chance to intercept. The other one works as expected.

BTW: It is not needed to initialize the scanner for each page. I call my routines for initialization prior to the Transfer() loop. Works just fine.

Another hickup I ran into was to first initialize page sizes, then the feeder. So if you do not get it to work, try switching the sequence how you change the properties for your WIA driver. As mentioned in the MSDN, some properties also influence others, potentially resetting your changes.

So praise to ZEV SPITZ for the answer on Aug. 09, 2015.

Abominable answered 12/2, 2022 at 23:8 Comment(0)
G
-1

You should instantiate and setup device inside the 'while' loop. See:

const int FEEDER = 1;

var morePages=true;
var counter=0;
while (morePages) {
    counter++;

    var manager=new DeviceManager();
    var deviceInfo=manager.DeviceInfos.Cast<DeviceInfo>().First();
    var device=deviceInfo.Connect();

    //device.Properties["Pages"].set_Value(1);
    device.Properties["Document Handling Select"].set_Value(1);

    var item=device.Items[1];
    item.Properties["Bits Per Pixel"].set_Value(1);
    item.Properties["Horizontal Resolution"].set_Value(300);
    item.Properties["Vertical Resolution"].set_Value(300);

    var img=(WIA.ImageFile)item.Transfer();
    var path=String.Format(@"C:\Users\user1\Documents\test_{0}.tiff",counter);
    img.SaveFile(path);

    var status=(int)device.Properties["Document Handling Status"].get_Value();
    morePages = (status & FEEDER) > 0;
}

I got this looking into this free project, which I believe is able to help you too: adfwia.codeplex.com

Godliman answered 17/12, 2014 at 18:38 Comment(2)
I have the same issue while trying to use adfwia.Except
Why did you think this would make a difference?Except

© 2022 - 2024 — McMap. All rights reserved.