I'm writing a network scanner application, using WIA. My problem now is that the transfer method only scan one image. I tried to force the parameter WIA_DOCUMENT_HANDLING_SELECT = "3088"; but the result is the same it scan just one image per time. How can I manage the document feeder and the duplex parameter?
I tried this code
const string WIA_SCAN_COLOR_MODE = "6146";
const string WIA_HORIZONTAL_SCAN_RESOLUTION_DPI = "6147";
const string WIA_VERTICAL_SCAN_RESOLUTION_DPI = "6148";
const string WIA_HORIZONTAL_SCAN_START_PIXEL = "6149";
const string WIA_VERTICAL_SCAN_START_PIXEL = "6150";
const string WIA_HORIZONTAL_SCAN_SIZE_PIXELS = "6151";
const string WIA_VERTICAL_SCAN_SIZE_PIXELS = "6152";
const string WIA_SCAN_BRIGHTNESS_PERCENTS = "6154";
const string WIA_SCAN_CONTRAST_PERCENTS = "6155";
const string WIA_MANUFACTURER = "3";
const string WIA_DESCRIPTION = "4";
const string WIA_DOCUMENT_HANDLING_SELECT = "3088";
//const string WIA_LAMP_WARM_UP_TIME = "6161";
//const string WIA_IPS_DOCUMENT_HANDLING_SELECT =
//const string WIA_IPS_LAMP =
const int widthA4at300dpi = 2480;
const int heightA4at300dpi = 3508;
const int widthA4at600dpi = 4960;
const int heightA4at600dpi = 7016;
public static Image scan(DeviceInfo dev, Protocol.ScannerOptions options)
{
ImageFile imageFile = null;
try
{
// Connect to the first available scanner
Device device = dev.Connect();
// Select the scanner
Item scannerItem = device.Items[1];
if(options.adf)
SetWIAProperty(device.Properties, WIA_DOCUMENT_HANDLING_SELECT, 1); //1 is feeder 2 is flatbed
AdjustScannerSettings(scannerItem, options.dpi, 0, 0, 1250, 1700, options.brightness, options.contrast, options.color_mode);
imageFile = (ImageFile)scannerItem.Transfer(FormatID.wiaFormatBMP);
}
catch (COMException e)
{
// Convert the error code to UINT
uint errorCode = (uint)e.ErrorCode;
// See the error codes
if (errorCode == 0x80210006)
{
Console.WriteLine("The scanner is busy or isn't ready");
NetScanImageServer.txt_logger.write_log("The scanner is busy or isn't ready");
throw new Exception("The scanner is busy or isn't ready");
}
else if (errorCode == 0x80210064)
{
Console.WriteLine("The scanning process has been cancelled.");
NetScanImageServer.txt_logger.write_log("The scanning process has been cancelled.");
throw new Exception("The scanning process has been cancelled.");
}
else if (errorCode == 0x8021000C)
{
Console.WriteLine("There is an incorrect setting on the WIA device.");
NetScanImageServer.txt_logger.write_log("There is an incorrect setting on the WIA device.");
throw new Exception("There is an incorrect setting on the WIA device.");
}
else if (errorCode == 0x80210005)
{
Console.WriteLine("The device is offline. Make sure the device is powered on and connected to the PC.");
NetScanImageServer.txt_logger.write_log("The device is offline. Make sure the device is powered on and connected to the PC.");
throw new Exception("The device is offline. Make sure the device is powered on and connected to the PC.");
}
else if (errorCode == 0x80210001)
{
Console.WriteLine("An unknown error has occurred with the WIA device.");
NetScanImageServer.txt_logger.write_log("An unknown error has occurred with the WIA device.");
throw new Exception("An unknown error has occurred with the WIA device.");
}
}
catch (Exception ex)
{
Console.WriteLine("Errore SCANNER non pronto\n" + ex.ToString());
NetScanImageServer.txt_logger.write_log("Errore SCANNER non pronto\n" + ex.ToString());
throw new Exception("Errore SCANNER non pronto\n" + ex.ToString());
}
if(imageFile!=null)
return ToBitmap(imageFile);
else return null;
}