Having a problem getting this working after following some samples and checking ways to fix this error with other questions posted on here, nothing working so far.
It scans the first page and when the code loops around to where it should get the second image it always throws exception saying the device is busy, is there anyway to pause or stop the scanning in document feeder after each page to prevent this exception?
string deviceid;
List<ImageFile> images = new List<ImageFile>();
CommonDialogClass dlg = new CommonDialogClass();
Device d = dlg.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);
if (d != null)
{
deviceid = d.DeviceID;
}
else
{
//no scanner chosen
return;
}
bool hasMorePages = true;
int x = 0;
int numPages = 0;
while (hasMorePages)
{
DeviceManager manager = new DeviceManagerClass();
Device WiaDev = null;
foreach (DeviceInfo info in manager.DeviceInfos)
{
if (info.DeviceID == deviceid)
{
WIA.Properties infoprop = null;
infoprop = info.Properties;
WiaDev = info.Connect();
break;
}
}
SelectDeviceDocumentHandling(WiaDev, DeviceDocumentHandling.Feeder);
SetDeviceProperty(WiaDev, DEVICE_PROPERTY_PAGES_ID, 1);
ImageFile img = null;
Item Item = WiaDev.Items[1];
try
{
WIA.CommonDialog WiaCommonDialog = new WIA.CommonDialog();
img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, FormatID.wiaFormatPNG, false);
images.Add(img);
numPages++;
img = null;
}
catch (Exception ex) //ex.Message "0x80210003" means no documents found in feeder
{
if (ex.Message.Contains("0x80210015")) MessageBox.Show("Could not connect to scanner", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else if (ex.Message.Contains("0x80210006")) MessageBox.Show("Device is busy", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //where I get exception on second page each time
else if (ex.Message.Contains("0x80210003")) MessageBox.Show("No documents found in document feeder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Item = null;
//determine if there are any more pages waiting
Property documentHandlingSelect = null;
Property documentHandlingStatus = null;
foreach (Property prop in WiaDev.Properties)
{
if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT)
documentHandlingSelect = prop;
if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS)
documentHandlingStatus = prop;
}
hasMorePages = false; //assume there are no more pages
if (documentHandlingSelect != null)
//may not exist on flatbed scanner but required for feeder
{
//check for document feeder
if ((Convert.ToUInt32(documentHandlingSelect.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER) != 0)
{
hasMorePages = ((Convert.ToUInt32(documentHandlingStatus.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY) != 0);
}
}
x++;
}
}
I've tried solutions from the following post with no luck, as well as searching around the web a lot: Scanning with WIA automatic feeder scanner fails for second page
Wondering if this might also be a problem with my specific scanner, I'm working from home but will be able to test on work scanner when back in office next week.