Пример #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>
        /// Cycle through the modes On/Off/Standby if we are already in one of the modes.
        /// We leave in On mode if we are already in one of the three modes.
        /// </summary>
        /// <param name="end">timeout</param>
        /// <returns>true if we are not in On/Off/Standby initially or if we reached On mode after the cycle.</returns>
        private bool CycleModes(DateTime end)
        {
            if (!Acquisition.WaitFor(TimeSpan.Zero, SystemMode.Off, SystemMode.Standby, SystemMode.On))
            {
                return(true);
            }

            // Test every possible switch!
            KeyValuePair <IMode, SystemMode>[] switches =
            {
                new KeyValuePair <IMode, SystemMode>(Acquisition.CreateStandbyMode(), SystemMode.Standby),
                new KeyValuePair <IMode, SystemMode>(Acquisition.CreateOnMode(),      SystemMode.On),
                new KeyValuePair <IMode, SystemMode>(Acquisition.CreateStandbyMode(), SystemMode.Standby),
                new KeyValuePair <IMode, SystemMode>(Acquisition.CreateOffMode(),     SystemMode.Off),
                new KeyValuePair <IMode, SystemMode>(Acquisition.CreateOnMode(),      SystemMode.On),
                new KeyValuePair <IMode, SystemMode>(Acquisition.CreateOffMode(),     SystemMode.Off),
                new KeyValuePair <IMode, SystemMode>(Acquisition.CreateStandbyMode(), SystemMode.Standby),
                new KeyValuePair <IMode, SystemMode>(Acquisition.CreateOnMode(),      SystemMode.On),
            };
            if (Arguments.Verbose)
            {
                Console.WriteLine("Switching modes...");
            }

            DateTime start = DateTime.MaxValue;

            for (int i = 0; i < switches.Length; i++)
            {
                if (i == 1)
                {
                    // After the first "change" we take the time. The "change" may not
                    // had any influence if we had been in this state already. And don't
                    // be too smart in detecting the correct state.
                    start = Now;
                }
                if (Arguments.Chatty)
                {
                    Console.Write("   to {0} ", switches[i].Value.ToString());
                }
                if (Acquisition.SetMode(switches[i].Key) != ChangeResult.Submitted)
                {
                    if (Arguments.Chatty)
                    {
                        Console.WriteLine();
                    }
                    Console.WriteLine("Cannot set the instrument to {0}...", switches[i].Value.ToString());
                    return(false);
                }
                if (Arguments.Chatty)
                {
                    Console.Write(" ...");
                }
                if (!Acquisition.WaitFor(end - Now, switches[i].Value))
                {
                    if (Arguments.Chatty)
                    {
                        Console.WriteLine();
                    }
                    Console.WriteLine("Mode change to {0} didn't happen as expected...", switches[i].Value.ToString());
                    return(false);
                }
                if (Arguments.Chatty)
                {
                    Console.WriteLine();
                }
            }
            TimeSpan switchingTime6 = Now - start;

            if (Arguments.Verbose)
            {
                Console.WriteLine("Average mode switching time: {0:F2} ms", switchingTime6.TotalMilliseconds / 6);
            }

            return(true);
        }