예제 #1
0
        /// <summary>
        /// This method ensures the system runs, either by a user-provided method/acquisition or by an
        /// already running acquisition.
        /// </summary>
        /// <param name="started">time stamp when the machine has started</param>
        /// <returns>true if the system is running, false if the instrument is disconnected</returns>
        private bool EnsureRunningSystem(DateTime started)
        {
            DateTime end = started + TimeSpan.FromMilliseconds(Arguments.OperationTime);

            // wait until the instrument is connected
            if (Acquisition.WaitFor(TimeSpan.Zero, SystemMode.Disconnected, SystemMode.Maintenance, SystemMode.Malconfigured))
            {
                Console.WriteLine("Waiting for a connection...");

                if (!Acquisition.WaitForOtherThan(end - Now, SystemMode.Disconnected, SystemMode.Maintenance, SystemMode.Malconfigured))
                {
                    return(false);
                }

                // let the instrument settle for a maximum of 45 seconds after a reconnect.
                int settleTime = Math.Max(45, (int)(end - Now).TotalSeconds);
                Acquisition.WaitFor(TimeSpan.FromSeconds(settleTime), SystemMode.On, SystemMode.Off, SystemMode.Standby);
            }

            if (Arguments.ModeTest)
            {
                if (!CycleModes(end))
                {
                    return(false);
                }
            }

            Console.WriteLine("Mode=" + Acquisition.State.SystemMode);
            Console.WriteLine("State=" + Acquisition.State.SystemState);
            if (Acquisition.WaitForOtherThan(TimeSpan.Zero, SystemMode.Disconnected, SystemMode.Maintenance, SystemMode.Malconfigured, SystemMode.Off, SystemMode.Standby))
            {
                return(true);
            }
            Console.WriteLine("Waiting for a system mode where data gets processed...");
            return(Acquisition.WaitForOtherThan(end - Now, SystemMode.Disconnected, SystemMode.Maintenance, SystemMode.Malconfigured, SystemMode.Off, SystemMode.Standby));
        }
예제 #2
0
        /// <summary>
        /// Start a method if one if given in the arguments to the program or perform another method-like acquisition.
        /// For this, the instrument needs to be On.
        /// </summary>
        /// <param name="started">time stamp when the machine has started</param>
        /// <returns>true if the system is running somehow, false if the instrument is disconnected</returns>
        private bool StartMethodIfSystemIsIdle(DateTime started)
        {
            DateTime end = started + TimeSpan.FromMilliseconds(Arguments.OperationTime);

            if (Acquisition.WaitForOtherThan(TimeSpan.Zero, SystemMode.On))
            {
                return(true);
            }

            // the instrument is on, test if we have to start an acquisition.
            IAcquisitionWorkflow methodWorkflow = null;

            if (Arguments.RunCount.HasValue)
            {
                try
                {
                    // this may throw an exception if the arguments are invalid.
                    methodWorkflow = Acquisition.CreateAcquisitionLimitedByCount(Arguments.RunCount.Value);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception creating an acquisition limited by a count: " + e.Message);
                    return(false);
                }
            }
            if (Arguments.RunTime.HasValue)
            {
                try
                {
                    // this may throw an exception if the arguments are invalid.
                    methodWorkflow = Acquisition.CreateAcquisitionLimitedByDuration(Arguments.RunTime.Value);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception creating an acquisition limited by time: " + e.Message);
                    return(false);
                }
            }
            if (Arguments.RunMethod != null)
            {
                try
                {
                    // this may throw an exception if the arguments are invalid.
                    methodWorkflow = Acquisition.CreateMethodAcquisition(Arguments.RunMethod);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception creating an acquisition defined by a method: " + e.Message);
                    return(false);
                }
            }

            // start the method
            if (methodWorkflow != null)
            {
                if (Arguments.ModeTest)
                {
                    // stop in standby mode to illustrate common value settings like starttrigger, RAW file, etc:
                    methodWorkflow.Continuation = AcquisitionContinuation.Standby;
                }
                ChangeResult result = Control.Acquisition.StartAcquisition(methodWorkflow);
                switch (result)
                {
                case ChangeResult.ForeignControl:
                // taken under foreign control in between which is OK

                case ChangeResult.IllegalOperationState:
                // taken under foreign control in between which is OK

                case ChangeResult.InstrumentDisconnected:
                // The instrument disconnected in between, which is OK

                default:
                    // Assume a harmless, unknown problem
                    return(true);

                case ChangeResult.UnknownRequestType:
                    Console.WriteLine("The interface rejected the request to start an acquisition because of an unknown request type.");
                    // let this stop to show the error prominently.
                    return(false);

                case ChangeResult.IllegalValues:
                    Console.WriteLine("The interface rejected the request to start an acquisition because of invalid values.");
                    // let this stop to show the error prominently.
                    return(false);

                case ChangeResult.Submitted:
                    return(true);
                }
            }

            // no acquisition by user selected
            return(true);
        }