Beispiel #1
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposeEvenManagedStuff">true to dispose managed and unmanaged resources; false to dispose unmanaged resources</param>
        protected void Dispose(bool disposeEvenManagedStuff)
        {
            // prevent double disposing
            if (Interlocked.Exchange(ref m_disposed, 1) != 0)
            {
                return;
            }

            if ((Arguments != null) && Arguments.RepeatingScanTest && repeatingScanStarted && (InstrumentInstance != null))
            {
                ScansTest.CancelRepeatingScan(InstrumentInstance);
            }

            if (disposeEvenManagedStuff)
            {
                if (m_scansOutput != null)
                {
                    m_scansOutput.CloseDown();
                    m_scansOutput = null;
                }
                if (m_analogOutput != null)
                {
                    m_analogOutput.CloseDown();
                    m_analogOutput = null;
                }
                if (m_valuesTest != null)
                {
                    m_valuesTest.CloseDown();
                    m_valuesTest = null;
                }
                if (m_scansTest != null)
                {
                    m_scansTest.Dispose();
                    m_scansTest = null;
                }
                if (m_methodsTest != null)
                {
                    m_methodsTest.CloseDown();
                    m_methodsTest = null;
                }
                if (InstrumentInstance != null)
                {
                    InstrumentInstance.Dispose();
                    InstrumentInstance = null;
                }
            }


            IInstrumentAccessContainer container = Container;

            Container = null;
            if (container != null)
            {
                IDisposable disp = container as IDisposable;
                if (disp != null)
                {
                    disp.Dispose();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Let the selected operations happen.
        /// </summary>
        internal void Go()
        {
            if (Arguments.Verbose)
            {
                Console.WriteLine("Instrument ID:   " + InstrumentInstance.InstrumentId);
                Console.WriteLine("Instrument Name: " + InstrumentInstance.InstrumentName);
            }
            Console.WriteLine("Connected:       " + InstrumentInstance.Connected);
            if (Arguments.Verbose)
            {
                DumpRoles();
            }

            try
            {
                DateTime started = Now;
                m_wait = new ManualResetEvent(InstrumentInstance.Connected);

                InstrumentInstance.ConnectionChanged += new EventHandler(ConnectionChanged);
                InstrumentInstance.UserRolesChanged  += new EventHandler(UserRolesChanged);
                InstrumentInstance.ErrorsArrived     += new EventHandler <ErrorsArrivedEventArgs>(Instrument_ErrorsArrived);

                if (Arguments.ShowStatus)
                {
                    Acquisition.StateChanged += new EventHandler <StateChangedEventArgs>(Acquisition_StateChanged);
                    m_scansOutput             = new ScansOutput(InstrumentInstance, Arguments);
                }
                if (Arguments.ShowScanOutput)
                {
                    m_scansOutput = new ScansOutput(InstrumentInstance, Arguments);
                }
                if (Arguments.ShowAnalogOutput)
                {
                    m_analogOutput = new AnalogOutput(InstrumentInstance);
                }

                if (EnsureRunningSystem(started))
                {
                    if (StartMethodIfSystemIsIdle(started))
                    {
                        if (Arguments.ValuesTest)
                        {
                            m_valuesTest = new ValuesTest(InstrumentInstance, Arguments);
                        }
                        if (Arguments.MethodsTest != null)
                        {
                            m_methodsTest = new MethodsTest(InstrumentInstance, Arguments);
                        }
                        if (Arguments.RepeatingScanTest)
                        {
                            repeatingScanStarted = ScansTest.SetRepeatingScan(InstrumentInstance, Arguments.Verbose);
                        }
                        if (Arguments.ScansTest)
                        {
                            m_scansTest = new ScansTest(InstrumentInstance, Arguments);
                        }

                        int span = Arguments.OperationTime - (int)(Now - started).TotalMilliseconds;
                        if (span > 0)
                        {
                            Console.WriteLine("Sleeping for " + (span / 1000) + "s");
                            Thread.Sleep(span);
                        }
                    }
                }
            }
            finally
            {
                InstrumentInstance.ErrorsArrived     -= new EventHandler <ErrorsArrivedEventArgs>(Instrument_ErrorsArrived);
                InstrumentInstance.UserRolesChanged  -= new EventHandler(UserRolesChanged);
                InstrumentInstance.ConnectionChanged -= new EventHandler(ConnectionChanged);
            }
        }