Cannot read second page scanned via ADF

陌路散爱 提交于 2020-01-03 10:55:10

问题


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.


回答1:


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.




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/27473142/cannot-read-second-page-scanned-via-adf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!