Can't read the second page scanned through ADF

I have a Brother multifunction network printer / scanner / fax (model MFC-9140CDN). I am trying to use the following code with WIA to retrieve items scanned with a 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 pages go through the document feeder. The first page will be saved using img.SaveFile to the path traveled, but all subsequent pages are inaccessible - device.Items.Count is 1, and an attempt to device.Items[2] throws an exception.

In the next iteration, the Transfer call throws an exception - understandably, because there are no pages in the feeder right now.

How can I get subsequent images that were scanned in the feeder?

(NB Iterating over all device properties, there is an additional unnamed property with identifier 38922. I could not find a link to this property.)

Update

I could not find the property on the device corresponding to WIA_IPS_SCAN_AHEAD or WIA_DPS_SCAN_AHEAD_PAGES , but this makes sense, since this property is optional according to the documentation.

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

+5
source share
3 answers

This is a network scanner, and I used the WSD driver.

As soon as I installed the manufacturer's driver, the behavior will be as expected - one page passes through the ADF, after which control returns to the program.

(Even now, when I use the WIA CommonDialog.ShowSelectDevice method, the scanner is available twice, once using the Windows driver and once using the Brother driver, when I select the WSD driver, I still see the problem.)

+1
source

I recently experienced a similar error with the HP MFC.

It seems that the driver has been changed. The previous software developer I'm working on just kept updating the driver every time in the for loop.

In my case, the property was 'Media Type' set to FLATBED (0x02), although I did a multi-page scan and needed it for NEXT_PAGE (0x80).

I found that this is a repository of each property in front of the scanner (both properties of the device and the item) and again after scanning the first page. Then I applied the application to print any changed properties and was able to identify my problem.

+1
source

You must instantiate and configure the device inside the while loop. Cm:

 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 studied this free project, which I believe can also help you: adfwia.codeplex.com

-1
source

Source: https://habr.com/ru/post/1209021/


All Articles