I have a .NET application that scans images from a document feeder but pages are being skipped when scanning.
The current scanner I use is Toshiba e-STUDIO2550C Series connected to my PC via LAN. I am using .NET 4.6.1 on Windows 10 64 bit. The problem also occurs on another computer running Windows Server 2012 R2. My code is as follows:
public const int WIA_DPS_DOCUMENT_HANDLING_SELECT = 3088;
public const int FEEDER = 1;
public const uint WIA_ERROR_PAPER_EMPTY = 0x80210003;
private static void SetProperty(this IProperties properties, int id, object value)
{
var property = properties.Cast<Property>().FirstOrDefault(p => p.PropertyID == id);
property.set_Value(ref value);
}
private static void Scan(string deviceId)
{
var deviceManager = new DeviceManager();
var deviceInfo = deviceManager.DeviceInfos.Cast<DeviceInfo>().Single(d => d.DeviceID == deviceId);
var device = deviceInfo.Connect();
device.Properties.SetProperty(WIA_DPS_DOCUMENT_HANDLING_SELECT, FEEDER);
var scannerItem = device.Items[1];
var page = 1;
do
{
try
{
// When calling Transfer the two paper are fed in the ADF but only one image is retuned
var image = (ImageFile)scannerItem.Transfer(FormatID.wiaFormatJPEG);
image.SaveFile($"image{page}.jpg");
page++;
}
catch (COMException ex)
{
if ((uint)ex.HResult != WIA_ERROR_PAPER_EMPTY)
break;
throw;
}
}
while (true);
}
When the scannerItem.Transfer method is called, the scanner feeder would scan 2 documents, but only one image item is returned. Then the loop continues, there is a pause, then the when scannerItem.Transfer is called again 2 more pages are scanned by the feeder but again only one image is returned. So if I put 10 pages to be scanned, only pages 1, 3, 5, 7 and 9 are saved. The other pages 2, 4, 6, 8 and 10 are fed into the auto feeder, but they are not saved.
When I tried using "Windows Fax and Scan" application on the same computer and same scanner, the feeder scans all 10 pages very fast then takes time to transfer them, but they are all saved. So I don't think it's a problem with the scanner itself or the driver.
My code runs in an ASP.NET application so I can't use methods that display dialogs or UI. However I tried a console application using CommonDialog.ShowAquireImage and CommonDialog.ShowTransfer, but I get the same result.
Also the problem happens on both 32 and 64 bit versions of the .NET Runtime and WIA 2.0.