/// <summary>
        /// Monitors the flow rate and adjustes voltage to pump as necessary in
        /// order to maintain desired flowrate.
        /// </summary>
        protected override void Run()
        {
            try
            {
                if (!Pump.IsRunning())
                {
                    return;
                }

                ConsoleState state = Master.ConsoleService.CurrentState;
                if (state == ConsoleState.Diagnosing || state == ConsoleState.InteractiveDiagnostics)
                {
                    return;
                }

                int openedPosition = Pump.GetOpenValvePosition();

                if (openedPosition > 0)
                {
                    DateTime openTime = Pump.GetTimePumpStarted();
                    DateTime now      = DateTime.UtcNow;

                    Log.Debug(string.Format("Opened solenoid {0} at {1}", Pump.GetOpenValvePosition(), Log.DateTimeToString(openTime)));

                    Pump.FlowStatus flowStatus = Pump.CheckFlow();

                    if (flowStatus != Pump.FlowStatus.TooLow)
                    {
                        _flowFailures = 0;
                        if ((openTime != DateTime.MinValue) && ((now - openTime) > _periodAllowedOpen))
                        {
                            Pump.CloseValve(openedPosition);   // Close the valve.
                        }
                    }
                    // Else, assumption is that FlowStatus is TooLow. (empty cylinder?)
                    else if (((now - openTime) > _minOpenPeriod) &&
                             Pump.IsRunning())
                    {
                        _flowFailures++;
                        Log.Debug("Flow failed " + _flowFailures + " times.");

                        if (_flowFailures >= _MIN_FLOW_FAILURES)
                        {
                            _flowFailures = 0;
                            Pump.CloseValve(openedPosition);
                        }
                        else
                        {
                            Pump.OpenValve(Pump.GetOpenValvePosition(), false);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(Name, e);
            }
        }
Beispiel #2
0
 public virtual bool IsRunning()
 {
     return(Pump.IsRunning());
 }