WIA Scanning via Feeder
Asked Answered
A

1

8

WIA Scanning via Feeder

Here is my device properties:

Document Handling Select = 1 (2 is for flatbed, and 1 is for the feeder.)

Here is my item (page) properties:

Horizontal Resolution = 150
Vertical Resolution = 150
Horizontal Extent = 500 (I want to get it first to work, then I'll play with the extents.),
Vertical Extent = 500
Bits Per Pixel = 8
Current Intent = 4

I got everything running smoothly if I set the "Document Handling Select" to "2". When I set it to "1", and ran it, just before I say item.Transfer() (or item.Transfer(bmp/jpeg/pngGuid)) I get the exception "Value does not fall within the expected range."

This is so annoying, what value? I have googled the web, and I could only find a little information but it isn't much of help.

Acima answered 16/8, 2011 at 10:51 Comment(2)
I have played more with it, and I found that the only way that I could use the feeder was by opening the common dialog to ask the "item". The method in the dialog requests a device. It sets the properties in the device and in the item. I had a peek in the properties and it looks the same as in my questions. And it works. There must be something I am not seeing...Acima
I've got the same problem. :-( I'm assuming there must be another device property that has to be modified.Ordinary
O
11

I think you have to set the device property "Pages" (ID 3096) from 0 to 1 to prevent the exception. It took me some time to figure this out. Finally, I found this property by comparing the device properties before and after a call to CommonDialogClass.ShowSelectItems.

Here is some code:

    public enum DeviceDocumentHandling : int
    {
        Feeder = 1,
        FlatBed = 2
    }

    const int DEVICE_PROPERTY_DOCUMENT_HANDLING_CAPABILITIES_ID = 3086;
    const int DEVICE_PROPERTY_DOCUMENT_HANDLING_STATUS_ID = 3087;
    const int DEVICE_PROPERTY_DOCUMENT_HANDLING_SELECT_ID = 3088;
    const int DEVICE_PROPERTY_PAGES_ID = 3096;

    public static Property FindProperty(WIA.Properties properties, 
                                        int propertyId)
    {
        foreach (Property property in properties)
            if (property.PropertyID == propertyId)
                return property;
        return null;
    }

    public static void SetDeviceProperty(Device device, int propertyId, 
                                         object value)
    {
        Property property = FindProperty(device.Properties, propertyId);
        if (property != null)
            property.set_Value(value);
    }

    public static object GetDeviceProperty(Device device, int propertyId)
    {
        Property property = FindProperty(device.Properties, propertyId);
        return property != null ? property.get_Value() : null;
    }

    public static void SelectDeviceDocumentHandling(Device device, 
                                DeviceDocumentHandling handling)
    {
        int requested = (int)handling;
        int supported = (int)GetDeviceProperty(device, 
                 DEVICE_PROPERTY_DOCUMENT_HANDLING_CAPABILITIES_ID);
        if ((requested & supported) != 0)
        {
            if ((requested & (int)DeviceDocumentHandling.Feeder) != 0)
                SetDeviceProperty(device, DEVICE_PROPERTY_PAGES_ID, 1);
            SetDeviceProperty(device, 
                   DEVICE_PROPERTY_DOCUMENT_HANDLING_SELECT_ID, requested);
        }
    }
Ordinary answered 29/9, 2011 at 10:21 Comment(2)
I have tried the above code but when setting the below line I am getting an exception" value is not in range". object objValue = FEEDER | WIA_DPS_DOCUMENT_HANDLING_SELECT.DUPLEX; documentHandlingSelect.set_Value(ref objValue);Miquelon
You saved a life today, 13 years later :)Mow

© 2022 - 2024 — McMap. All rights reserved.