| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474 | 
							- using System;
 
- using System.Collections;
 
- using System.Text;
 
- using System.Xml;
 
- using Aitex.Core.Common.DeviceData;
 
- using Aitex.Core.RT.DataCenter;
 
- using Aitex.Core.RT.Device;
 
- using Aitex.Core.RT.Event;
 
- using Aitex.Core.RT.IOCore;
 
- using Aitex.Core.RT.Log;
 
- using Aitex.Core.RT.OperationCenter;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Core.RT.Tolerance;
 
- using Aitex.Core.Util;
 
- using MECF.Framework.Common.Communications;
 
- using MECF.Framework.Common.DataCenter;
 
- using MECF.Framework.Common.Device.Bases;
 
- using MECF.Framework.Common.Equipment;
 
- using Venus_Core;
 
- namespace Venus_RT.Devices
 
- {
 
-     public enum EdwardsPumpState { ON = 0, OFF, Connected, Disconnected, Unknown, ERROR }
 
-     static class EdwardsPumpControlSystemParameters
 
-     {
 
-         public const int System_Node = 1;
 
-         public const int Dry_Pump_Current = 3;
 
-         public const int Dry_Pump_Power = 4;
 
-         public const int Booster_Current = 7;
 
-         public const int Booster_Power = 8;
 
-         public const int Dry_Pump_Control = 11;
 
-         public const int Dry_Pump_Run_hours = 14;
 
-         public const int Number_of_pump_starts = 20;
 
-     }
 
-     static class EdwardsPumpMessage
 
-     {
 
-         public const string EOF = "\r\n";
 
-         public const string RESET = "/";
 
-         public const string QUERY_Alarm_Status = "?A";
 
-         public const string QUERY_Bitfield_Status = "?B";
 
-         public const string QUERY_Control_Status = "?C";
 
-         public const string QUERY_Gas_ballast_Status = "?D";
 
-         public const string QUERY_Gate_valve_Status = "?G";
 
-         public const string QUERY_Nitrogen_supply_Status = "?N";
 
-         public const string QUERY_On_process_Status = "?O";
 
-         public const string QUERY_Pump_Status = "?P";
 
-         public const string QUERY_Run_til_crash_Status = "?R";
 
-         public const string QUERY_Inlet_purge_Status = "?U";
 
-         public const string QUERY_Pump_node_type = "?T";
 
-         public const string QUERY_Value = "?V";
 
-         public const string QUERY_Serial_Number = "?S";
 
-         public const string QUERY_Information = "?I";
 
-         public const string QUERY_Format_mode = "?F";
 
-         public const string COMMAND_Release_Control = "!C0";
 
-         public const string COMMAND_Take_Control = "!C1";
 
-         public const string COMMAND_Gas_ballast = "!D";
 
-         public const string COMMAND_Equipment = "!E";
 
-         public const string COMMAND_Format_mode = "!F";
 
-         public const string COMMAND_Gate_valve = "!G";
 
-         public const string COMMAND_Reserved = "!L";
 
-         public const string COMMAND_Simulation_mode = "!M";
 
-         public const string COMMAND_Nitrogen_supply = "!N";
 
-         public const string COMMAND_On_process = "!O";
 
-         public const string COMMAND_Switch_on_Pump = "!P1";
 
-         public const string COMMAND_Switch_off_Pump_Auto_shut_down = "!P0";
 
-         public const string COMMAND_Switch_off_Pump_Fast_shut_down = "!P2";
 
-         public const string COMMAND_Run_til_crash = "!R";
 
-         public const string COMMAND_Reserved_do_not_use = "!T";
 
-         public const string COMMAND_Inlet_purge = "!U";
 
-         public const string COMMAND_Terminate_protocol = "!XO";
 
-         public const string SET_SHORT_REPLY = "!F0";
 
-         public const string SET_LONG_REPLY = "!F1";
 
-     }
 
-     class EdwardsPump : PumpBase
 
-     {
 
-         // ----------------------------Fields--------------------------
 
-         //
 
-         private const ushort CHK_ST_INTERVAL = 1000;
 
-         private const ushort CHK_CONTROL_INTERVAL = 3 * 1000;
 
-         private const ushort CHK_REC_INTERVAL = 20 * 1000;
 
-         private const ushort CHK_PUMP_REC_INTERVAL = 10 * 1000;
 
-         private double _total;
 
-         private double _fromLast;
 
-         private const string EOF = "\r";
 
-         private const char MSG_DELIMITER = ' ';
 
-         private readonly string _PortNum = "COM91";
 
-         private const int _counterMax = 30;
 
-         //private int _counter = 0;
 
-         private static string SendData;
 
-         private readonly AsyncSerialPort _serial;
 
-         private readonly DeviceTimer _timerQueryStatus = new DeviceTimer();
 
-         private readonly DeviceTimer _timerControlStatus = new DeviceTimer();
 
-         private readonly DeviceTimer _timerReceiveStatus = new DeviceTimer();
 
-         private readonly DeviceTimer _timerPumpOn = new DeviceTimer();
 
-         private readonly DeviceTimer _timerPumpOff = new DeviceTimer();
 
-         private readonly DeviceTimer _timerTotal = new DeviceTimer();
 
-         private readonly DeviceTimer _timerFromLast = new DeviceTimer();
 
-         private readonly R_TRIG _trigPumpOn = new R_TRIG();
 
-         private readonly R_TRIG _trigPumpOff = new R_TRIG();
 
-         private readonly R_TRIG _trigReceiveStatus = new R_TRIG();
 
-         private readonly RD_TRIG _trigOnOff = new RD_TRIG();
 
-         private readonly R_TRIG _trigPMNeeded = new R_TRIG();
 
-         private StatsDataItemRFAndPump _statPumpOnTime;
 
-         // --------------------------Properties------------------------
 
-         //
 
-         public EdwardsPumpState StatusDry { get; set; }
 
-         public string LastPMTime
 
-         {
 
-             get
 
-             {
 
-                 return _statPumpOnTime != null ? _statPumpOnTime.LastPMTime.ToString() : "";
 
-             }
 
-         }
 
-         public double DaysFromLastPM
 
-         {
 
-             get
 
-             {
 
-                 return _statPumpOnTime == null ? 0 : _statPumpOnTime.fromLastPM;
 
-             }
 
-             set
 
-             {
 
-                 if (_statPumpOnTime != null)
 
-                     _statPumpOnTime.fromLastPM = value;
 
-             }
 
-         }
 
-         public double TotalDays
 
-         {
 
-             get
 
-             {
 
-                 return _statPumpOnTime != null ? _statPumpOnTime.Total : 0;
 
-             }
 
-             set
 
-             {
 
-                 if (_statPumpOnTime != null)
 
-                     _statPumpOnTime.Total = value;
 
-             }
 
-         }
 
-         public double PMIntervalDays
 
-         {
 
-             get
 
-             {
 
-                 return _statPumpOnTime != null ? _statPumpOnTime.PMInterval : 0;
 
-             }
 
-         }
 
-         public bool IsPMNeeded
 
-         {
 
-             get
 
-             {
 
-                 return DaysFromLastPM > PMIntervalDays;
 
-             }
 
-         }
 
-         public bool EnableAlarm
 
-         {
 
-             get
 
-             {
 
-                 return _statPumpOnTime == null || _statPumpOnTime.AlarmEnable;
 
-             }
 
-         }
 
-         [Subscription(AITPumpProperty.IsRunning)]
 
-         public override bool IsRunning
 
-         {
 
-             get
 
-             {
 
-                 return StatusDry == EdwardsPumpState.ON;
 
-             }
 
-         }
 
-         [Subscription(AITPumpProperty.IsError)]
 
-         public override bool IsError
 
-         {
 
-             get
 
-             {
 
-                 return StatusDry == EdwardsPumpState.ERROR || StatusDry == EdwardsPumpState.Disconnected;
 
-             }
 
-         }
 
-         public override AITPumpData DeviceData
 
-         {
 
-             get
 
-             {
 
-                 AITPumpData deviceData = new AITPumpData
 
-                 {
 
-                     DeviceName = Name,
 
-                     DeviceModule = Module,
 
-                     DeviceSchematicId = DeviceID,
 
-                     DisplayName = Display,
 
-                     IsError = false,
 
-                     IsWarning = false,
 
-                     IsOn = IsRunning,
 
-                     //WaterFlow = WaterFlowValue,
 
-                     IsDryPumpEnable = true,
 
-                     IsN2PressureEnable = false,
 
-                     IsWaterFlowEnable = false,
 
-                     //WaterFlowWarning = WaterFlowWarning,
 
-                     //WaterFlowAlarm = WaterFlowAlarm,
 
-                     //N2PressureAlarm = N2PressureAlarm,
 
-                     //N2PressureWarning = N2PressureWarning,
 
-                 };
 
-                 return deviceData;
 
-             }
 
-         }
 
-         // --------------------------Constructor-----------------------
 
-         //
 
-         public EdwardsPump(ModuleName mod) : base(mod.ToString(), VenusDevice.MainPump.ToString(), "Edwards Pump", "")
 
-         {
 
-             _PortNum = SC.GetStringValue($"{mod}.DryPump.Port");
 
-             StatusDry = EdwardsPumpState.Unknown;
 
-             _serial = new AsyncSerialPort(_PortNum, 9600, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "\r\n", true);
 
-         }
 
-         public EdwardsPump(ModuleName mod, string name) : base(mod.ToString(), VenusDevice.MainPump.ToString(), "Edwards Pump", "")
 
-         {
 
-             _PortNum = SC.GetStringValue($"{mod.ToString()}.{name}.Port");
 
-             StatusDry = EdwardsPumpState.Unknown;
 
-             _serial = new AsyncSerialPort(_PortNum, 9600, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "\r\n", true);
 
-         }
 
-         public override bool Initialize()
 
-         {
 
-             base.Initialize();
 
-             if (!_serial.Open())
 
-             {
 
-                 StatusDry = EdwardsPumpState.Disconnected;
 
-                 LOG.Write(eEvent.ERR_DRY_PUMP, Module, "Edwards Pump串口无法打开");
 
-                 return false;
 
-             }
 
-             _statPumpOnTime = StatsDataManager.Instance.GetItemRFAndPump($"{Module}.PumpOnTime");
 
-             StatusDry = EdwardsPumpState.Connected;
 
-             _trigPumpOn.RST = true;
 
-             _trigPumpOff.RST = true;
 
-             _trigReceiveStatus.RST = true;
 
-             _serial.OnDataChanged += OnPortDataChanged;
 
-             _serial.OnErrorHappened += OnErrorOccurred;
 
-             SendCmd(EdwardsPumpMessage.RESET);
 
-             SendCmd(EdwardsPumpMessage.SET_SHORT_REPLY);
 
-             SendCmd(EdwardsPumpMessage.COMMAND_Take_Control);
 
-             _timerQueryStatus.Start(CHK_ST_INTERVAL);
 
-             _timerControlStatus.Start(CHK_CONTROL_INTERVAL);
 
-             _timerReceiveStatus.Start(CHK_REC_INTERVAL);
 
-             return true;
 
-         }
 
-         private void OnErrorOccurred(string obj)
 
-         {
 
-             StatusDry = EdwardsPumpState.ERROR;
 
-             LOG.Write(eEvent.WARN_DEVICE_INFO, Module, $"[{Module}] edwards pump error: [{obj}]");
 
-         }
 
-         private void OnPortDataChanged(string obj)
 
-         {
 
-             if (string.IsNullOrEmpty(obj))
 
-                 LOG.Write(eEvent.WARN_DEVICE_INFO, Module, "edwards pump message IsNullOrEmpty");
 
-             try
 
-             {
 
-                 _timerReceiveStatus.Stop();
 
-                 _timerReceiveStatus.Start(CHK_REC_INTERVAL);
 
-                 string cmd = obj.ToString().Split('\n')[0].Split('\r')[0];
 
-                 switch (SendData)
 
-                 {
 
-                     case EdwardsPumpMessage.RESET:
 
-                         break;
 
-                     case EdwardsPumpMessage.COMMAND_Take_Control:
 
-                         LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Take Control Edwards Pump {QueryCmdReply(cmd)}");
 
-                         break;
 
-                     case EdwardsPumpMessage.COMMAND_Release_Control:
 
-                         LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Release Control Edwards Pump {QueryCmdReply(cmd)}");
 
-                         break;
 
-                     case EdwardsPumpMessage.COMMAND_Switch_on_Pump:
 
-                         LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Switch on Edwards Pump {QueryCmdReply(cmd)}");
 
-                         break;
 
-                     case EdwardsPumpMessage.COMMAND_Switch_off_Pump_Fast_shut_down:
 
-                         LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Switch off Edwards Pump {QueryCmdReply(cmd)}");
 
-                         break;
 
-                     case EdwardsPumpMessage.QUERY_Pump_Status:
 
-                         if (cmd == "0")
 
-                         {
 
-                             StatusDry = EdwardsPumpState.OFF;
 
-                             if (_trigPumpOn.Q && _timerPumpOn.IsTimeout())
 
-                             {
 
-                                 _trigPumpOn.RST = true;
 
-                                 LOG.Write(eEvent.WARN_DEVICE_INFO, Module, "Edwards Pump 无法打开");
 
-                             }
 
-                             if (_trigPumpOff.Q)
 
-                             {
 
-                                 LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Edwards Pump关闭");
 
-                             }
 
-                             _trigPumpOff.RST = true;
 
-                         }
 
-                         else if (cmd == "4")
 
-                         {
 
-                             StatusDry = EdwardsPumpState.ON;
 
-                             if (_trigPumpOff.Q && _timerPumpOff.IsTimeout())
 
-                             {
 
-                                 _trigPumpOff.RST = true;
 
-                                 LOG.Write(eEvent.WARN_DEVICE_INFO, Module, "Edwards Pump 无法关闭");
 
-                             }
 
-                             if (_trigPumpOn.Q)
 
-                             {
 
-                                 LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Edwards Pump打开");
 
-                             }
 
-                             _trigPumpOn.RST = true;
 
-                         }
 
-                         break;
 
-                     default:
 
-                         LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Edwards Pump {SendData} {QueryCmdReply(cmd)}");
 
-                         break;
 
-                 }
 
-             }
 
-             catch (Exception ex)
 
-             {
 
-                 LOG.WriteExeption($"[{Module}] edwards pump error: ", ex);
 
-             }
 
-         }
 
-         public string QueryCmdReply(string cmd)
 
-         {
 
-             if (cmd == "ERR 0")
 
-             {
 
-                 return "No error";
 
-             }
 
-             else if (cmd == "ERR 1")
 
-             {
 
-                 return "Invalid message";
 
-             }
 
-             else if (cmd == "ERR 2")
 
-             {
 
-                 return "Number not found";
 
-             }
 
-             else if (cmd == "ERR 3")
 
-             {
 
-                 return "Number Invalid";
 
-             }
 
-             else if (cmd == "ERR 4")
 
-             {
 
-                 return "Parameter’s value not received";
 
-             }
 
-             else if (cmd == "ERR 5")
 
-             {
 
-                 return "Command not possible";
 
-             }
 
-             else
 
-             {
 
-                 return cmd;
 
-             }
 
-         }
 
-         public override void Monitor()
 
-         {
 
-             try
 
-             {
 
-                 // 状态查询
 
-                 if (_timerQueryStatus.IsTimeout() && this.StatusDry != EdwardsPumpState.ERROR)
 
-                 {
 
-                     this.SendCmd(EdwardsPumpMessage.QUERY_Pump_Status);
 
-                     _timerQueryStatus.Start(CHK_ST_INTERVAL);
 
-                 }
 
-                 if (_timerReceiveStatus.IsTimeout() && this.StatusDry != EdwardsPumpState.ERROR)
 
-                 {
 
-                     _trigReceiveStatus.CLK = true;
 
-                     if (_trigReceiveStatus.Q)
 
-                     {
 
-                         //EV.PostMessage(Module, EventEnum.DefaultWarning, "Edwards Pump 没有回复");
 
-                         //EV.PostAlarmLog(Module, "Edwards Pump 没有回复",)
 
-                     }
 
-                 }
 
-                 _trigOnOff.CLK = IsRunning;
 
-                 //第一次检测到打开了,开始计时
 
-                 if (_trigOnOff.R)
 
-                 {
 
-                     _total = TotalDays;
 
-                     _fromLast = DaysFromLastPM;
 
-                     _timerTotal.Start(0);
 
-                     _timerFromLast.Start(0);
 
-                 }
 
-                 //第一次检测到从打开到关闭状态
 
-                 if (_trigOnOff.T)
 
-                 {
 
-                 }
 
-                 //如果开着,就更新SC
 
-                 if (_trigOnOff.M)
 
-                 {
 
-                     TotalDays = _total + _timerTotal.GetElapseTime() / 1000 / 60 / 60;
 
-                     DaysFromLastPM = _fromLast + _timerFromLast.GetElapseTime() / 1000 / 60 / 60;
 
-                 }
 
-                 if (PMIntervalDays > 0)
 
-                 {
 
-                     _trigPMNeeded.CLK = IsPMNeeded;
 
-                     if (_trigPMNeeded.Q)
 
-                     {
 
-                         if (EnableAlarm)
 
-                         {
 
-                             EV.PostAlarmLog(Module, "pump on time value larger than setting interval days");
 
-                         }
 
-                     }
 
-                 }
 
-                 StatsDataManager.Instance.Increase($"{Module}.PumpOnTime", $"{Module} PumpOnTime", DaysFromLastPM, TotalDays);
 
-             }
 
-             catch (Exception ex)
 
-             {
 
-                 throw ex;
 
-             }
 
-         }
 
-         private bool SendCmd(string str)
 
-         {
 
-             SendData = str;
 
-             if (SendData == "!P1")
 
-             {
 
-                 _trigPumpOn.CLK = true;
 
-                 _timerPumpOn.Start(CHK_PUMP_REC_INTERVAL);
 
-                 LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"[{Module}] Switch on Edwards Pump");
 
-             }
 
-             else if (SendData == "!P2")
 
-             {
 
-                 _trigPumpOff.CLK = true;
 
-                 _timerPumpOff.Start(CHK_PUMP_REC_INTERVAL);
 
-                 LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"[{Module}] Switch off Edwards Pump");
 
-             }
 
-             return _serial.Write(str + "\r");
 
-         }
 
-         public override void Reset()
 
-         {
 
-             _trigPumpOn.RST = true;
 
-             _trigPumpOff.RST = true;
 
-             _trigReceiveStatus.RST = true;
 
-             _trigPMNeeded.RST = true;
 
-             SendCmd(EdwardsPumpMessage.RESET);
 
-         }
 
-         public override void Terminate()
 
-         {
 
-             //if (StatusDry == EdwardsPumpState.ON)
 
-             //    SetPumpOnOff(false);
 
-             _serial?.Close();
 
-         }
 
-         public override void SetPumpOnOff(bool on)
 
-         {
 
-             SendCmd(on ? EdwardsPumpMessage.COMMAND_Switch_on_Pump : EdwardsPumpMessage.COMMAND_Switch_off_Pump_Fast_shut_down);
 
-         }
 
-     }
 
- }
 
 
  |