Click here to Skip to main content
16,020,811 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to scan duplex interfacing with Neatdesk scanner using VB.Net. I currently have the capability to scan each page front only, and have not been able to set the unit to duplex. When I try to set the duplex parameter, I either get a "out of bounds" error or "access denied" error. Here is my snippet of the code that I found and edited from other sources.

Dim DeviceManager1 = CreateObject("WIA.DeviceManager")   'wia device manager
        For i = 1 To DeviceManager1.DeviceInfos.Count 'loop through all devices

            If DeviceManager1.DeviceInfos(i).Type = 1 Then  'Select only scanners, not webcams etc...
                Dim Scanner As WIA.Device = DeviceManager1.DeviceInfos(i).connect
                Dim Img As WIA.ImageFile
                Try
                    'MsgBox(Scanner.Properties("3088").Value.ToString)
                    With Scanner.Items(1)
                        .Properties("6146").Value = 4 '4 is Black-white,gray is 2, color 1 (Color Intent)
                        .Properties("3088").Value = &H4 'To print Duplex
                    End With                                   
                Finally
                    Img = Scanner.Items(1).Transfer("{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}") 'Grab the image in jpeg format
                    Img.SaveFile(location & page & ".jpg")
                 End Try
            End If
        Next


If I omit the
.Properties("3088").Value = &H4
portion, I am able to scan all the documents I need front face up only.

Thank you for the help.
Posted

I know this is an old thread, but if someone needs another solution, this might be it :

You cannot only set the WIA_DPS_DOCUMENT_HANDLING_SELECT (3088) to the value 4.
You need to select the FEEDER or FLATBED value as well.

So let's say i want to select the FEEDER (1) and the DUPLEX (4) mode, you would have to assign the value 5:
1 + 4 = 5

http://msdn.microsoft.com/en-us/library/windows/hardware/ff552792%28v=vs.85%29.aspx
 
Share this answer
 
v3
Comments
Member 13889990 12-Aug-18 23:07pm    
tank you!!!
I think your problem is that the color intent is a item property, but the document handling select is a device property. I don't have my WIA code in front of me but will probably be something along these lines

Scanner.Properties("3088").Value = &H4
instead of ...
Scanner.Items(1).Properties...


Also, the document handling select is a flag property, here are the const values from wiadef.h

VB
'WIA_DPS_DOCUMENT_HANDLING_SELECT flags

const FEEDER = &H1
const FLATBED = &H2
const DUPLEX = &H4
const FRONT_FIRST = &H8
const BACK_FIRST = &H10
const FRONT_ONLY = &H20
const BACK_ONLY = &H40
const NEXT_PAGE = &H80
const PREFEED = &H100
const AUTO_ADVANCE = &H200
 
Share this answer
 
Comments
ayaraneri3 1-Aug-13 9:18am    
Thank you for your response, however this did not solve the problem. I took the code out of the items block and changed the property of the scanner itself with the following variations:

Scanner.Properties("&HC10").let_Value("4")
Scanner.Properties("&HC10").Value = "4"
Scanner.Properties("3088").Value = &H4
Scanner.Properties("3088").Value = "&H4"

All giving me the following error "Value does not fall within the expected range."
I looked at my code and this is how I enable duplexing for WIA. I know this is in C# but should be able to translate to VB easily. If you need it translated I can take the time to translate it for you.

C#
//this is from my GetPropertyName method
case PropertyId.DocumentHandlingSelect:
                    return "Document Handling Select";




C#
internal static void SetDuplexMode(WIA.Device dev, bool useduplex)
{
    try
    {
        //get device property for document handling select
        WIA.Property prop = dev.Properties[GetPropertyName(PropertyId.DocumentHandlingSelect)];

        if (prop != null)
        {
            //get current value
            int mask = prop.get_Value();

            if (useduplex) //enable duplexing
            {
                //mask "or equals" duplex (bit mask)
                mask |= (int)document.handling.Select.DUPLEX;
            }
            else //disable duplexing
            {
                //mask "and equals" duplex (bit mask)
                mask &= ~(int)document.handling.Select.DUPLEX;
            }
            //set value
            prop.set_Value(mask);
        }

    }
    catch (System.Runtime.InteropServices.COMException cex)
    {
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900