Scan Issue with Kodak(FLATBED with ADF)

Issue #84 new
Prashant created an issue

Hi , I am facing strange issue when I try to use nTwain library with KODAK(flatbed+ ADF) scanner. it raises the TRAY but never pull sheets. same piece of code is working perfectly fine with Canon which is just ADF.

Thanks in advance, any sort of help/guidance will be appreciated. #

** I am leaving Issue parameters(Kind,Priority) to default.

Comments (6)

  1. Eugene Wang repo owner

    Maybe try setting CapFeederEnabled to true.

    ds.Capabilities.CapFeederEnabled.SetValue(BoolType.True)
    
  2. Prashant reporter
    if (_Scanner.Capabilities.CapUIControllable.CanGet && _Scanner.Capabilities.CapUIControllable.GetCurrent() == BoolType.True)
                        {
                            _Scanner.Capabilities.CapIndicators.SetValue(BoolType.False);//page#468
                        }
    
                        // Feeder related capabilities
                        try
                        {
                            var resetResult = _Scanner.Capabilities.ResetAll();
                            logger.Info("Capability reset result {0}", resetResult.ConvertToString());
                        }
                        catch (Exception e)
                        {
                            logger.Error(e, "exception while reseting with reset capabilities");
                        }
    
                        if (_Scanner.Capabilities.CapFeederEnabled.CanSet)
                        {
                            var enableResult = _Scanner.Capabilities.CapFeederEnabled.SetValue(BoolType.True);
                            logger.Info("Feeder enabled , result is {0}", enableResult.ConvertToString());
                            if (enableResult.Equals(ReturnCode.Success))
                            {
                                // check if paper is detectable
                                if (_Scanner.Capabilities.CapPaperDetectable.GetCurrent().Equals(BoolType.True))
                                {
                                    logger.Info("Source has capability to detect paper with feder");
                                }
                                else
                                {
                                    logger.Info("Source doesn't have capability to detect paper with feeder");
                                }
                                // irrespective of above condition true or false we will continue further, check if feder has paper
                                if (_Scanner.Capabilities.CapFeederLoaded.CanGet && _Scanner.Capabilities.CapFeederLoaded.GetCurrent().Equals(BoolType.True))
                                {
                                    logger.Info("Feeder is loaded");
                                    try
                                    {
                                        cap_Set_Result = _Scanner.Capabilities.CapAutoFeed.SetValue(BoolType.True);
                                        logger.Info("Auto feed set result {0}", cap_Set_Result.ConvertToString());
    
                                    }
                                    catch (Exception e) { logger.Error(e, "Error while setting Auto feed"); }
                                    // set Auto Scan
                                    try
                                    {
                                        cap_Set_Result = ReturnCode.Failure;
                                        cap_Set_Result = _Scanner.Capabilities.CapAutoScan.SetValue(BoolType.True);
                                        logger.Info("Auto Scan set result {0}", cap_Set_Result.ConvertToString());
                                        if (cap_Set_Result.Equals(ReturnCode.Success))
                                        {
                                            // set xfer count
                                            cap_Set_Result = ReturnCode.Failure;
                                            if (_Scanner.Capabilities.CapXferCount.CanSet)
                                            {
                                                try
                                                {
                                                    var current_val = _Scanner.Capabilities.CapXferCount.GetCurrent();
                                                    logger.Info("Current value for XferCount is {0}", current_val);
                                                    if (current_val != -1)
                                                    {
                                                        cap_Set_Result = _Scanner.Capabilities.CapXferCount.SetValue(-1);
                                                        logger.Info("XFer result set to -1 , set result {0}", cap_Set_Result.ConvertToString());
                                                    }
    
                                                }
                                                catch (Exception e) { logger.Error(e, "Error while setting Auto Scan"); }
                                            }
                                            else { logger.Info("XFer cannot be set"); }
                                        }
                                    }
                                    catch (Exception e) { logger.Error(e, "Error while setting Auto Scan"); }
    
                                    // check about feeder packet
                                    try
                                    {
                                        if (!_Scanner.Capabilities.CapAutomaticSenseMedium.GetCurrent().Equals(BoolType.True))
                                        {
                                            cap_Set_Result = _Scanner.Capabilities.CapAutomaticSenseMedium.SetValue(BoolType.True);
                                            logger.Info("Automatic medium is set to True, set result {0}", cap_Set_Result.ConvertToString());
                                        }
    
                                    }
                                    catch (Exception e) { logger.Error(e, "Error while setting Auto Scan"); }
    
                                    logger.Info("Before Enabling DataSource");
                                    rc = _Scanner.Enable(SourceEnableMode.NoUI, true, handle);
                                    logger.Info("DataSource Enable method called , return Code +=" + rc.ConvertToString());
    

    I tried it and tried others too. Another point is that twainSession_DataTransferred event never execute in case of KODAK. Please let me know if I am doing anything wrong.

  3. Eugene Wang repo owner

    Looks like it should work, so can't say why. For testing purposes you might try one or more of these

    • Don't use modal and pass IntPtr.Zero for handle in Enable().
    • if it's an app with UI try clicking around in empty app areas after Enable() call to see if scanner starts moving
    • if winform/wpf app try using WindowsFormsMessageLoopHook/WpfMessageLoopHook in session.Open() call instead of the implicit one that uses background thread.

    If none of these work then it's not a threading problem and probably some scanner setting not combined correctly. Maybe try Enable() with UI and see if it works.

  4. Prashant reporter

    Thanks, I will try steps illustrated by you. Other strange thing , do we have any CAP by name "CAP_PAPERSOURCE" ? Downloaded Kodak free Scan SDK and went inside code I see this cap used when setting data source.

    string str = "CAP_PAPERSOURCE,TWON_ONEVALUE,TWTY_UINT16," + m_ipapersource.ToString();
                    this.retVal = twainscan.SendDat("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref str, null, null, new IntPtr());
    

    but when I search this CAP with Twain specification 2.4 I do not find any. Searching this CAP on google gives this link ftp://ftp.sbmu.ac.ir/Drivers/scaner/kodak%20i1420/Integrator/KODAK/TWAIN_ProgrammaticControl.htm link says that it is KODAK Custom. If you can suggest anything after this, please do. Thanks

  5. Eugene Wang repo owner

    You could make your own cap wrapper like I did. See this example modified from the Capabilities.cs file. Otherwise you will have to do the hard work of calling the capability triplet yourself.

        class KodakCaps
        {
            private IDataSource _source;
    
            public KodakCaps(IDataSource source)
            {
                _source = source;
            }
    
    
            private CapWrapper<KodakPaperSource> _paperSrc;
    
            public ICapWrapper<KodakPaperSource> CapPaperSource
            {
                get
                {
                    return _paperSrc ?? (_paperSrc = new CapWrapper<KodakPaperSource>(_source, (CapabilityId)0x802C, ValueExtensions.ConvertToEnum<KodakPaperSource>, value => new TWOneValue
                    {
                        Item = (uint)value,
                        ItemType = ItemType.UInt16
                    }));
                }
            }
        }
    
        enum KodakPaperSource : UInt16
        {
            // from TWPU_* values
            Auto = 0,
            ADF,
            // and more
        }
    
  6. Log in to comment