コード例 #1
0
        private void RunTwain()
        {
            logger.Debug("Run Twain");

            logger.Debug("IsTwain2Supported = {0}", _twain32.IsTwain2Supported);
            logger.Debug("IsTwain2Enable = {0}", _twain32.IsTwain2Enable);
            if (_twain32.OpenDataSource() == false)
            {
                string text = "Не удалось открыть источник.";
                logger.Error(text);
                throw new InvalidOperationException(text);
            }
            logger.Debug("DataSource is opened.");

                        #if DEBUG
            logger.Debug("XferMech.IsSupported=", _twain32.Capabilities.XferMech.IsSupported());
            logger.Debug("XferMech Support:");
            Twain32.Enumeration xferMech = _twain32.Capabilities.XferMech.Get();
            for (int i = 0; i < xferMech.Count; i++)
            {
                logger.Debug("[{0}] {1}", i, xferMech[i].ToString());
            }

            logger.Debug("All Capabilities");

            foreach (TwCap cap in Enum.GetValues(typeof(TwCap)))
            {
                if ((_twain32.IsCapSupported(cap) & TwQC.GetCurrent) != 0)
                {
                    logger.Debug("{0}(Current) = {1}", cap, _twain32.GetCurrentCap(cap));
                }
                else if ((_twain32.IsCapSupported(cap) & TwQC.Get) != 0)
                {
                    logger.Debug("{0} = {1}", cap, _twain32.GetCap(cap));
                }
                else
                {
                    logger.Debug("{0} = skiped", cap);
                }
            }
                        #endif

            _twain32.Capabilities.XferMech.Set(TwSX.Memory);
            //Feeder
            if (this._twain32.Capabilities.FeederEnabled.IsSupported(TwQC.Set))
            {
                this._twain32.Capabilities.FeederEnabled.Set(true);
                logger.Debug("TwCap.FeederEnabled = Enabled");

                if (this._twain32.Capabilities.AutoFeed.IsSupported(TwQC.Set))
                {
                    this._twain32.Capabilities.AutoFeed.Set(true);
                    logger.Debug("TwCap.AutoFeed = Enabled");
                }

                if (this._twain32.Capabilities.XferCount.IsSupported(TwQC.Set))
                {
                    this._twain32.Capabilities.XferCount.Set(-1);
                    logger.Debug("TwCap.XferCount = Enabled");
                }
            }

                        #if DEBUG
            //Отслеживаем все события
            _twain32.AcquireCompleted += delegate {
                logger.Debug("AcquireCompleted fired");
            };

            _twain32.AcquireError += (sender, e) => logger.Debug("AcquireError fired");

            _twain32.DeviceEvent += delegate {
                logger.Debug("DeviceEvent fired");
            };

            _twain32.EndXfer += delegate {
                logger.Debug("EndXfer fired");
            };

            _twain32.FileXferEvent += delegate {
                logger.Debug("FileXferEvent fired");
            };

            _twain32.MemXferEvent += delegate {
                logger.Debug("MemXferEvent fired");
            };

            _twain32.SetupFileXferEvent += delegate {
                logger.Debug("SetupFileXferEvent fired");
            };

            _twain32.SetupMemXferEvent += delegate {
                logger.Debug("SetupMemXferEvent fired");
            };

            _twain32.TwainStateChanged += (object sender, Twain32.TwainStateEventArgs e) => {
                logger.Debug("TwainStateChanged fired");
                logger.Debug("TwainState = {0}", e.TwainState);
            };

            _twain32.XferDone += delegate {
                logger.Debug("XferDone fired");
            };
                        #endif

            logger.Debug("Run Acquire");
            _twain32.Acquire();
            logger.Debug("After Acquire");
        }