示例#1
0
        public bool Disable()
        {
            if (SourceState != null && SourceState >= TwainState.SourceEnabled)
            {
                if (SourceId.Id != 0)
                {
                    var userInterface = new UserInterface();

                    TwainResult result = Twain32Native.DsUserInterface(
                        _applicationId,
                        SourceId,
                        DataGroup.Control,
                        DataArgumentType.UserInterface,
                        Message.DisableDS,
                        userInterface);


                    if (result != TwainResult.Failure)
                    {
                        _log.Debug(string.Format("DisableDS, result: {0}", result));
                        SourceState = TwainState.SourceOpen;
                        return(true);
                    }
                    var condition = DataSourceManager.GetConditionCode(_applicationId, SourceId);
                    _log.Debug(string.Format("DisableDS, result: {0}, conditionCode: {1}", result, condition));
                    return(false);
                }
                return(false);
            }

            return(false);
        }
示例#2
0
        public DataSourceManager(Identity applicationId, IWindowsMessageHook messageHook)
        {
            // Make a copy of the identity in case it gets modified
            ApplicationId = applicationId.Clone();

            ScanningComplete += delegate { };
            TransferImage    += delegate { };

            _messageHook = messageHook;
            _messageHook.FilterMessageCallback = FilterMessage;
            IntPtr windowHandle = _messageHook.WindowHandle;

            _eventMessage.EventPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WindowsMessage)));

            // Initialise the data source manager
            TwainResult result = Twain32Native.DsmParent(
                ApplicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Parent,
                Message.OpenDSM,
                ref windowHandle);

            if (result == TwainResult.Success)
            {
                //according to the 2.0 spec (2-10) if (applicationId.SupportedGroups
                // | DataGroup.Dsm2) > 0 then we should call DM_Entry(id, 0, DG_Control, DAT_Entrypoint, MSG_Get, wh)
                //right here
                DataSource = DataSource.GetDefault(ApplicationId, _messageHook);
            }
            else
            {
                throw new TwainException("Error initialising DSM: " + result, result);
            }
        }
示例#3
0
        public void Close()
        {
            if (SourceId.Id != 0)
            {
                UserInterface userInterface = new UserInterface();

                TwainResult result = Twain32Native.DsUserInterface(
                    _applicationId,
                    SourceId,
                    DataGroup.Control,
                    DataArgumentType.UserInterface,
                    Message.DisableDS,
                    userInterface);

                if (result != TwainResult.Failure)
                {
                    result = Twain32Native.DsmIdentity(
                        _applicationId,
                        IntPtr.Zero,
                        DataGroup.Control,
                        DataArgumentType.Identity,
                        Message.CloseDS,
                        SourceId);
                }
            }
        }
示例#4
0
        protected void SetValue <T>(T value)
        {
            var rawValue        = Convert.ToInt32(value);
            var oneValue        = new CapabilityOneValue(_twainType, rawValue);
            var twainCapability = TwainCapability.From(_capability, oneValue);

            var result = Twain32Native.DsCapability(
                _applicationId,
                _sourceId,
                DataGroup.Control,
                DataArgumentType.Capability,
                Message.Set,
                twainCapability);

            if (result == TwainResult.Success)
            {
                return;
            }
            if (result == TwainResult.Failure)
            {
                throw new TwainException("Failed to set capability.", result, GetStatus());
            }
            if (result != TwainResult.CheckStatus)
            {
                throw new TwainException("Failed to set capability.", result);
            }
        }
示例#5
0
        protected virtual void Dispose(bool disposing)
        {
            Marshal.FreeHGlobal(_eventMessage.EventPtr);

            if (disposing)
            {
                DataSource.Dispose();

                IntPtr windowHandle = _messageHook.WindowHandle;

                if (ApplicationId.Id != 0)
                {
                    // Close down the data source manager
                    Twain32Native.DsmParent(
                        ApplicationId,
                        IntPtr.Zero,
                        DataGroup.Control,
                        DataArgumentType.Parent,
                        Message.CloseDSM,
                        ref windowHandle);
                }

                ApplicationId.Id = 0;
            }
        }
示例#6
0
        public static DataSource GetDefault(Identity applicationId, IWindowsMessageHook messageHook)
        {
            log.Debug("create new identity");
            var defaultSourceId = new Identity();

            // Attempt to get information about the system default source
            log.Debug("call DsmIdentity");
            var result = Twain32Native.DsmIdentity(
                applicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Identity,
                Message.GetDefault,
                defaultSourceId);

            if (result != TwainResult.Success)
            {
                log.Debug("result != success");
                var status = DataSourceManager.GetConditionCode(applicationId, null);
                throw new TwainException("Error getting information about the default source: " + result, result, status);
            }

            log.Debug("return new data source");
            return(new DataSource(applicationId, defaultSourceId, messageHook));
        }
示例#7
0
        public void Close()
        {
            if (SourceId.Id != 0)
            {
                try
                {
                    UserInterface userInterface = new UserInterface();

                    TwainResult result = Twain32Native.DsUserInterface(
                        _applicationId,
                        SourceId,
                        DataGroup.Control,
                        DataArgumentType.UserInterface,
                        Message.DisableDS,
                        userInterface);

                    if (result != TwainResult.Failure)
                    {
                        result = Twain32Native.DsmIdentity(
                            _applicationId,
                            IntPtr.Zero,
                            DataGroup.Control,
                            DataArgumentType.Identity,
                            Message.CloseDS,
                            SourceId);
                    }
                }
                catch
                {
                    // ignore this is bypass an error that if trigerd needs the whole twain classto be reinitialised
                }
            }
        }
示例#8
0
        /// <summary>
        /// 打開DS,進入State 4以溝通Capabilities
        /// </summary>
        /// <exception cref="DeviceOpenExcetion">當DS被其他人占用的時候可能會擲回,或twain DLL沒有錯誤,但是回傳值失敗的話就會擲回</exception>
        public void OpenSource()
        {
            TwainResult result = TwainResult.NotDSEvent;

            try
            {
                result = Twain32Native.DsmIdentity(
                    _applicationId,
                    IntPtr.Zero,
                    DataGroup.Control,
                    DataArgumentType.Identity,
                    Message.OpenDS,
                    SourceId);
            }
            catch (Exception ex)
            {
                throw new DeviceOpenExcetion(ex.Message);
            }

            if (result != TwainResult.Success)
            {
                throw new DeviceOpenExcetion("Error opening data source", result);
            }
            Logger.WriteLog(LOG_LEVEL.LL_NORMAL_LOG, string.Format("DataSource \"{0}\" successfully opened.", this.SourceId.ProductName));
        }
示例#9
0
        /// <summary>
        /// 接下來就交給source控制這個流程。MSG_XFERREADY, MSG_CLOSEDSREQ, or MSG_CLOSEDSOK messages會傳回來,其中MSG_XFERREADY代表source準備好從state 5→6。
        /// </summary>
        /// <param name="settings"></param>
        /// <returns></returns>
        public bool Enable(ScanSettings settings)
        {
            UserInterface ui = new UserInterface();

            ui.ShowUI     = (settings.ShowTwainUI ? TwainBool.True : TwainBool.False);
            ui.ModalUI    = TwainBool.False;
            ui.ParentHand = _messageHook.WindowHandle;

            var result = Twain32Native.DsUserInterface(
                _applicationId,
                SourceId,
                DataGroup.Control,
                DataArgumentType.UserInterface,
                Message.EnableDS,
                ui);

            if (result != TwainResult.Success)
            {
                Console.WriteLine("Enable() error! return=" + result);
                Logger.WriteLog(LOG_LEVEL.LL_SUB_FUNC, "Enable() error! return=" + result);
                Dispose();
                return(false);
            }
            return(true);
        }
示例#10
0
        public List <object> GetValue()
        {
            var twainCapability = TwainCapability.From(_capability);

            var result = Twain32Native.DsCapability(
                _applicationId,
                _sourceId,
                DataGroup.Control,
                DataArgumentType.Capability,
                Message.Get,
                twainCapability);

            if (result != TwainResult.Success)
            {
                var conditionCode = GetStatus();

                log.Debug(string.Format("Failed to get capability:{0} reason: {1}",
                                        _capability, conditionCode));

                return(null);

                /*return new BasicCapabilityResult()
                 * {
                 *      ConditionCode = conditionCode,
                 *      ErrorCode = result
                 * };*/
            }


            var ojbts = new List <object>();

            CapabilityReader.ReadValue(twainCapability).PopulateFromCapValues(ojbts);

            return(ojbts);
        }
示例#11
0
        protected virtual void Dispose(bool disposing)
        {
            Marshal.FreeHGlobal(_eventMessage.EventPtr);

            if (disposing)
            {
                DataSource.Dispose();

                IntPtr windowHandle = _messageHook.WindowHandle;

                if (ApplicationId.Id != 0)
                {
                    // Close down the data source manager
                    var result = Twain32Native.DsmParent(
                        ApplicationId,
                        IntPtr.Zero,
                        DataGroup.Control,
                        DataArgumentType.Parent,
                        Message.CloseDSM,
                        ref windowHandle);

                    _log.Debug(string.Format("CloseDSM, result: {0}", result));

                    if (result != TwainResult.Failure)
                    {
                        _twainState = TwainState.SourceManagerLoaded;
                    }
                }

                ApplicationId.Id = 0;
            }
        }
示例#12
0
        public List <DataSource> GetAllSources()
        {
            var sources = new List <DataSource>();
            var id      = new Identity();

            // Get the first source
            var result = Twain32Native.DsmIdentity(
                ApplicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Identity,
                Message.GetFirst,
                id);

            _log.Debug(string.Format("GetFirst (GetAllSources), result: {0}", result));
            if (result == TwainResult.EndOfList)
            {
                return(sources);
            }
            if (result != TwainResult.Success)
            {
                throw new TwainException("Error getting first source.", result);
            }

            sources.Add(new DataSource(ApplicationId, id, _messageHook, _log));


            while (true)
            {
                // Get the next source
                result = Twain32Native.DsmIdentity(
                    ApplicationId,
                    IntPtr.Zero,
                    DataGroup.Control,
                    DataArgumentType.Identity,
                    Message.GetNext,
                    id);

                _log.Debug(string.Format("GetNext (GetAllSources), result: {0}", result));
                if (result == TwainResult.EndOfList)
                {
                    break;
                }
                if (result != TwainResult.Success)
                {
                    throw new TwainException("Error enumerating sources.", result);
                }

                sources.Add(new DataSource(ApplicationId, id, _messageHook, _log));
            }

            var sb = new StringBuilder("GetAllSources result: ");

            foreach (var dataSource in sources)
            {
                sb.Append(string.Format("sourceId: {0}; ", dataSource.SourceId.ProductName));
            }
            _log.Debug(sb);
            return(sources);
        }
示例#13
0
        public BasicCapabilityResult GetBasicValue()
        {
            var oneValue        = new CapabilityOneValue(_twainType, 0);
            var twainCapability = TwainCapability.From(_capability, oneValue);

            var result = Twain32Native.DsCapability(
                _applicationId,
                _sourceId,
                DataGroup.Control,
                DataArgumentType.Capability,
                Message.Get,
                twainCapability);

            if (result != TwainResult.Success)
            {
                var conditionCode = GetStatus();

                log.Debug(string.Format("Failed to get capability:{0} reason: {1}",
                                        _capability, conditionCode));

                return(new BasicCapabilityResult()
                {
                    ConditionCode = conditionCode,
                    ErrorCode = result
                });
            }

            twainCapability.ReadBackValue();

            return(new BasicCapabilityResult()
            {
                RawBasicValue = oneValue.Value
            });
        }
示例#14
0
        public bool Enable(ScanSettings settings)
        {
            var ui = new UserInterface();

            ui.ShowUI     = (short)(settings.ShowTwainUI ? 1 : 0);
            ui.ModalUI    = 0;
            ui.ParentHand = _messageHook.WindowHandle;

            var result = Twain32Native.DsUserInterface(
                _applicationId,
                SourceId,
                DataGroup.Control,
                DataArgumentType.UserInterface,
                Message.EnableDS,
                ui);

            _log.Debug(string.Format("EnableDS, result: {0}", result));
            if (result != TwainResult.Success)
            {
                Dispose();
                return(false);
            }

            SourceState = TwainState.SourceEnabled;
            return(true);
        }
示例#15
0
        public static DataSource GetSource(string sourceProductName, Identity applicationId, IWindowsMessageHook messageHook)
        {
            Identity id = new Identity();

            // Get the first source
            var result = Twain32Native.DsmIdentity(
                applicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Identity,
                Message.GetFirst,
                id);

            if (result == TwainResult.EndOfList)
            {
                return(null);
            }
            else if (result != TwainResult.Success)
            {
                throw new TwainException("Error getting first source.", result);
            }
            else if (id.ProductName == sourceProductName)
            {
                return(new DataSource(applicationId, id, messageHook));
            }

            while (true)
            {
                id = new Identity();
                // Get the next source
                result = Twain32Native.DsmIdentity(
                    applicationId,
                    IntPtr.Zero,
                    DataGroup.Control,
                    DataArgumentType.Identity,
                    Message.GetNext,
                    id);

                if (result == TwainResult.EndOfList)
                {
                    break;
                }
                else if (result != TwainResult.Success)
                {
                    throw new TwainException("Error enumerating sources.", result);
                }

                else if (id.ProductName == sourceProductName)
                {
                    return(new DataSource(applicationId, id, messageHook));
                }
            }

            return(null);
        }
示例#16
0
 public static DataSource SetScanSource(Identity applicationId, Identity defaultSourceId, IWindowsMessageHook messageHook)
 {
     // Show the TWAIN interface to allow the user to select a source
     Twain32Native.DsmIdentity(
         applicationId,
         IntPtr.Zero,
         DataGroup.Control,
         DataArgumentType.Identity,
         Message.GetDefault,
         defaultSourceId);
     return(new DataSource(applicationId, defaultSourceId, messageHook));
 }
示例#17
0
        public static List <string> GetAllSourceNames(Identity applicationId)
        {
            var      sources = new List <string>();
            Identity id      = new Identity();

            // Get the first source
            var result = Twain32Native.DsmIdentity(
                applicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Identity,
                Message.GetFirst,
                id);

            if (result == TwainResult.EndOfList)
            {
                return(sources);
            }
            else if (result != TwainResult.Success)
            {
                throw new TwainException("Error getting first source.", result);
            }
            else
            {
                sources.Add(id.ProductName);
            }

            while (true)
            {
                id = new Identity();
                // Get the next source
                result = Twain32Native.DsmIdentity(
                    applicationId,
                    IntPtr.Zero,
                    DataGroup.Control,
                    DataArgumentType.Identity,
                    Message.GetNext,
                    id);

                if (result == TwainResult.EndOfList)
                {
                    break;
                }
                else if (result != TwainResult.Success)
                {
                    throw new TwainException("Error enumerating sources.", result);
                }

                sources.Add(id.ProductName);
            }

            return(sources);
        }
示例#18
0
        private bool NegotiateArea(ScanSettings scanSettings)
        {
            var area = scanSettings.Area;

            if (area == null)
            {
                return(false);
            }

            try
            {
                var cap = new Capability(Capabilities.IUnits, TwainType.UInt16, _applicationId, SourceId);
                if ((Units)cap.GetBasicValue().Int16Value != area.Units)
                {
                    Capability.SetBasicCapability(Capabilities.IUnits, (int)area.Units, TwainType.UInt16, _applicationId, SourceId);
                }
            }
            catch
            {
                Logger.WriteLog(LOG_LEVEL.LL_SUB_FUNC, "DataSource failed to set Units");
                // Do nothing if the data source does not support the requested capability
            }

            var imageLayout = new ImageLayout
            {
                Frame = new Frame
                {
                    Left   = new Fix32(area.Left),
                    Top    = new Fix32(area.Top),
                    Right  = new Fix32(area.Right),
                    Bottom = new Fix32(area.Bottom)
                }
            };

            var result = Twain32Native.DsImageLayout(
                _applicationId,
                SourceId,
                DataGroup.Image,
                DataArgumentType.ImageLayout,
                Message.Set,
                imageLayout);

            if (result != TwainResult.Success)
            {
                Logger.WriteLog(LOG_LEVEL.LL_SUB_FUNC, "DataSource failed to set ImageLayout");
                // note: 我這裡總是失敗,但是實際上image layout是可以設定成功的,由掃描結果不同來推測。
                //throw new TwainException("DsImageLayout.GetDefault error", result);
            }

            return(true);
        }
示例#19
0
        public static ConditionCode GetConditionCode(Identity applicationId, Identity sourceId)
        {
            Status status = new Status();

            Twain32Native.DsmStatus(
                applicationId,
                sourceId,
                DataGroup.Control,
                DataArgumentType.Status,
                Message.Get,
                status);

            return(status.ConditionCode);
        }
示例#20
0
        public void OpenSource()
        {
            var result = Twain32Native.DsmIdentity(
                _applicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Identity,
                Message.OpenDS,
                SourceId);

            if (result != TwainResult.Success)
            {
                throw new TwainException("Error opening data source", result);
            }
        }
示例#21
0
        private bool NegotiateArea(ScanSettings scanSettings)
        {
            var area = scanSettings.Area;

            if (area == null)
            {
                return(false);
            }

            try
            {
                var cap = new Capability(Capabilities.IUnits, TwainType.Int16, _applicationId, SourceId);
                if ((Units)cap.GetBasicValue().Int16Value != area.Units)
                {
                    Capability.SetCapability(Capabilities.IUnits, (short)area.Units, _applicationId, SourceId);
                }
            }
            catch
            {
                // Do nothing if the data source does not support the requested capability
            }

            var imageLayout = new ImageLayout
            {
                Frame = new Frame
                {
                    Left   = new Fix32(area.Left),
                    Top    = new Fix32(area.Top),
                    Right  = new Fix32(area.Right),
                    Bottom = new Fix32(area.Bottom)
                }
            };

            var result = Twain32Native.DsImageLayout(
                _applicationId,
                SourceId,
                DataGroup.Image,
                DataArgumentType.ImageLayout,
                Message.Set,
                imageLayout);

            if (result != TwainResult.Success)
            {
                throw new TwainException("DsImageLayout.GetDefault error", result);
            }

            return(true);
        }
示例#22
0
        public static DataSource UserSelected(Identity applicationId, IWindowsMessageHook messageHook)
        {
            var defaultSourceId = new Identity();

            // Show the TWAIN interface to allow the user to select a source
            var result = Twain32Native.DsmIdentity(
                applicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Identity,
                Message.UserSelect,
                defaultSourceId);

            _log.Debug(string.Format("UserSelect, result: {0}", result));
            return(new DataSource(applicationId, defaultSourceId, messageHook, _log));
        }
示例#23
0
        protected void SetValue <T>(T value)
        {
            /*log.Debug(string.Format("Attempting to set capabilities:{0}, value:{1}, type:{1}",
             *  _capability, value, _twainType));*/
            Logger.WriteLog(LOG_LEVEL.LL_NORMAL_LOG, string.Format("Attempting to set capabilities:{0}, value:{1}, type:{2}",
                                                                   _capability, value, _twainType.ToString()));

            int rawValue        = Convert.ToInt32(value);
            var oneValue        = new CapabilityOneValue(_twainType, rawValue);
            var twainCapability = TwainCapability.From(_capability, oneValue);

            TwainResult result = Twain32Native.DsCapability(
                _applicationId,
                _sourceId,
                DataGroup.Control,
                DataArgumentType.Capability,
                Message.Set,
                twainCapability);

            if (result != TwainResult.Success)
            {
                Logger.WriteLog(LOG_LEVEL.LL_SUB_FUNC, string.Format("Failed to set capabilities:{0}, value:{1}, type:{2}, result:{3}",
                                                                     _capability, value, _twainType, result));

                if (result == TwainResult.Failure)
                {
                    var conditionCode = GetStatus();

                    Logger.WriteLog(LOG_LEVEL.LL_SERIOUS_ERROR, string.Format("Failed to set capabilites:{0} reason: {1}",
                                                                              _capability, conditionCode));

                    throw new TwainException("Failed to set capability.", result, conditionCode);
                }
                else if (result == TwainResult.CheckStatus)
                {
                    Logger.WriteLog(LOG_LEVEL.LL_SUB_FUNC, "Value changed but not to requested value");
                }
                else
                {
                    throw new TwainException("Failed to set capability.", result);
                }
            }
            else
            {
                Logger.WriteLog(LOG_LEVEL.LL_NORMAL_LOG, "Set capabilities:" + _capability + " successfully");
            }
        }
示例#24
0
        protected void SetValue <T>(T value)
        {
            log.Debug(string.Format("Attempting to set capabilities:{0}, value:{1}, type:{1}",
                                    _capability, value, _twainType));

            int rawValue        = Convert.ToInt32(value);
            var oneValue        = new CapabilityOneValue(_twainType, rawValue);
            var twainCapability = TwainCapability.From(_capability, oneValue);

            TwainResult result = Twain32Native.DsCapability(
                _applicationId,
                _sourceId,
                DataGroup.Control,
                DataArgumentType.Capability,
                Message.Set,
                twainCapability);

            if (result != TwainResult.Success)
            {
                log.Debug(string.Format("Failed to set capabilities:{0}, value:{1}, type:{1}, result:{2}",
                                        _capability, value, _twainType, result));

                if (result == TwainResult.Failure)
                {
                    var conditionCode = GetStatus();

                    log.Error(string.Format("Failed to set capabilites:{0} reason: {1}",
                                            _capability, conditionCode));

                    throw new TwainException("Failed to set capability.", result, conditionCode);
                }
                else if (result == TwainResult.CheckStatus)
                {
                    log.Debug("Value changed but not to requested value");
                }
                else
                {
                    throw new TwainException("Failed to set capability.", result);
                }
            }
            else
            {
                log.Debug("Set capabilities successfully");
            }
        }
示例#25
0
        public void OpenSource()
        {
            var result = Twain32Native.DsmIdentity(
                _applicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Identity,
                Message.OpenDS,
                SourceId);

            if (result != TwainResult.Success)
            {
                throw new TwainException("Error opening data source", result);
            }
            if (result != TwainResult.Success)
            {
                throw new TwainException("Error opening data source: " + SourceId.ProductName, result);
            }
            isOpened = true;
            NegotiateProgressIndicator();  // ←do this first to suppresss error messages
        }
示例#26
0
        public void OpenSource()
        {
            var result = Twain32Native.DsmIdentity(
                _applicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Identity,
                Message.OpenDS,
                SourceId);

            if (result != TwainResult.Success)
            {
                var conditionCode = DataSourceManager.GetConditionCode(_applicationId, SourceId);
                _log.Debug(string.Format("OpenDS, result: {0}, conditionCode: {1}", result, conditionCode));
                throw new TwainException("Error opening data source", result, conditionCode);
            }

            _log.Debug("OpenDS, result: " + result);

            SourceState = TwainState.SourceOpen;
        }
示例#27
0
        public void Close()
        {
            var result = Twain32Native.DsmIdentity(
                _applicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Identity,
                Message.CloseDS,
                SourceId);


            if (result != TwainResult.Failure)
            {
                _log.Debug(string.Format("CloseDS, result: {0}", result));
                SourceState = null;
            }
            else
            {
                var condition = DataSourceManager.GetConditionCode(_applicationId, SourceId);
                _log.Debug(string.Format("CloseDS, result: {0}, conditionCode: {1}", result, condition));
            }
        }
示例#28
0
        /// <summary>
        /// Get default data source.
        /// </summary>
        /// <param name="applicationId"></param>
        /// <param name="messageHook"></param>
        /// <returns></returns>
        public static DataSource GetDefault(Identity applicationId, IWindowsMessageHook messageHook)
        {
            var defaultSourceId = new Identity();

            // Attempt to get information about the system default source
            var result = Twain32Native.DsmIdentity(
                applicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Identity,
                Message.GetDefault,
                defaultSourceId);

            if (result != TwainResult.Success)
            {
                ConditionCode status = DataSourceManager.GetConditionCode(applicationId, null);
                Logger.WriteLog(LOG_LEVEL.LL_SERIOUS_ERROR, "Error getting information about the default source: " + result);
                throw new TwainException("Error getting information about the default source: " + result, result, status);
            }

            return(new DataSource(applicationId, defaultSourceId, messageHook));
        }
示例#29
0
        public DataSource GetDefault(Identity applicationId)
        {
            var defaultSourceId = new Identity();

            // Attempt to get information about the system default source
            var result = Twain32Native.DsmIdentity(
                applicationId,
                IntPtr.Zero,
                DataGroup.Control,
                DataArgumentType.Identity,
                Message.GetDefault,
                defaultSourceId);

            if (result != TwainResult.Success)
            {
                var status = GetConditionCode(applicationId, null);

                _log.Debug(string.Format("GetDefault, result: {0}, conditionCode: {1}", result, status));
                throw new TwainException("Error getting information about the default source: " + result, result, status);
            }
            _log.Debug(string.Format("GetDefault, result: {0}", result));
            return(new DataSource(applicationId, defaultSourceId, _messageHook, _log));
        }
示例#30
0
        public bool Enable(ScanSettings settings)
        {
            UserInterface ui = new UserInterface();

            ui.ShowUI     = (short)(settings.ShowTwainUI ? 1 : 0);
            ui.ModalUI    = 1;
            ui.ParentHand = _messageHook.WindowHandle;

            var result = Twain32Native.DsUserInterface(
                _applicationId,
                SourceId,
                DataGroup.Control,
                DataArgumentType.UserInterface,
                Message.EnableDS,
                ui);

            if (result != TwainResult.Success)
            {
                Dispose();
                return(false);
            }
            return(true);
        }