using System; using System.Threading; using MECF.Framework.Simulator.Core.Driver; using Venus_Simulator.Instances; using Aitex.Core.RT.SCCore; using MECF.Framework.Common.SCCore; using MECF.Framework.Common.DataCenter; using Aitex.Core.Util; using System.IO; namespace Venus_Simulator.Devices { class SMCChillerMock : SerialPortDeviceSimulator { public enum SMCChillerStatus { Open, Close, } public static SMCChillerStatus _simPumpStatus; private const string EOF = "\r\n"; private const char MSG_DELIMITER = ' '; //private const string MOCKUP_PORT = "COM43"; public SMCChillerMock(string port) : base(port, -1, EOF, MSG_DELIMITER) { _simPumpStatus = SMCChillerStatus.Close; } protected override void ProcessUnsplitMessage(string message) { if (string.IsNullOrEmpty(message)) throw new ArgumentException("Hardware command message is invalid"); string[] separatingStrings = { EOF }; string[] msgs = message.Trim().Split(separatingStrings, System.StringSplitOptions.RemoveEmptyEntries); foreach (var msg in msgs) { if(msg.StartsWith(":0106000B")) { int temp = Convert.ToInt32(msg.Substring(9, 8), 16); Console.WriteLine($"Chiller Set Temp: {temp}"); SetTemp(temp); } else if(msg.StartsWith(":0106000C0001")) { _simPumpStatus = SMCChillerStatus.Open; } else if(msg.StartsWith(":0106000C0000")) { _simPumpStatus = SMCChillerStatus.Close; } } } void SetTemp(int temp) { //Singleton.Instance.Initialize(PathManager.GetCfgDir() + "System.sccfg"); string module = PortName == "COM43" ? "PMA" : "PMB"; //double _OffsetTemp = SC.GetValue($"{module}.Chiller.ChillerTemperatureOffset"); double _OffsetTemp = SystemConfig.Instance.GetValue($"{module}.Chiller.ChillerTemperatureOffset"); //double offset = (double)QueryDataClient.Instance.Service.GetConfig($"{module}.Chiller.ChillerTemperatureOffset"); SimulatorSystem.Instance.SetCoolantOutletTemp(module, temp / 10 + (int)_OffsetTemp); } } }