/// <summary> /// DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER /// This triplet is used to cancel or terminate a transfer. Issued in state 6, this triplet cancels the next /// pending transfer, discards the transfer data, and decrements the pending transfers count. In state 7, /// this triplet terminates the current transfer. If any data has not been transferred (this is only /// possible during a memory transfer) that data is discarded. /// The application can use this operation to cancel the next pending transfer (Source writers take /// note of this). For example, after the application checks TW_IMAGEINFO(or TW_AUDIOINFO, if /// transferring audio snippets), it may decide to not transfer the next image. The operation must be /// sent prior to the beginning of the transfer, otherwise the Source will simply abort the current /// transfer. The Source decrements the number of pending transfers. /// /// DG_CONTROL / DAT_PENDINGXFERS / MSG_GET /// Returns the number of transfers the Source is ready to supply to the application, upon demand. If /// DAT_XFERGROUP is set to DG_IMAGE, this is the number of images.If DAT_XFERGROUP is set to /// DG_AUDIO, this is the number of audio snippets for the current image. If there is no current /// image, this call must return TWRC_FAILURE / TWCC_SEQERROR. /// /// DG_CONTROL / DAT_PENDINGXFERS / MSG_RESET /// Sets the number of pending transfers in the Source to zero. /// </summary> /// <param name="msg">The Message of the operation triplet.</param> /// <param name="data">The data parameter is a pointer to the data (a variable or, more /// typically, a structure) that will be used according to the action specified by the operation /// triplet.</param> /// <returns>TWAIN Return Codes.</returns> private TwRC _PendingXfersProcessRequest(TwMSG msg, IntPtr data) { try { switch (msg) { case TwMSG.EndXfer: if ((this.State & DataSourceState.Ready) == 0) { throw new DataSourceException(TwRC.Failure, TwCC.SeqError); } if (this.XferEnvironment.PendingXfers == 0) { throw new DataSourceException(TwRC.Failure, TwCC.OperationError); } this.XferEnvironment.PendingXfers--; this.OnEndXfer(); break; case TwMSG.Get: break; case TwMSG.Reset: if ((this.State & DataSourceState.Ready) == 0 || (this.State & DataSourceState.Transferring) != 0) { throw new DataSourceException(TwRC.Failure, TwCC.SeqError); } this.XferEnvironment.PendingXfers = 0; this.OnResetXfer(); break; default: throw new DataSourceException(TwRC.Failure, TwCC.BadProtocol); } var _pendingXfers = new TwPendingXfers { Count = this.XferEnvironment.PendingXfers }; for (var _cap = this[TwCap.JobControl]; _cap != null;) { _pendingXfers.EOJ = (uint)(TwJC)_cap.Value; break; } Marshal.StructureToPtr(_pendingXfers, data, true); return(TwRC.Success); } finally { if (this.XferEnvironment.PendingXfers >= 0) { this.State &= ~DataSourceState.Transferring; } if (this.XferEnvironment.PendingXfers == 0) { this.State &= ~DataSourceState.Ready; this.XferEnvironment.ImageInfo = null; } } }
private ArrayList TransferPictures() { ArrayList pics = new ArrayList(); if (CurrentScanner == -1) { return(pics); } TwRC rc; TwPendingXfers pendingxfer = new TwPendingXfers(); do { pendingxfer.Count = 0; IntPtr hbitmap = IntPtr.Zero; TwImageInfo imageinfo = new TwImageInfo(); rc = tw.DsImageInfo(appId, sources[CurrentScanner], TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, imageinfo); if (rc != TwRC.Success) { CloseDS(); return(pics); } rc = tw.DsImagexfer(appId, sources[CurrentScanner], TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap); if (rc != TwRC.XferDone) { CloseDS(); return(pics); } rc = tw.DsPendingxfers(appId, sources[CurrentScanner], TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pendingxfer); if (rc != TwRC.Success) { CloseDS(); return(pics); } pics.Add(hbitmap); }while (pendingxfer.Count != 0); rc = tw.DsPendingxfers(appId, sources[CurrentScanner], TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pendingxfer); return(pics); }
public TwPendingXfers DiscardPendingTransfers(TwIdentity dataSourceId) { TwPendingXfers result = new TwPendingXfers(); TwRC rc = LibTwain32.DSpxfer(fApplicationId, dataSourceId, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, result); return (rc == TwRC.Success) ? result : null; }
public bool DiscardPendingTransfers(TwIdentity dataSourceId, TwPendingXfers result) { TwRC rc = LibTwain32.DSpxfer(fApplicationId, dataSourceId, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, result); return (bool)(rc == TwRC.Success); }
private void _ImageTransmission() { ArrayList _pics=new ArrayList(); if(this._srcds.Id==IntPtr.Zero) { return; } IntPtr _hBitmap=IntPtr.Zero; TwPendingXfers _pxfr=new TwPendingXfers(); Image _img=null; do { _pxfr.Count=0; _hBitmap=IntPtr.Zero; var _isXferDone=DsImageXfer(this._appid,this._srcds,TwDG.Image,TwDAT.ImageNativeXfer,TwMSG.Get,ref _hBitmap)==TwRC.XferDone; if(DsPendingXfer(this._appid,this._srcds,TwDG.Control,TwDAT.PendingXfers,TwMSG.EndXfer,_pxfr)==TwRC.Success && _isXferDone) { IntPtr _pBitmap=GlobalLock(_hBitmap); try { this._images.Add(_img=DibToImage.WithScan(_pBitmap)); this._OnEndXfer(new EndXferEventArgs(_img)); } finally { GlobalUnlock(_hBitmap); GlobalFree(_hBitmap); } } else { break; } } while(_pxfr.Count!=0); var _rc=DsPendingXfer(this._appid,this._srcds,TwDG.Control,TwDAT.PendingXfers,TwMSG.Reset,_pxfr); }
public TwRC DsPendingxfers([In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwPendingXfers pendingxfer) { return(DsEntryPendingxfers(origin, dest, dg, dat, msg, pendingxfer)); }
internal static extern TwRC DsEntryPendingxfers([In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwPendingXfers pendingxfer);
private bool TransferPictures() { bool success = IsActive(); if(success) { TwPendingXfers pxfr = new TwPendingXfers(); success = fTwain.GetNumberOfPendingTransfers(fIdent, pxfr); while(success && (pxfr.Count != 0)) { TwImageInfo iinf = new TwImageInfo(); success = fTwain.GetImageInfo(fIdent, iinf); IntPtr hBitmap = IntPtr.Zero; if(success) { success = fTwain.TransferImage(fIdent, ref hBitmap); } if(success) { Image image = null; IntPtr ptrBitmap = LibKernel32.GlobalLock(hBitmap); image = TwainUtils.DibToImage(ptrBitmap); LibKernel32.GlobalUnlock(hBitmap); Raise_OnNewPictureData(image, fSettings); } if(success) { success = fTwain.TransferEnd(fIdent, pxfr); } } } return success; }