예제 #1
0
파일: Twain.cs 프로젝트: code-mtnit/WPFSM
        public void Acquire()
        {
            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.IPixelType, 0, TwType.UInt16);
                twRC = Twain.DScap(this.appid, this.srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capa);
                if (twRC != TwRC.Success)
                {
                    this.CloseSrc();
                }
                else
                {
                    TwCapability capa2 = new TwCapability(TwCap.RESOLUTION, 200, TwType.Fix32);
                    twRC = Twain.DScap(this.appid, this.srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capa2);
                    if (twRC != TwRC.Success)
                    {
                        this.CloseSrc();
                    }
                    else
                    {
                        TwCapability capa3 = new TwCapability(TwCap.XferCount, 1, TwType.Int16);
                        twRC = Twain.DScap(this.appid, this.srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capa3);
                        if (twRC != TwRC.Success)
                        {
                            this.CloseSrc();
                        }
                        else
                        {
                            TwUserInterface twUserInterface = new TwUserInterface();
                            twUserInterface.ShowUI     = 1;
                            twUserInterface.ModalUI    = 1;
                            twUserInterface.ParentHand = this.hwnd;
                            twRC = Twain.DSuserif(this.appid, this.srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, twUserInterface);
                            if (twRC != TwRC.Success)
                            {
                                this.CloseSrc();
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public void Acquire()
        {
            TwRC rc;

            CloseSrc();
            if (appid.Id == IntPtr.Zero)
            {
                Init(hwnd);
                if (appid.Id == IntPtr.Zero)
                {
                    MessageBox.Show("Scanner not found.", "Scan Interface", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return;
            }
            TwIdentity srcds1 = new TwIdentity();

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

            //TwCapability cap = new TwCapability( TwCap.XferCount, 1 );
            //changed XferCount to -i for ADF multipage scanning
            TwCapability cap = new TwCapability(TwCap.XferCount, -1);

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

            TwUserInterface guif = new TwUserInterface();

            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;
            }
        }
        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;
            }
        }
예제 #4
0
파일: Twain.cs 프로젝트: code-mtnit/WPFSM
        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 static extern TwRC DScap([In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwCapability capa);
        public TwRC AcquireLexmark(short CountPags = 200, short ShowUI = 0, short ModalUI = 0, bool isDuplex = false)
        {
            TwRC rc;

            CloseSrc();
            if (appid.Id == IntPtr.Zero)
            {
                Init(hwnd);
                if (appid.Id == IntPtr.Zero)
                {
                    return(TwRC.Failure);
                }
            }
            rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds);
            if (rc != TwRC.Success)
            {
                ACSLog.InsertLog(MessageBoxIcon.Information, "Sem comunicação com o Scanner: Primeira tentativa - " + rc.ToString());
                return(rc);
            }

            //Quantidade de Imagens a Capturar
            TwFix32 f32 = new TwFix32();

            f32.FromFloat(CountPags);
            TwCapability cap = new TwCapability(TwCap.XferCount, f32);

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

            if (rc != TwRC.Success)
            {
                ACSLog.InsertLog(MessageBoxIcon.Information, "Sem comunicação com o Scanner: Quantidade de imagens - " + rc.ToString());
                CloseSrc();
                return(rc);
            }

            //Scanner como...
            f32 = new TwFix32();
            f32.FromFloat(this.ScanAs);
            TwCapability capPixelType = new TwCapability(TwCap.IPixelType, f32);

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

            if (rc != TwRC.Success)
            {
                ACSLog.InsertLog(MessageBoxIcon.Information, "Sem comunicação com o Scanner: Cor da captura - " + rc.ToString());
                CloseSrc();
                return(rc);
            }

            //Resolução Imagem
            f32 = new TwFix32();
            f32.FromFloat(this.Resolution);//value of DPI
            var capResolution = new TwCapability(TwCap.IXResolution, f32);

            rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.GetCurrent, capResolution);
            if (rc != TwRC.Success)
            {
                ACSLog.InsertLog(MessageBoxIcon.Information, "Sem comunicação com o Scanner: Resolução da Imagem - " + rc.ToString());
                CloseSrc();
                return(rc);
            }

            //Brightness
            short TWON_ONEVALUE = 5;

            f32 = new TwFix32();
            f32.FromFloat(this.Brightness * 10);
            var capBrightness = new TwCapability(TwCap.ICAP_BRIGHTNESS, f32);

            capBrightness.ConType = TWON_ONEVALUE;
            //capBrightness.Handle = hwnd;
            rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capBrightness);

            //Contrast
            f32 = new TwFix32();
            f32.FromFloat(this.Contrast * 10);
            var capContrast = new TwCapability(TwCap.ICAP_CONTRAST, f32);

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

            // duplex
            if (isDuplex)
            {
                f32 = new TwFix32();
                f32.FromFloat(-2);
                var XferCount = new TwCapability(TwCap.XferCount, f32);

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

                f32 = new TwFix32();
                f32.FromFloat(1);
                var capDuplexEnable = new TwCapability(TwCap.DuplexEnabled, f32);

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

                f32 = new TwFix32();
                f32.FromFloat(1);
                var capDuplex = new TwCapability(TwCap.Duplex, f32);
                capDuplex.ConType = 5;
                rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capDuplex);
            }
            else
            {
                f32 = new TwFix32();
                f32.FromFloat(-2);
                var XferCount = new TwCapability(TwCap.XferCount, f32);

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

                f32 = new TwFix32();
                f32.FromFloat(0);
                var capDuplexEnable = new TwCapability(TwCap.DuplexEnabled, f32);

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

                f32 = new TwFix32();
                f32.FromFloat(0);
                var capDuplex = new TwCapability(TwCap.Duplex, f32);
                capDuplex.ConType = 5;
                rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capDuplex);
            }


            TwUserInterface guif = new TwUserInterface();

            guif.ShowUI     = ShowUI;
            guif.ModalUI    = ModalUI;
            guif.ParentHand = hwnd;
            rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif);
            if (rc != TwRC.Success)
            {
                if (rc == TwRC.CheckStatus)
                {
                    // CloseSrc();
                    return(TwRC.Success);
                }
                ACSLog.InsertLog(MessageBoxIcon.Information, "Sem comunicação com o Scanner: Última verificação - " + rc.ToString());
                CloseSrc();
                return(rc);
            }

            return(rc);
        }
        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;
            }
        }
 private static extern TwRC DScap([In, Out] TW_IDENTITY origin, [In] TW_IDENTITY dest, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwCapability capa);