| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 | using System;using System.Text;using System.Collections.Generic;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.Device.Bases;using MECF.Framework.Common.Equipment;using Venus_Core;namespace Venus_RT.Devices{    class AIRSYSChiller : ChillerBase    {        private float _controlTcSetPoint;        private float _controlTcFeedback;        private readonly double _scSetPointLimitMax;        private readonly double _scSetPointLimitMin;        private readonly string _PortNum = "COM48";        private readonly AsyncSerialPort _serial;        private readonly DeviceTimer _timerQueryStatus = new DeviceTimer();        private const ushort CHK_ST_INTERVAL = 300;        public enum Operation        {            ReadTemperature,            ReadStatus,            ReadFlowRate,            ReadResistivity,            UnitStart,            UnitStop,            SelectThermoProbe,            SetTemperature,            SetResistivity,        }        private readonly Dictionary<Operation, string> _noneParaCommandOp = new Dictionary<Operation, string>        {            {Operation.ReadTemperature,             "AA10\r" },            {Operation.ReadStatus,                  "AA42\r" },            {Operation.ReadFlowRate,                "AAB1\r" },            {Operation.ReadResistivity,             "AAB2\r" },            {Operation.UnitStart,                   "AA90\r" },            {Operation.UnitStop,                    "AA91\r" },            {Operation.SelectThermoProbe,           "AAA1\r" },        };        private readonly Dictionary<Operation, string> _oneParaCommandOp = new Dictionary<Operation, string>        {            {Operation.SetTemperature,              "AAB0{0:X4}\r" },            {Operation.SetResistivity,              "AAB3{0:X4}\r" },        };        public double SetPointLimitMax        {            get            {                return _scSetPointLimitMax; ;            }        }        public double SetPointLimitMin        {            get            {                return _scSetPointLimitMin; ;            }        }        [Subscription(AITChillerProperty.ControlTcSetPoint)]        public float ControlTcSetPoint        {            get            {                return _controlTcSetPoint;            }        }        [Subscription(AITChillerProperty.ControlTcFeedback)]        public float ControlTcFeedback        {            get            {                return _controlTcFeedback;            }        }        [Subscription(AITChillerProperty.CoolantInletTempFeedback)]        public override float CoolantInletTcFeedback        {            get            {                if (jetChamber == JetChamber.Venus)                {                    return GetAiValue($"{Module}.AI_Coolant_Inlet_Temp");                }                else                {                    return 0;                }                         }        }        [Subscription(AITChillerProperty.CoolantOutletTempFeedback)]        public override float CoolantOutletTcFeedback        {            get            {                if (jetChamber == JetChamber.Venus)                {                    return GetAiValue($"{Module}.AI_Coolant_Outlet_Temp");                }                else                {                    return 0;                }            }        }        public override AITChillerData DeviceData        {            get            {                AITChillerData deviceData = new AITChillerData                {                    Module = Module,                    DeviceName = Name,                    DeviceModule = Module,                    DeviceSchematicId = DeviceID,                    DisplayName = Display,                    IsError = false,                    IsWarning = false,                    IsPowerOn = IsRunning,                    ScaleMax = SetPointLimitMax,                    ScaleMin = SetPointLimitMin,                    SetPoint = ControlTcSetPoint,                    FeedBack = CoolantOutletTcFeedback,                    CoolantInletFeedBack = CoolantInletTcFeedback,                    CoolantOutletFeedBack = CoolantOutletTcFeedback,                    Unit = "℃",                };                return deviceData;            }        }        private SCConfigItem _scAlarmRange;        private SCConfigItem _scEnableAlarm;        private SCConfigItem _scAlarmTime;        private ToleranceChecker _toleranceChecker = new ToleranceChecker();        private string _lastAlarmString;        private int _operation_flag = 0;        JetChamber jetChamber;        public AIRSYSChiller(ModuleName mod, string name) : base(mod.ToString(), name, name, "")        {            if (Module == "PMB" && SC.GetValue<bool>($"PMB.Chiller.ChillerSameWithPMA") && SC.GetValue<bool>($"PMB.Chiller.EnableChiller")) return;            _PortNum = SC.GetStringValue($"{mod}.{Name}.Port");            _scSetPointLimitMax = SC.GetValue<double>($"{Module}.{Name}.SetPointLimitMax");            _scSetPointLimitMin = SC.GetValue<double>($"{Module}.{Name}.SetPointLimitMin");            _scEnableAlarm = SC.GetConfigItem($"{Module}.{Name}.EnableToleranceAlarm");            _scAlarmRange = SC.GetConfigItem($"{Module}.{Name}.ToleranceAlarmRange");            _scAlarmTime = SC.GetConfigItem($"{Module}.{Name}.ToleranceAlarmTime");            _serial = new AsyncSerialPort(_PortNum, 9600, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.Two, "\r", true);            jetChamber = (JetChamber)SC.GetValue<int>($"{mod.ToString()}.ChamberType");        }        public override bool Initialize()        {            base.Initialize();            if (!_serial.Open())            {                LOG.Write(eEvent.ERR_DEVICE_CHILLER, Module, "AIRSYS Chiller串口无法打开");                return false;            }            _serial.OnDataChanged += OnPortDataChanged;            _serial.OnErrorHappened += OnErrorOccurred;            _timerQueryStatus.Start(CHK_ST_INTERVAL);            return true;        }        public override void Monitor()        {            if (_timerQueryStatus.IsTimeout())            {                Operation queryOp = _operation_flag++ % 2 == 0 ? Operation.ReadStatus : Operation.ReadTemperature;                _sendCommand(queryOp);                _timerQueryStatus.Start(CHK_ST_INTERVAL);            }            if (IsRunning && _scEnableAlarm != null && _scEnableAlarm.BoolValue)            {                var range = _scAlarmRange.IntValue;                var time = _scAlarmTime.IntValue;                _toleranceChecker.Monitor(_controlTcFeedback, _controlTcSetPoint - Math.Abs(range), _controlTcSetPoint + Math.Abs(range), time);                if (_toleranceChecker.Trig)                {                    LOG.Write(eEvent.ERR_DEVICE_CHILLER, Module, Display + $" temperature out of tolerance in {time:0} seconds");                }            }            else            {                _toleranceChecker.RST = true;            }        }        private void OnPortDataChanged(string obj)        {             if(obj.StartsWith("AA"))            {                string op = obj.Substring(2, 2);                switch(op)                {                    case "42":                        ushort significate_status = ushort.Parse(obj.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);                        ushort low_significatate_status = ushort.Parse(obj.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);                        _process_signicate_chiller_status(significate_status);                        _process_low_signicate_chiller_status(low_significatate_status);                        break;                    case "10":                        _controlTcFeedback = (float)Int32.Parse(obj.Substring(4, 4), System.Globalization.NumberStyles.HexNumber) / (float)10.0;                        break;                }            }            else            {                _noRepeatAlarm($"AIRSYS chiller receive wrong message:{obj}");            }        }        private void OnErrorOccurred(string obj)        {            LOG.Write(eEvent.ERR_DEVICE_CHILLER, Module, $"[{Module}] AIRSYS chiller error: [{obj}]");        }        public override void SetChillerTemp(float value, float offset)        {            int isettemp = Convert.ToInt16((value - offset) * 10);            _sendCommand(Operation.SetTemperature, isettemp);            _controlTcSetPoint = value;        }        public override void SetChillerOnOff(bool on)        {            IsRunning = on;            _sendCommand(on ? Operation.UnitStart : Operation.UnitStop);        }        private bool _sendCommand(Operation op)        {            if (_noneParaCommandOp.ContainsKey(op))            {                return _sendCmd(_noneParaCommandOp[op]);            }            _noRepeatAlarm($"Adixen Turbo Pump: The {op} command need parameters");            return false;        }        private bool _sendCommand(Operation op, int data)        {            if (_oneParaCommandOp.ContainsKey(op))            {                var cmd = string.Format(_oneParaCommandOp[op], data);                return _sendCmd(cmd);            }            _noRepeatAlarm($"Adixen Turbo Pump: The command {op} does not need one parameter");            return false;        }        private bool _sendCmd(string cmd)        {            return _serial.Write(cmd);        }        private void _noRepeatAlarm(string alarm)        {            if (_lastAlarmString != alarm)            {                _lastAlarmString = alarm;                LOG.Write(eEvent.ERR_DEVICE_CHILLER, Module, alarm);            }        }        private void _process_signicate_chiller_status(ushort status)        {            StringBuilder errorInfo = new StringBuilder();            if((status & 0x80) != 0)            {                errorInfo.Append("Memory Data Error Fault; ");            }            if ((status & 0x40) != 0)            {                errorInfo.Append("Controller Error Fault; ");            }            if ((status & 0x20) != 0)            {                errorInfo.Append("Pump Breaker Trip Fault; ");            }            if ((status & 0x10) != 0)            {                errorInfo.Append("Heater Breaker Trip Fault; ");            }            if ((status & 0x08) != 0)            {                errorInfo.Append("Water Leak Fault; ");            }            if ((status & 0x04) != 0)            {                errorInfo.Append("Return Low Flow Fault; ");            }            if ((status & 0x02) != 0)            {                errorInfo.Append("Reservoir High Temperature Fault; ");            }            if ((status & 0x01) != 0)            {                errorInfo.Append("Reservoir Low Level Fault; ");            }            if(errorInfo.Length > 10)            {                IsError = true;                _noRepeatAlarm($"AIRSYS chiller status error:{errorInfo}");            }            else            {                IsError = true;            }        }        private void _process_low_signicate_chiller_status(ushort status)        {            StringBuilder errorInfo = new StringBuilder();            if ((status & 0x80) != 0)            {                errorInfo.Append("Temperature Fuse Fault; ");            }            if ((status & 0x40) != 0)            {                errorInfo.Append("DC Power Fuse Fault; ");            }            if ((status & 0x02) != 0)            {                errorInfo.Append("Reservoir High Temperature Warning; ");            }            if ((status & 0x01) != 0)            {                errorInfo.Append("Reservoir Low Level Warning; ");            }            if (errorInfo.Length > 10)            {                _noRepeatAlarm($"AIRSYS chiller status error:{errorInfo}");            }        }    }}
 |