WIA + Windows 7 + Network Scanner (WSD Device)

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello everyone. Is there some documentation or sample code how to get all scans from network scanner with feeder (and duplex)?
Here is my code:
<pre class="prettyprint WIA.CommonDialog WiaCommonDialog = new WIA.CommonDialog();

try
{
do
{
//Connect to Device
Device wia = Connect();
WIA.Item item = wia.Items[1] as WIA.Item;

//Setup ADF
if ((useAdf) || (duplex))
SetupADF(wia, duplex);

//Setup Page Size
SetupPageSize(wia, rotatePage, pageSize, DPI, item);

WIA.ImageFile imgFile = null;
WIA.ImageFile imgFile_duplex = null; //if duplex is setup, this will be back page

imgFile = (ImageFile)WiaCommonDialog.ShowTransfer(item, wiaFormatJPEG, false);

//If duplex page, get back page now.
if (duplex)
{
imgFile_duplex = (ImageFile)WiaCommonDialog.ShowTransfer(item, wiaFormatJPEG, false);
}

string varImageFileName = filepath + "\Scanned-" + pages.ToString() + ".jpg";
Delete_File(varImageFileName); //if file already exists. delete it.
imgFile.SaveFile(varImageFileName);

string varImageFileName_duplex;

if (duplex)
{
varImageFileName_duplex = filepath + "\Scanned-" + pages++.ToString() + ".jpg";
Delete_File(varImageFileName_duplex); //if file already exists. delete it.
imgFile_duplex.SaveFile(varImageFileName);
}

//Check with scanner to see if there are more pages.
if (useAdf || duplex)
{
hasMorePages = HasMorePages(wia);
pages++;
}

}
while (hasMorePages);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}[/code]
SetupADF Code :
<pre class="prettyprint private void SetupADF(Device wia, bool duplex)
{
foreach (WIA.Property deviceProperty in wia.Properties)
{
if (deviceProperty.Name == "Document Handling Select") //or PropertyID == 3088
{
int value = duplex ? 0x004 : 0x001;
deviceProperty.set_Value(value);
}

}

}[/code]
<br/>
HasMorePages Code:
<pre class="prettyprint private bool HasMorePages(Device wia)
{

//determine if there are any more pages waiting
Property documentHandlingSelect = null;
Property documentHandlingStatus = null;

foreach (Property prop in wia.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;
}

if ((Convert.ToUInt32(documentHandlingSelect.get_Value()) & 0x00000001) != 0)
{
return ((Convert.ToUInt32(documentHandlingStatus.get_Value()) & 0x00000001) != 0);
}

return false;

}[/code]
<br/>
All what i get is one page and exception. Scanner continues to scan. HasMorePages works fine, but i dont understand how to get other images?
Using windows device panel - all works: i can select simple scan, feeder, feeder with duplex and windows get all the pages.

View the full article
 
Back
Top