public void CloseSrc() { if (this.srcds.Id != IntPtr.Zero) { TwUserInterface guif = new TwUserInterface(); TwRC twRC = Twain.DSuserif(this.appid, this.srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.DisableDS, guif); twRC = Twain.DSMident(this.appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.CloseDS, this.srcds); } }
public void StopAcquire() { TwUserInterface guif = new TwUserInterface(); var rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.StopFeeder, guif); if (!ACSConfig.GetScanner().Driver.ToUpper().Contains("FUJITSU") && !ACSConfig.GetScanner().Driver.ToUpper().Contains("SP-1120")) { Application.DoEvents(); } }
public void CloseSrc() { TwRC rc; if (srcds.Id != IntPtr.Zero) { TwUserInterface guif = new TwUserInterface(); rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.DisableDS, guif); rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.CloseDS, srcds); } }
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(); } } } } } }
public void CloseSrc() { TwRC rc; try { if (srcds.Id != IntPtr.Zero) { TwUserInterface guif = new TwUserInterface(); rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.DisableDS, guif); rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.CloseDS, srcds); } } catch (AccessViolationException ex) { } }
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 CloseSrc() { try { if (!ACSConfig.GetScanner().Driver.ToUpper().Contains("FUJITSU") && !ACSConfig.GetScanner().Driver.ToUpper().Contains("SP-1120")) { TwRC rc; if (srcds.Id != IntPtr.Zero) { TwUserInterface guif = new TwUserInterface(); rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.DisableDS, guif); rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.CloseDS, srcds); } } } catch (Exception) { } }
public TwRC Acquire() { TwRC rc = TwRC.Success; CloseSrc(); if (appid.Id == IntPtr.Zero) { Init(hwnd); if (appid.Id == IntPtr.Zero) { return(rc); } } rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds); if (rc != TwRC.Success) { return(rc); } TwCapability cap = new TwCapability(TwCap.XferCount, 1); rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap); if (rc != TwRC.Success) { CloseSrc(); return(rc); } 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(rc); } return(rc); }
private static extern TwRC DSuserif([In, Out] TwIdentity origin, [In, Out] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, TwUserInterface guif);
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); }
/// <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 }
public void Acquire() { TwRC rc; 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; 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; } }
private static extern TwRC DSuserif( [In, Out] TwIdentity origin, [In, Out] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, TwUserInterface guif );
public void CloseSrc() { TwRC rc; if( srcds.Id != IntPtr.Zero ) { TwUserInterface guif = new TwUserInterface(); rc = DSuserif( appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.DisableDS, guif ); rc = DSMident( appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.CloseDS, srcds ); } }