public static extern ReturnCode DsmWin32(
     [In, Out] TW_IDENTITY origin,
     [In, Out] TW_IDENTITY destination,
     DataGroups dg,
     DataArgumentType dat,
     Message msg,
     ref TW_PENDINGXFERS data);
Beispiel #2
0
        ReturnCode DoIt(Message msg, ref TW_PENDINGXFERS pendingXfers)
        {
            if (Is32Bit)
            {
                if (IsWin)
                {
                    return(NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32,
                                                  DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers));
                }
                if (IsLinux)
                {
                    return(NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32,
                                                    DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers));
                }
                if (IsMac)
                {
                    return(NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32,
                                                  DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers));
                }
            }

            if (IsWin)
            {
                return(NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32,
                                              DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers));
            }
            if (IsLinux)
            {
                return(NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32,
                                                DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers));
            }
            if (IsMac)
            {
                return(NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32,
                                              DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers));
            }

            return(ReturnCode.Failure);
        }
Beispiel #3
0
        private void DoTransferRoutine()
        {
            var xMech = GetTransferMechs();

            TW_PENDINGXFERS pending = default;
            var             rc      = DGControl.PendingXfers.Get(ref pending);

            if (rc == ReturnCode.Success)
            {
                do
                {
                    var readyArgs = new TransferReadyEventArgs(CurrentSource, pending.Count, pending.EndOfJob)
                    {
                        CancelAll = _disableDSNow
                    };
                    OnTransferReady(readyArgs);


                    #region actually handle xfer

                    if (readyArgs.CancelAll || _disableDSNow)
                    {
                        rc = DGControl.PendingXfers.Reset(ref pending);
                    }
                    else
                    {
                        if (!readyArgs.CancelCurrent)
                        {
                            if (xMech.ImageMech.HasValue)
                            {
                                switch (xMech.ImageMech.Value)
                                {
                                case XferMech.Memory:
                                    rc = DoImageMemoryXfer();
                                    break;

                                case XferMech.File:
                                    rc = DoImageFileXfer();
                                    break;

                                case XferMech.MemFile:
                                    rc = DoImageMemoryFileXfer();
                                    break;

                                case XferMech.Native:
                                default:     // always assume native
                                    rc = DoImageNativeXfer();
                                    break;
                                }
                            }
                            if (xMech.AudioMech.HasValue)
                            {
                                switch (xMech.AudioMech.Value)
                                {
                                case XferMech.File:
                                    rc = DoAudioFileXfer();
                                    break;

                                case XferMech.Native:
                                default:     // always assume native
                                    rc = DoAudioNativeXfer();
                                    break;
                                }
                            }
                        }

                        if (rc != ReturnCode.Success)// && StopOnTransferError)
                        {
                            // end xfer without setting rc to exit (good/bad?)
                            DGControl.PendingXfers.Reset(ref pending);
                        }
                        else
                        {
                            rc = DGControl.PendingXfers.EndXfer(ref pending);
                        }
                    }
                    #endregion
                } while (rc == ReturnCode.Success && pending.Count != 0 && !_disableDSNow);
            }
            else
            {
                HandleXferReturnCode(rc);
            }

            if (_disableDSNow)
            {
                DGControl.UserInterface.DisableDS(ref _lastEnableUI, false);
            }
        }
Beispiel #4
0
 /// <summary>
 /// If CapAutoScan is TRUE, this command will stop the operation of the scanner’s automatic
 /// feeder. No other action is taken.
 /// </summary>
 /// <param name="pendingXfers">The pending xfers.</param>
 /// <returns></returns>
 public ReturnCode StopFeeder(ref TW_PENDINGXFERS pendingXfers)
 {
     return(DoIt(Message.StopFeeder, ref pendingXfers));
 }
Beispiel #5
0
 /// <summary>
 /// Sets the number of pending transfers in the Source to zero.
 /// </summary>
 /// <param name="pendingXfers">The pending xfers.</param>
 /// <returns></returns>
 internal ReturnCode Reset(ref TW_PENDINGXFERS pendingXfers)
 {
     return(DoIt(Message.Reset, ref pendingXfers));
 }
Beispiel #6
0
 /// <summary>
 /// 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 Failure / SeqError.
 /// </summary>
 /// <param name="pendingXfers">The pending xfers.</param>
 /// <returns></returns>
 public ReturnCode Get(ref TW_PENDINGXFERS pendingXfers)
 {
     return(DoIt(Message.Get, ref pendingXfers));
 }
Beispiel #7
0
 /// <summary>
 /// 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.
 /// </summary>
 /// <param name="pendingXfers">The pending xfers.</param>
 /// <returns></returns>
 internal ReturnCode EndXfer(ref TW_PENDINGXFERS pendingXfers)
 {
     return(DoIt(Message.EndXfer, ref pendingXfers));
 }
Beispiel #8
0
        /// <summary>
        /// Issue pendingxfers commands...
        /// </summary>
        /// <param name="a_dg">Data group</param>
        /// <param name="a_msg">Operation</param>
        /// <param name="a_twpendingxfers">PENDINGXFERS structure</param>
        /// <returns>TWAIN status</returns>
        public STS DatPendingxfers(DG a_dg, MSG a_msg, ref TW_PENDINGXFERS a_twpendingxfers)
        {
            STS sts;

            // Submit the work to the TWAIN thread...
            if ((m_threadTwain != null) && (m_threadTwain.ManagedThreadId != Thread.CurrentThread.ManagedThreadId))
            {
                lock (m_lockTwain)
                {
                    // Set our command variables...
                    ThreadData threaddata = default(ThreadData);
                    threaddata.twpendingxfers = a_twpendingxfers;
                    threaddata.dg = a_dg;
                    threaddata.msg = a_msg;
                    threaddata.dat = DAT.PENDINGXFERS;
                    long lIndex = m_twaincommand.Submit(threaddata);

                    // Submit the command and wait for the reply...
                    CallerToThreadSet();
                    ThreadToCallerWaitOne();

                    // Return the result...
                    a_twpendingxfers = m_twaincommand.Get(lIndex).twpendingxfers;
                    sts = m_twaincommand.Get(lIndex).sts;

                    // Clear the command variables...
                    m_twaincommand.Delete(lIndex);
                }
                return (sts);
            }

            // Log it...
            if (Log.GetLevel() > 0)
            {
                Log.LogSendBefore(a_dg.ToString(), DAT.PENDINGXFERS.ToString(), a_msg.ToString(), "");
            }

            // Windows...
            if (ms_platform == Platform.WINDOWS)
            {
                // Issue the command...
                try
                {
                    if (m_blUseLegacyDSM)
                    {
                        sts = (STS)WindowsTwain32DsmEntryPendingxfers(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.PENDINGXFERS, a_msg, ref a_twpendingxfers);
                    }
                    else
                    {
                        sts = (STS)WindowsTwaindsmDsmEntryPendingxfers(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.PENDINGXFERS, a_msg, ref a_twpendingxfers);
                    }
                }
                catch
                {
                    // The driver crashed...
                    Log.LogSendAfter(STS.BUMMER.ToString(), "");
                    return (STS.BUMMER);
                }
            }

            // Linux...
            else if (ms_platform == Platform.LINUX)
            {
                // Issue the command...
                try
                {
                    if (GetMachineWordBitSize() == 32)
                    {
                        sts = (STS)LinuxDsmEntryPendingxfers(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.PENDINGXFERS, a_msg, ref a_twpendingxfers);
                    }
                    else
                    {
                        sts = (STS)Linux64DsmEntryPendingxfers(ref m_twidentityApp, ref m_twidentityDs, a_dg, DAT.PENDINGXFERS, a_msg, ref a_twpendingxfers);
                    }
                }
                catch
                {
                    // The driver crashed...
                    Log.LogSendAfter(STS.BUMMER.ToString(), "");
                    return (STS.BUMMER);
                }
            }

            // Mac OS X, which has to be different...
            else if (ms_platform == Platform.MACOSX)
            {
                // Issue the command...
                try
                {
                    sts = (STS)MacosxDsmEntryPendingxfers(ref m_twidentitymacosxApp, ref m_twidentitymacosxDs, a_dg, DAT.PENDINGXFERS, a_msg, ref a_twpendingxfers);
                }
                catch
                {
                    // The driver crashed...
                    Log.LogSendAfter(STS.BUMMER.ToString(), "");
                    return (STS.BUMMER);
                }
            }

            // Uh-oh...
            else
            {
                Log.LogSendAfter(STS.BUMMER.ToString(), "");
                return (STS.BUMMER);
            }

            // Log it...
            if (Log.GetLevel() > 0)
            {
                Log.LogSendAfter(sts.ToString(), PendingxfersToCsv(a_twpendingxfers));
            }

            // If we endxfer, go to state 5 or 6...
            if (a_msg == MSG.ENDXFER)
            {
                if (sts == STS.SUCCESS)
                {
                    if (a_twpendingxfers.Count == 0)
                    {
                        m_blIsMsgxferready = false;
                        m_state = STATE.S5;
                    }
                    else
                    {
                        m_state = STATE.S6;
                    }
                }
            }

            // If we reset, go to state 5...
            else if (a_msg == MSG.RESET)
            {
                if (sts == STS.SUCCESS)
                {
                    m_blIsMsgxferready = false;
                    m_state = STATE.S5;
                }
            }

            // All done...
            return (AutoDatStatus(sts));
        }
Beispiel #9
0
 /// <summary>
 /// Convert the contents of a pending xfers structure to a string that
 /// we can show in our simple GUI...
 /// </summary>
 /// <param name="a_twsetupfilexfer">A TWAIN structure</param>
 /// <returns>A CSV string of the TWAIN structure</returns>
 public string PendingxfersToCsv(TW_PENDINGXFERS a_twpendingxfers)
 {
     try
     {
         CSV csv = new CSV();
         csv.Add(a_twpendingxfers.Count.ToString());
         csv.Add(a_twpendingxfers.EOJ.ToString());
         return (csv.Get());
     }
     catch
     {
         return ("***error***");
     }
 }
Beispiel #10
0
 private static extern UInt16 MacosxDsmEntryPendingxfers
 (
     ref TW_IDENTITY_MACOSX origin,
     ref TW_IDENTITY_MACOSX dest,
     DG dg,
     DAT dat,
     MSG msg,
     ref TW_PENDINGXFERS twpendingxfers
 );
Beispiel #11
0
 private static extern UInt16 Linux64DsmEntryPendingxfers
 (
     ref TW_IDENTITY origin,
     ref TW_IDENTITY dest,
     DG dg,
     DAT dat,
     MSG msg,
     ref TW_PENDINGXFERS twpendingxfers
 );
Beispiel #12
0
 private static extern UInt16 WindowsTwaindsmDsmEntryPendingxfers
 (
     ref TW_IDENTITY_LEGACY origin,
     ref TW_IDENTITY_LEGACY dest,
     DG dg,
     DAT dat,
     MSG msg,
     ref TW_PENDINGXFERS twpendingxfers
 );