| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 | 
							- using Aitex.Core.RT.Device;
 
- using Aitex.Core.RT.Routine;
 
- using Aitex.Core.RT.SCCore;
 
- using CyberX8_Core;
 
- using MECF.Framework.Common.Routine;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- namespace CyberX8_RT.Devices.Reservoir
 
- {
 
-     public class StandardHotPHRoutine : RoutineBase, IRoutine
 
-     {
 
-         private enum PHDetectStep
 
-         {
 
-             PHValveOn,
 
-             DelayFlowTime,
 
-             PHValveOff,
 
-             DelayStableTime,
 
-             Sample,
 
-             SampleRecord,
 
-             AverageSample,
 
-             End
 
-         }
 
-         #region 内部变量
 
-         private StandardHotReservoirDevice _device;
 
-         private int _phFlowTime;
 
-         private int _phStabilizationTime;
 
-         private int _phSampleTime;
 
-         private int _phSamples;
 
-         private DateTime _sampTime=DateTime.Now;
 
-         private List<double> _sampleLst = new List<double>();
 
-         private int _sampleInterval = 0;
 
-         private DateTime _startSampleTime = DateTime.Now;
 
-         #endregion
 
-         /// <summary>
 
-         /// 构造函数
 
-         /// </summary>
 
-         /// <param name="module"></param>
 
-         public StandardHotPHRoutine(string module) : base(module)
 
-         {
 
-         }
 
-         /// <summary>
 
-         /// 中止
 
-         /// </summary>
 
-         public void Abort()
 
-         {
 
-             Runner.Stop("Manual Abort");
 
-         }
 
-         /// <summary>
 
-         /// 监控
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public RState Monitor()
 
-         {
 
-             Runner.Run(PHDetectStep.PHValveOn, _device.PHValveOn, _delay_1ms)
 
-                 .Delay(PHDetectStep.DelayFlowTime, _phFlowTime)
 
-                 .Run(PHDetectStep.PHValveOff, _device.PHValveOff, _delay_1ms)
 
-                 .Delay(PHDetectStep.DelayStableTime, _phStabilizationTime)
 
-                 .Run(PHDetectStep.Sample, StartSample, _delay_1ms)
 
-                 .Run(PHDetectStep.SampleRecord, RecordSample, CheckSampleComplete, _phSampleTime + _delay_2m)
 
-                 .Run(PHDetectStep.AverageSample, AverageSample)
 
-                 .End(PHDetectStep.End, NullFun, _delay_1ms);
 
-             return Runner.Status;
 
-         }
 
-         /// <summary>
 
-         /// 启动采样
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool StartSample()
 
-         {
 
-             _sampTime = DateTime.Now;
 
-             _startSampleTime = DateTime.Now;
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 记录采样
 
-         /// </summary>
 
-         private bool RecordSample()
 
-         {
 
-             if(DateTime.Now.Subtract(_sampTime).TotalMilliseconds>=_sampleInterval)
 
-             {
 
-                 _sampleLst.Add(_device.ReservoirData.PHValue);
 
-                 _sampTime = DateTime.Now;
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 检验采样是否结束
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool CheckSampleComplete()
 
-         {
 
-             if (_sampleLst.Count>= _phSamples)
 
-             {
 
-                 return true;
 
-             }
 
-             if (DateTime.Now.Subtract(_startSampleTime).TotalMilliseconds >= _phSampleTime)
 
-             {
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// 计算平均值
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool AverageSample() 
 
-         {
 
-             double total=0.0;
 
-             for (int i = 0; i < _sampleLst.Count; i++)
 
-             {
 
-                 total += _sampleLst[i];
 
-             }
 
-             double avarage = Math.Round(total / _sampleLst.Count,2);
 
-             _device.AveragePH = avarage;
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 启动
 
-         /// </summary>
 
-         /// <param name="objs"></param>
 
-         /// <returns></returns>
 
-         public RState Start(params object[] objs)
 
-         {
 
-             _sampleLst.Clear();
 
-             _device = DEVICE.GetDevice<StandardHotReservoirDevice>(Module);
 
-             _phFlowTime =(int)Math.Round(SC.GetValue<double>("Reservoir.PHFlowTime")*1000,0);
 
-             _phStabilizationTime = (int)Math.Round(SC.GetValue<double>("Reservoir.PHStabilizationTime")*1000,0);
 
-             _phSampleTime =(int)(Math.Round(SC.GetValue<double>("Reservoir.PHSampleTime")*1000,0));
 
-             _phSamples = SC.GetValue<int>("Reservoir.PHSamples");
 
-             _sampleInterval = (int)(Math.Round((double)_phFlowTime / _phSamples,0));
 
-             return Runner.Start(Module, "Start PH Detection");
 
-         }
 
-     }
 
- }
 
 
  |