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.
source share