0
votes

i am new to WIA. And i have been asked to make scaning service scan faster and duplex. My current service scan one page, then put it in pdf and so on untill there is less then 20 pages(this number just a crutch used before me, will be glad if someone explane how to get "if there is any paper in there" variable). I started to dig and found docs on MSDN describing properties and after found this post describing duplex sanning, but with mysterious 5 in set. After I found this and figured out what i need WIA_DPS_DOCUMENT_HANDLING_SELECT to set to 0x205(FEEDER + DUPLEX + AUTO_ADVANCE). So I tried to setup them like this:

    private static void SetProperty(Property property, int value)
    {
        IProperty x = (IProperty)property;
        Object val = value;
        x.set_Value(ref val);
    }

...some code...

    foreach (Property prop in device.Properties)
    {
        //LOGGER.Warn(prop.Name);
        //LOGGER.Warn(prop.PropertyID);
        switch ((Int32)prop.PropertyID)
        {
           // Document Handling Select
           case 3088:
              SetProperty(prop, 517);
              break;
           // Pages
           case 3096:
              SetProperty(prop, 1);
              break;
        }
    }

And it did't worked for me... It just stuck on setting... Can Somebody explain how to setup AUTO_ADVANCE and DUPLEX props? Or maybe "make scanning faster and duplex" need something more then just AUTO_ADVANCE and DUPLEX and my perception about them is wrong? Or I should considering "ISIS / TWAIN (Windows XP / Vista / 7 / 8 / 8.1 / 10)" string in my scan description and use other libraries?
(Window 10, Canon DR-M160||, DR-M160 & DR-M160II Driver for Windows)

and also here is the current fetch function:

    public List<ImageFile> FetchImageList()
    {
        List<ImageFile> imageList = new List<ImageFile>();
        //bool hasMorePages = true;
        int testcount = 0;
        while (testcount >= 0)
        {
            testcount--;
            WIA.Device device = FindDevice(_deviceId);
            if (device == null)
            {
                LOGGER.Warn("Scanner device not found");
                return null;
            }
            // get item
            WIA.Item scanItem = device.Items[1] as WIA.Item;
            LOGGER.Debug($"ScanItem: {scanItem.ItemID}");

            try
            {
                foreach (Property prop in device.Properties)
                {
                    //LOGGER.Warn(prop.Name);
                    //LOGGER.Warn(prop.PropertyID);
                    switch ((Int32)prop.PropertyID)
                    {
                        // Document Handling Select
                        case 3088:
                            LOGGER.Warn("here");
                            SetProperty(prop, 517);
                            LOGGER.Warn("here");
                            break;
                        // Pages
                        case 3096:
                            SetProperty(prop, 1);
                            break;
                    }
                }
                // scan image
                WIA.ICommonDialog wiaCommonDialog = new WIA.CommonDialog();
                WIA.ImageFile image = (WIA.ImageFile)scanItem.Transfer(WIA.FormatID.wiaFormatPNG);
                imageList.Add(image);
                LOGGER.Warn("Front");

                //get back side
                image = (WIA.ImageFile)scanItem.Transfer(WIA.FormatID.wiaFormatPNG);
                imageList.Add(image);
                LOGGER.Warn("Back");
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
        return imageList;
    }
1
"Value does not fall within expected range" ... Sorry for vagueness, to c# I am also new (Viles

1 Answers

1
votes

Well... I tried to make duplex scan without AUTO_ADVANCE and got HRESULT: 0x8000FFFF (E_UNEXPECTED) on Transfer call. According to this post(even though that was on Windows 7) I guess there is no way to solve this for me by using WIA, still hope there will other suggestions...

Solved problem I used saraff.twain and it worked for me: - git page :https://github.com/saraff-9EB1047A4BEB4cef8506B29BA325BD5A/Saraff.Twain.NET good library with grate wiki page.(Also have similar library for .net 4.6.1)