Exemple #1
0
        //============================================================================
        // NOMBRE: SeleccionarEscaner
        //
        // DESCRIPCIÓN: Permite seleccionar un escáner de entre todos los instalados en el sistema.
        //
        // ARGUMENTOS: -
        //
        // SALIDA: Booleano que indica si la selección del escáner se ha realizado correctamente
        //============================================================================
        public bool SeleccionarEscaner()
        {
            TwRC accionUsuario = escaner.Select();

            if (accionUsuario == TwRC.Success)
            {
                return(true);//Escaner seleccionado correctamente
            }
            else
            {
                return(false);//El usuario ha cancelado la selección o bien se ha producido algún error
            }
        }
Exemple #2
0
        //============================================================================
        // NOMBRE: Adquirir
        //
        // DESCRIPCIÓN: Muestra la ventana de opciones del escáner.
        //
        // ARGUMENTOS: -
        //
        // SALIDA: Booleano que indica si el escáner es accesible
        //============================================================================
        public bool Adquirir()
        {
            TwRC escanerAccesible = escaner.Acquire();

            if (escanerAccesible == TwRC.Success)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        //============================================================================
        // NOMBRE: Inicializar
        //
        // DESCRIPCIÓN: Prepara el escáner para su uso.
        //
        // ARGUMENTOS: -
        //
        // SALIDA: Booleano que indica si la inicialización del escáner se ha producido correctamente
        //============================================================================
        public bool Inicializar()
        {
            TwRC existeTwain = escaner.Init(handle);

            if (existeTwain == TwRC.Success)
            {
                return(true);//Existe escaner
            }
            else
            {
                return(false);//No existe escaner o se ha producido algún error
            }
        }
Exemple #4
0
        public TwainCommand PassMessage(ref Message m)
        {
            if (srcds.Id == IntPtr.Zero)
            {
                return(TwainCommand.Not);
            }

            int pos = GetMessagePos();

            winmsg.hwnd    = m.HWnd;
            winmsg.message = m.Msg;
            winmsg.wParam  = m.WParam;
            winmsg.lParam  = m.LParam;
            winmsg.time    = GetMessageTime();
            winmsg.x       = (short)pos;
            winmsg.y       = (short)(pos >> 16);

            Marshal.StructureToPtr(winmsg, evtmsg.EventPtr, false);
            evtmsg.Message = 0;
            TwRC rc = DSevent(appid, srcds, TwDG.Control, TwDAT.Event, TwMSG.ProcessEvent, ref evtmsg);

            if (rc == TwRC.NotDSEvent)
            {
                return(TwainCommand.Not);
            }
            if (evtmsg.Message == (short)TwMSG.XFerReady)
            {
                return(TwainCommand.TransferReady);
            }
            if (evtmsg.Message == (short)TwMSG.CloseDSReq)
            {
                return(TwainCommand.CloseRequest);
            }
            if (evtmsg.Message == (short)TwMSG.CloseDSOK)
            {
                return(TwainCommand.CloseOk);
            }

            if (evtmsg.Message == 0)
            {
                return(TwainCommand.CloseOk);
            }

            if (evtmsg.Message == (short)TwMSG.DeviceEvent)
            {
                return(TwainCommand.DeviceEvent);
            }

            return(TwainCommand.Null);
        }
        private TwRC OpenDS()
        {
            CloseDS();
            TwRC rc = tw.DsmIdentity(appId, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, sources[CurrentScanner]);

            if (rc == TwRC.Success)
            {
                twainState |= TwainStateFlag.DSOpen;
            }
            else
            {
                throw new Exception(GetTwainStatus());
            }
            return(rc);
        }
Exemple #6
0
        public TwainCommand PassMessage(ref Message m)
        {
            TwainCommand result;

            if (this.srcds.Id == IntPtr.Zero)
            {
                result = TwainCommand.Not;
            }
            else
            {
                int messagePos = Twain.GetMessagePos();
                this.winmsg.hwnd    = m.HWnd;
                this.winmsg.message = m.Msg;
                this.winmsg.wParam  = m.WParam;
                this.winmsg.lParam  = m.LParam;
                this.winmsg.time    = Twain.GetMessageTime();
                this.winmsg.x       = (int)((short)messagePos);
                this.winmsg.y       = (int)((short)(messagePos >> 16));
                Marshal.StructureToPtr(this.winmsg, this.evtmsg.EventPtr, false);
                this.evtmsg.Message = 0;
                TwRC twRC = Twain.DSevent(this.appid, this.srcds, TwDG.Control, TwDAT.Event, TwMSG.ProcessEvent, ref this.evtmsg);
                if (twRC == TwRC.NotDSEvent)
                {
                    result = TwainCommand.Not;
                }
                else if (this.evtmsg.Message == 257)
                {
                    result = TwainCommand.TransferReady;
                }
                else if (this.evtmsg.Message == 258)
                {
                    result = TwainCommand.CloseRequest;
                }
                else if (this.evtmsg.Message == 259)
                {
                    result = TwainCommand.CloseOk;
                }
                else if (this.evtmsg.Message == 260)
                {
                    result = TwainCommand.DeviceEvent;
                }
                else
                {
                    result = TwainCommand.Null;
                }
            }
            return(result);
        }
        private TwRC SetCapability()
        {
            TwCapability cap = new TwCapability(TwCap.XferCount, 1, TwType.Int16);
            TwRC         rc  = tw.DsCapability(appId, sources[CurrentScanner], TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);

            if (rc != TwRC.Success)
            {
                CloseDS();
                throw new Exception(GetTwainStatus());
            }
            else
            {
                twainState |= TwainStateFlag.DSReady;
            }
            return(rc);
        }
        private TwRC OpenDSM()
        {
            CloseDSM();
            TwRC rc = tw.DsmParent(appId, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwnd);

            if (rc == TwRC.Success)
            {
                twainState |= TwainStateFlag.DSMOpen;
                GetAllSorces();
                CurrentScanner = DefaultScanner;
            }
            else
            {
                throw new Exception(GetTwainStatus());
            }
            return(rc);
        }
Exemple #9
0
        public ArrayList TransferPictures()
        {
            ArrayList pics = new ArrayList();

            if (srcds.Id == IntPtr.Zero)
            {
                return(pics);
            }

            TwRC           rc;
            IntPtr         hbitmap = IntPtr.Zero;
            TwPendingXfers pxfr    = new TwPendingXfers();

            do
            {
                pxfr.Count = 0;
                hbitmap    = IntPtr.Zero;

                TwImageInfo iinf = new TwImageInfo();
                rc = DSiinf(appid, srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, iinf);
                if (rc != TwRC.Success)
                {
                    CloseSrc();
                    return(pics);
                }

                rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap);
                if (rc != TwRC.XferDone)
                {
                    CloseSrc();
                    return(pics);
                }

                rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pxfr);
                if (rc != TwRC.Success)
                {
                    CloseSrc();
                    return(pics);
                }

                pics.Add(hbitmap);
            }while (pxfr.Count != 0);

            rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pxfr);
            return(pics);
        }
        public void Acquire()
        {
            CloseSrc();

            if (appid.Id == IntPtr.Zero)
            {
                Init(hwnd);

                if (appid.Id == IntPtr.Zero)
                {
                    return;
                }
            }

            TwRC rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds);

            if (rc != TwRC.Success)
            {
                return;
            }

            TwCapability cap = new TwCapability(TwCap.XferCount, 1);

            rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);

            if (rc != TwRC.Success)
            {
                CloseSrc();
                return;
            }

            TW_USERINTERFACE guif = new TW_USERINTERFACE();

            guif.ShowUI     = 1;
            guif.ModalUI    = 1;
            guif.ParentHand = hwnd;

            rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif);

            if (rc != TwRC.Success)
            {
                CloseSrc();
                return;
            }
        }
Exemple #11
0
        /// <summary>
        /// Init data source
        /// </summary>
        /// <param name="hwndp"></param>
        public void Init(IntPtr hwndp)
        {
            CloseDSM();
            TwRC rc = DSMparent(m_appId, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp);

            if (rc == TwRC.Success)
            {
                rc = DSMident(m_appId, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetDefault, m_srcDs);
                if (rc == TwRC.Success)
                {
                    m_hWnd = hwndp;
                }
                else
                {
                    rc = DSMparent(m_appId, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, ref hwndp);
                }
            }
        }
        public String Select()
        {
            CloseSrc();

            if (appid.Id == IntPtr.Zero)
            {
                Init(hwnd);

                if (appid.Id == IntPtr.Zero)
                {
                    return("");
                }
            }

            TwRC rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.UserSelect, srcds);

            return(srcds.ProductName);
        }
        public void Init(IntPtr hwndp)
        {
            Finish();
            TwRC rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp);

            if (rc == TwRC.Success)
            {
                rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetDefault, srcds);
                if (rc == TwRC.Success)
                {
                    hwnd = hwndp;
                }
                else
                {
                    rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, ref hwndp);
                }
            }
        }
Exemple #14
0
        public bool SelectByName(string name)
        {
            if (srcds.ProductName == name)
            {
                return(true);
            }
            TwRC rc = TwRC.Success;

            while (rc == TwRC.Success)
            {
                rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetNext, srcds);
                if (srcds.ProductName == name)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #15
0
        public void Init(IntPtr hwndp)
        {
            this.Finish();
            TwRC twRC = Twain.DSMparent(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp);

            if (twRC == TwRC.Success)
            {
                twRC = Twain.DSMident(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.UserSelect, this.srcds);
                if (twRC == TwRC.Success)
                {
                    this.hwnd = hwndp;
                }
                else
                {
                    twRC = Twain.DSMparent(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, ref hwndp);
                }
            }
            TwIdentity twIdentity = this.srcds;
        }
Exemple #16
0
        public bool Init(IntPtr hwndp)
        {
            Finish();
            TwRC rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp);

            if (rc == TwRC.Success)
            {
                rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetFirst, srcds);
                if (rc == TwRC.Success)
                {
                    hwnd = hwndp;
                    return(true);
                }
                else
                {
                    rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, ref hwndp);
                    return(false);
                }
            }
            return(false);
        }
Exemple #17
0
        public void Acquire2()
        {
            this.CloseSrc();
            if (this.appid.Id == IntPtr.Zero)
            {
                this.Init(this.hwnd);
                if (this.appid.Id == IntPtr.Zero)
                {
                    return;
                }
            }
            TwRC twRC = Twain.DSMident(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, this.srcds);

            if (twRC == TwRC.Success)
            {
                TwCapability capa = new TwCapability(TwCap.XferCount, 1, TwType.Int16);
                twRC = Twain.DScap(this.appid, this.srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capa);
                if (twRC != TwRC.Success)
                {
                    this.CloseSrc();
                }
            }
        }
        private TwRC EnableDS()
        {
            TwRC rc = SetCapability();

            if (rc == TwRC.Success)
            {
                TwUserInterface guif = new TwUserInterface()
                {
                    ShowUI     = false,
                    ModalUI    = true,
                    ParentHand = hwnd
                };
                rc = tw.DsUserinterface(appId, sources[CurrentScanner], TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif);
                if (rc == TwRC.Success)
                {
                    twainState |= TwainStateFlag.DSEnabled;
                }
                else
                {
                    throw new Exception(GetTwainStatus());
                }
            }
            return(rc);
        }
Exemple #19
0
        public TwRC Init(IntPtr hwndp)
        {
            TwRC existeTwain = TwRC.Success;

            Finish();
            TwRC rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp);

            if (rc == TwRC.Success)
            {
                rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetDefault, srcds);

                existeTwain = rc;
                if (rc == TwRC.Success)
                {
                    hwnd = hwndp;
                }
                else
                {
                    rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, ref hwndp);
                }
            }

            return(existeTwain);
        }
Exemple #20
0
 public void Init(IntPtr hwndp)
 {
     try
     {
         Finish();
         TwRC rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp);
         if (rc == TwRC.Success)
         {
             rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetDefault, srcds);
             if (rc == TwRC.Success)
             {
                 hwnd = hwndp;
             }
             else
             {
                 rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, ref hwndp);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: Conecte el Dispositivo de Escaneo. \n" + ex.Message);
     }
 }
Exemple #21
0
 private bool Check(TwRC rc)
 {
     return(rc == TwRC.Success);
 }
Exemple #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TwainException"/> class.
 /// </summary>
 /// <param name="cc">The condition code.</param>
 /// <param name="rc">The return code.</param>
 internal TwainException(TwCC cc, TwRC rc) : this(TwainException._CodeToMessage(cc))
 {
     this.ConditionCode = cc;
     this.ReturnCode    = rc;
 }
Exemple #23
0
        /// <summary>
        /// 獲得掃描 結果
        /// </summary>
        public void Acquire(bool ShowGUI, int DPI)
        {
            #region INIT
            CloseSrc();
            if (appid.Id == IntPtr.Zero)
            {
                Init(hwnd);
                if (appid.Id == IntPtr.Zero)
                {
                    return;
                }
            }
            rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds);
            if (rc != TwRC.Success)
            {
                return;
            }
            #endregion

            #region GUI
            TwUserInterface guif = new TwUserInterface();


            if (ShowGUI)
            {
                guif.ShowUI     = 1;
                guif.ModalUI    = 1;
                guif.ParentHand = hwnd;
            }
            else
            {
                guif.ShowUI     = 0;
                guif.ModalUI    = 0;
                guif.ParentHand = IntPtr.Zero;
            }

            #endregion

            #region DPI
            //TwCapability capUnit = new TwCapability(TwCap.IUnits, 0);
            //rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capUnit);
            //TwCapability capX = new TwCapability(TwCap.IXResolution, (short)DPI);
            //rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capX);
            //if (rc != TwRC.Success)
            //{
            //    CloseSrc();
            //    return;
            //}

            //TwCapability capY = new TwCapability(TwCap.IYResolution, (short)DPI);
            //rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capY);
            //if (rc != TwRC.Success)
            //{
            //    CloseSrc();
            //    return;
            //}
            #endregion

            #region 單/雙面
            //TwCapability capDuplex = new TwCapability(TwCap.CAP_DUPLEXENABLED, 1, true);//雙面
            ////TwCapability capDuplex = new TwCapability(TwCap.CAP_DUPLEXENABLED, 0, true);//單面
            //rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capDuplex);
            //if (rc != TwRC.Success)
            //{
            //    CloseSrc();
            //    return;
            //}
            #endregion

            #region 邊界 (無作用)



            ////TwCapability cap = new TwCapability(TwCap.ICAP_AUTOMATICBORDERDETECTION, 1, true);
            //TwCapability cap = new TwCapability(TwCap.ICAP_AUTOMATICBORDERDETECTION, (short)1);
            //rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);

            //if (rc != TwRC.Success)
            //{
            //    CloseSrc();
            //    return;
            //}
            #endregion

            #region 連續掃描 (未測試)

            #region 多張設定

            // 1 = only 1 image if we're not using the user interface
            // -1 = scan all images if we're not using the user interface

            //TwCapability cap = new TwCapability(TwCap.XferCount, -1);//單張
            //TwCapability cap = new TwCapability(TwCap.XferCount, 2);//多張
            //TwCapability xfrecount = new TwCapability(TwCap.XferCount, 1);//多張
            //rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, xfrecount);
            //if (rc != TwRC.Success)
            //{
            //    CloseSrc();
            //    return;
            //}
            #endregion

            #region MyRegion
            //TwCapability cap = new TwCapability(TwCap.XferCount, -1);//連掃
            //TwCapability cap = new TwCapability(TwCap.XferCount, 1);//一張
            //rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);
            //if (rc != TwRC.Success)
            //{
            //    CloseSrc();
            //    return;
            //}
            #endregion

            #endregion

            #region 色彩 PixelType  無作用

            // Set the scan type
            // 0 = BW | 1 = Gray | 4 = Colour
            //short PixelType = 4;//無作用 0,1,2,3,8,16,-1
            //TwCapability ptCap = new TwCapability(TwCap.IPixelType, PixelType);
            ////TwCapability ptCap = new TwCapability(TwCap.IPixelType, 4, TwType.Int16);//err
            ////TwCapability ptCap = new TwCapability(TwCap.IPixelType, 4, TwType.Int16);//err

            //rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, ptCap);
            //if (rc != TwRC.Success)
            //{
            //    CloseSrc();
            //    return;
            //}

            #region color IBitDepth

            #region test result
            //pt:8>3,16,24  not work

            //pt:1>1,8,16,24,32  not work
            //pt:-1>16  not work
            //pt:2>8,16,24  not work
            //pt:3>8,16,24  not work
            //pt:4> 8,16,24,32  not work

            #endregion

            //short BitDepth = 24;
            ////b/w:1
            ////gray:8
            ////c:24

            //// set pixel bit depth to 1 bit (b/w)
            //TwCapability bdCap = new TwCapability(TwCap.IBitDepth, BitDepth);
            ////TwCapability bdCap = new TwCapability(TwCap.IBitDepth, (short)16, TwType.UInt16);//err不可用
            //rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, bdCap);
            //if (rc != TwRC.Success)
            //{
            //    CloseSrc();
            //    return;
            //}
            #endregion


            #region 亮度.ok
            //TwCapability capBrightness = new TwCapability(TwCap.ICAP_BRIGHTNESS, 100);
            //rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capBrightness);
            //if (rc != TwRC.Success)
            //{
            //    CloseSrc();
            //    return;
            //}
            #endregion

            #region  比.ok
            //// Set the gamma (doesn't work for BW)
            //TwCapability capGamma = new TwCapability(TwCap.ICAP_GAMMA, 2, TwType.Fix32);

            //TwCapability capGamma = new TwCapability(TwCap.ICAP_GAMMA, 1);
            //rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capGamma);
            //if (rc != TwRC.Success)
            //{
            //    CloseSrc();
            //    return;
            //}
            #endregion


            #endregion

            #region ds 沒有紙
            rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif);
            if (rc != TwRC.Success)
            {
                CloseSrc();
                return;
            }
            #endregion
        }
        private string GetTwainStatus()
        {
            TwStatus status = new TwStatus();
            TwRC     _rc    = tw.DsmStatus(appId, IntPtr.Zero, TwDG.Control, TwDAT.Status, TwMSG.Get, status);

            switch (status.ConditionCode)
            {
            case TwCC.Success:
                return("It worked!");

            case TwCC.Bummer:
                return("Failure due to unknown causes.");

            case TwCC.LowMemory:
                return("Not enough memory to perform operation.");

            case TwCC.NoDS:
                return("No Data Source.");

            case TwCC.MaxConnections:
                return("DS is connected to max possible applications.");

            case TwCC.OperationError:
                return("DS or DSM reported error, application shouldn't.");

            case TwCC.BadCap:
                return("Unknown capability.");

            case TwCC.BadProtocol:
                return("Unrecognized MSG DG DAT combination.");

            case TwCC.BadValue:
                return("Data parameter out of range.");

            case TwCC.SeqError:
                return("DG DAT MSG out of expected sequence.");

            case TwCC.BadDest:
                return("Unknown destination Application/Source in DSM_Entry.");

            case TwCC.CapUnsupported:
                return("Capability not supported by source.");

            case TwCC.CapBadOperation:
                return("Operation not supported by capability.");

            case TwCC.CapSeqError:
                return("Capability has dependancy on other capability.");

            /* Added 1.8 */
            case TwCC.Denied:
                return("File System operation is denied (file is protected).");

            case TwCC.FileExists:
                return("Operation failed because file already exists.");

            case TwCC.FileNotFound:
                return("File not found.");

            case TwCC.NotEmpty:
                return("Operation failed because directory is not empty.");

            case TwCC.PaperJam:
                return("The feeder is jammed.");

            case TwCC.PaperDoubleFeed:
                return("The feeder detected multiple pages.");

            case TwCC.FileWriteError:
                return("Error writing the file (meant for things like disk full conditions).");

            case TwCC.CheckDeviceOnline:
                return("The device went offline prior to or during this operation.");

            default:
                return("Unknown error.");
            }
        }
Exemple #25
0
        public System.Collections.Generic.List <string> TransferePicturesSaveImmediate(string ScanPath, string ScanTitle)
        {
            System.Collections.Generic.List <string> pics = new System.Collections.Generic.List <string>();
            if (srcds.Id == IntPtr.Zero)
            {
                return(pics);
            }

            TwRC           rc;
            IntPtr         hbitmap      = IntPtr.Zero;
            TwPendingXfers pxfr         = new TwPendingXfers();
            bool           boolEven     = false;
            string         LastFileName = "";

            #region do while
            do
            {
                pxfr.Count = 0;
                hbitmap    = IntPtr.Zero;

                TwImageInfo iinf = new TwImageInfo();
                rc = DSiinf(appid, srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, iinf);
                if (rc != TwRC.Success)
                {
                    CloseSrc();
                    return(pics);
                }

                rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap);
                if (rc != TwRC.XferDone)
                {
                    CloseSrc();
                    return(pics);
                }

                rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pxfr);
                if (rc != TwRC.Success)
                {
                    CloseSrc();
                    return(pics);
                }

                #region add ab file end
                string desFileName;
                if (boolEven)
                {
                    desFileName = ScanPath + ScanTitle + LastFileName + "_B";
                }
                else
                {
                    LastFileName = DateTime.Now.ToString("_yyMMddHHmmssffff");
                    System.Threading.Thread.Sleep(1);
                    desFileName = ScanPath + ScanTitle + LastFileName + "_A";
                }
                boolEven = !boolEven;
                #endregion

                DJScan.PicForm newpic = new DJScan.PicForm(hbitmap);
                newpic.Text = desFileName;
                pics.Add(desFileName + ".bmp");
                newpic.Show();
                newpic.saveImg();
                newpic.Close();
            }while (pxfr.Count != 0);
            #endregion



            rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pxfr);
            return(pics);
        }
Exemple #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataSourceException"/> class.
 /// </summary>
 /// <param name="rc">The TWRC_xxxx.</param>
 /// <param name="cc">The TWCC_xxxx.</param>
 public DataSourceException(TwRC rc, TwCC cc) : this(rc, cc, string.Empty)
 {
 }
Exemple #27
0
        /// <summary>
        /// 初始化扫描进程显示界面
        /// 添加文件保存后台线程的三个回调方法
        /// </summary>
        private void Init()
        {
            worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                String fileSingleName;      // 每次传输返回的文件名

                //获取传输模式
                TwMode mode = twSession.GetCurrentTransferMode();
                switch (mode)
                {
                case TwMode.TWSX_FILE:
                    transferFileAction = twSession.TransferSingleFileInFileMode;
                    break;

                case TwMode.TWSX_NATIVE:
                    transferFileAction = twSession.TransferSingleFileInNativeMode;
                    break;

                default:
                    break;
                }

                // 1:初始化GDI+
                Gdip.InitGDIPlus();

                //2:依次传输每个文件
                logger.Debug("开始传输文件:" + DateTime.Now);
                if (transferFileAction != null)
                {
                    int count = 0;
                    try
                    {
                        do
                        {
                            logger.Debug("开始传输单个文件: count = " + count);
                            //传输单个文件
                            transferResult = transferFileAction(fileType, out fileSingleName, resolution, out msg);
                            logger.Debug("传输单个文件结束: result = " + transferResult);
                            logger.Debug("开始结束一次传输过程。");
                            twSession.EndXfer(out count);
                            logger.Debug("结束一次传输过程结束: count = " + count);
                            //2.1:传输成功则检查文件大小
                            if (transferResult == TwRC.XferDone)
                            {
                                logger.Debug("得到一个传输文件: " + DateTime.Now);
                                if (fileSingleName != null)
                                {
                                    //A:判断读取的文件大小,零字节则不添加到列表中
                                    FileInfo fileInfo = new FileInfo(fileSingleName);
                                    if (fileInfo.Length > blankSizeLimit && fileInfo.Length < maxImageSize)
                                    {
                                        cnt++;
                                        fileNames.Add(fileSingleName);
                                        worker.ReportProgress(fileNames.Count);
                                        logger.Debug("添加文件到列表,文件名: " + fileSingleName);
                                        //iacTwain.RaiseGetOnePageEvent(fileSingleName);
                                    }
                                    //B:否则删除文件
                                    else
                                    {
                                        fileInfo.Delete();
                                        logger.Info("删除太大或太小的扫描结果文件。");
                                    }
                                }
                                else
                                {
                                    logger.Debug("文件名为null。");
                                }
                            }
                            //2.2:传输失败则跳出循环
                            else
                            {
                                logger.Debug("传输失败,跳出循环。");
                                //if (count != 0) //如果扫描仪还有图像未传输,通知扫描仪清空
                                //    twSession.ResetScanner();
                                break;
                            }
                            logger.Debug("结束传输单个文件: count = " + count);
                        } while (count != 0 && count != -2);
                        logger.Debug("结束循环 :" + DateTime.Now);
                    }
                    #region 异常处理
                    catch (ArgumentNullException e)
                    {
                        logger.Error("参数为空异常,异常信息: " + e.Message);
                    }
                    catch (ArgumentException e)
                    {
                        logger.Error("无效参数异常,异常信息: " + e.Message);
                    }
                    catch (System.Security.SecurityException e)
                    {
                        logger.Error("安全性错误引发的异常,异常信息: " + e.Message);
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        logger.Error("IO错误或指定类型引发的安全性错误引发的异常,异常信息: " + e.Message);
                    }
                    catch (PathTooLongException e)
                    {
                        logger.Error("路径太长引发的异常,异常信息: " + e.Message);
                    }
                    catch (NotSupportedException e)
                    {
                        logger.Error("调用的方法不受支持或视图读取,查找或写入不支持调用功能的流引发的异常,异常信息: " + e.Message);
                    }
                    catch (IOException e)
                    {
                        logger.Error("IO异常,异常信息: " + e.Message);
                    }
                    catch (Exception e)
                    {
                        logger.Error("操作发生异常,异常信息: " + e.Message);
                    }
                    finally
                    {
                        Gdip.ClearGDIPlus();
                    }
                    #endregion
                }
            };

            worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                buttonControl.Content = "已经扫描传输" + cnt + "页";
            };

            worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                if (transferResult == TwRC.Failure)
                {
                    MessageBox.Show("扫描失败:" + msg);
                }
                else
                {
                    if (twSession.State >= TwState.OpenDS)
                    {
                        twSession.DisableDS();
                    }
                }

                if (transferResult == TwRC.TransferError)
                {
                    MessageBox.Show("传输失败:" + msg);
                }

                if (transferResult == TwRC.BadValue)
                {
                    MessageBox.Show("扫描仪当前设置不支持文件格式" + fileType + ",请重新设置");
                }

                Close();
            };
        }
Exemple #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataSourceException"/> class.
 /// </summary>
 /// <param name="rc">The TWRC_xxxx.</param>
 /// <param name="cc">The TWCC_xxxx.</param>
 /// <param name="message">The message.</param>
 public DataSourceException(TwRC rc, TwCC cc, string message) : base(message)
 {
     this.ReturnCode    = rc;
     this.ConditionCode = cc;
 }