SMCShareChiller.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.RT.Tolerance;
  5. using Aitex.Core.Util;
  6. using MECF.Framework.Common.Device.Bases;
  7. using MECF.Framework.Common.Equipment;
  8. using System;
  9. using System.Collections.Concurrent;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using System.Linq;
  13. using System.ServiceModel.Channels;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using Venus_Core;
  17. using static Mono.Security.X509.X520;
  18. namespace Venus_RT.Devices
  19. {
  20. public class SMCShareChiller : ChillerBase
  21. {
  22. private SMCChillerDrive _driver;
  23. private string _address;
  24. private readonly DeviceTimer _timerQueryStatus = new DeviceTimer();
  25. private const ushort CHK_ST_INTERVAL = 1000;
  26. bool[] Statusflag = new bool[32];
  27. bool[] LastStatusflag = new bool[32];
  28. bool[] Alarmflag = new bool[48];
  29. bool[] LastAlarmflag = new bool[48];
  30. string[] AlarmMsg = new string[48];
  31. bool[] NeedToStop = new bool[48];
  32. //private ToleranceChecker _toleranceChecker = new ToleranceChecker();
  33. private float _controlTcSetPoint;
  34. private float _controlTcFeedback;
  35. private readonly double _scSetPointLimitMax;
  36. private readonly double _scSetPointLimitMin;
  37. private SCConfigItem _scAlarmRange;
  38. private SCConfigItem _scEnableAlarm;
  39. private SCConfigItem _scAlarmTime;
  40. private ToleranceChecker _toleranceChecker = new ToleranceChecker();
  41. private bool chillerIsOn;
  42. JetChamber jetChamber;
  43. private SMCMutiChillerMessage message;
  44. public SMCChillerState StatusSMC { get; private set; }
  45. public double SetPointLimitMax
  46. {
  47. get
  48. {
  49. return _scSetPointLimitMax; ;
  50. }
  51. }
  52. public double SetPointLimitMin
  53. {
  54. get
  55. {
  56. return _scSetPointLimitMin; ;
  57. }
  58. }
  59. [Subscription(AITChillerProperty.IsRunning)]
  60. public override bool IsRunning
  61. {
  62. get
  63. {
  64. return chillerIsOn;
  65. }
  66. }
  67. [Subscription(AITChillerProperty.IsError)]
  68. public override bool IsError
  69. {
  70. get
  71. {
  72. return StatusSMC == SMCChillerState.ERROR || StatusSMC == SMCChillerState.Disconnected;
  73. }
  74. }
  75. [Subscription(AITChillerProperty.ControlTcSetPoint)]
  76. public float ControlTcSetPoint
  77. {
  78. get
  79. {
  80. return _controlTcSetPoint;
  81. }
  82. }
  83. //[Subscription(AITChillerProperty.ControlTcFeedback)]
  84. //public float ControlTcFeedback
  85. //{
  86. // get
  87. // {
  88. // return _controlTcFeedback;
  89. // }
  90. //}
  91. [Subscription(AITChillerProperty.CoolantInletTempFeedback)]
  92. public override float CoolantInletTcFeedback
  93. {
  94. get
  95. {
  96. if (jetChamber == JetChamber.VenusSE)
  97. {
  98. return GetAiValue($"{Module}.AI_Coolant_Inlet_Temp");
  99. }
  100. else
  101. {
  102. return 0;
  103. }
  104. }
  105. }
  106. public override float Temperature
  107. {
  108. get
  109. {
  110. return ControlTcFeedback;
  111. }
  112. }
  113. [Subscription(AITChillerProperty.CoolantOutletTempFeedback)]
  114. public override float CoolantOutletTcFeedback
  115. {
  116. get
  117. {
  118. switch (jetChamber)
  119. {
  120. case JetChamber.VenusSE:
  121. return GetAiValue($"{Module}.AI_Coolant_Outlet_Temp");
  122. case JetChamber.VenusDE:
  123. return GetAiValue($"{Module}.AI_ESC_Coolant_Outlet_Temp");
  124. default:
  125. return 0;
  126. }
  127. }
  128. }
  129. public override AITChillerData DeviceData
  130. {
  131. get
  132. {
  133. AITChillerData deviceData = new AITChillerData
  134. {
  135. Module = Module,
  136. DeviceName = Name,
  137. DeviceModule = Module,
  138. DeviceSchematicId = DeviceID,
  139. DisplayName = Display,
  140. IsError = false,
  141. IsWarning = false,
  142. IsPowerOn = IsRunning,
  143. ScaleMax = SetPointLimitMax,
  144. ScaleMin = SetPointLimitMin,
  145. SetPoint = ControlTcSetPoint,
  146. Temperature = Convert.ToInt16(ControlTcSetPoint),
  147. //FeedBack = CoolantOutletTcFeedback,
  148. CoolantInletFeedBack = CoolantInletTcFeedback,
  149. CoolantOutletFeedBack = CoolantOutletTcFeedback,
  150. Unit = "℃",
  151. };
  152. return deviceData;
  153. }
  154. }
  155. public SMCShareChiller(ModuleName mod, string name) : base(mod.ToString(), name, name, "")
  156. {
  157. _address = SC.GetStringValue($"{mod}.{Name}.Address");
  158. _driver = ChillerFactory.QuoteDrive(SC.GetStringValue($"{mod}.{Name}.Port"), _address, $"{mod}.{Name}");
  159. _scSetPointLimitMax = SC.GetValue<double>($"{mod}.{name}.SetPointLimitMax");
  160. _scSetPointLimitMin = SC.GetValue<double>($"{mod}.{name}.SetPointLimitMin");
  161. _scEnableAlarm = SC.GetConfigItem($"{mod}.{name}.EnableToleranceAlarm");
  162. _scAlarmRange = SC.GetConfigItem($"{mod}.{name}.ToleranceAlarmRange");
  163. _scAlarmTime = SC.GetConfigItem($"{mod}.{name}.ToleranceAlarmTime");
  164. jetChamber = (JetChamber)SC.GetValue<int>($"{mod}.ChamberType");
  165. message = new SMCMutiChillerMessage(_address);
  166. _timerQueryStatus.Start(CHK_ST_INTERVAL);
  167. SetAlarmMsg();
  168. }
  169. public override void Monitor()
  170. {
  171. try
  172. {
  173. if (_timerQueryStatus.IsTimeout() && StatusSMC != SMCChillerState.ERROR)
  174. {
  175. _driver.SendCmd(ChillerMsgType.Get, message.GET_ALL);
  176. _timerQueryStatus.Start(CHK_ST_INTERVAL);
  177. }
  178. if (_driver != null && _driver.QueryData(_address) != null)
  179. {
  180. //LOG.Write(eEvent.INFO_DEVICE_CHILLER,Module,$"Address:{_address},");
  181. Statusflag = _driver.QueryData(_address).Statusflag;
  182. Alarmflag = _driver.QueryData(_address).Alarmflag;
  183. _controlTcFeedback = _driver.QueryData(_address).ControlTcFeedback;
  184. }
  185. else
  186. {
  187. LOG.Write(eEvent.WARN_DEVICE_CHILLER, Module, $"Address:{_address},获取的设备为空或值为空");
  188. return;
  189. }
  190. if (Statusflag[0])
  191. {
  192. StatusSMC = SMCChillerState.ON;
  193. chillerIsOn = true;
  194. }
  195. else
  196. {
  197. StatusSMC = SMCChillerState.OFF;
  198. chillerIsOn = false;
  199. }
  200. for (int i = 0; i < 48; i++)
  201. {
  202. if (Alarmflag[i])
  203. StatusSMC = SMCChillerState.ERROR;
  204. if (Alarmflag[i] && !LastAlarmflag[i])//取报警信号上升沿
  205. {
  206. //报警一次
  207. if (NeedToStop[i])
  208. LOG.Write(eEvent.ERR_DEVICE_CHILLER, Module, AlarmMsg[i]);
  209. else
  210. LOG.Write(eEvent.WARN_DEVICE_CHILLER, Module, AlarmMsg[i]);
  211. }
  212. LastAlarmflag[i] = Alarmflag[i];
  213. }
  214. if (IsRunning && _scEnableAlarm != null && _scEnableAlarm.BoolValue)
  215. {
  216. var range = SC.GetValue<double>($"{Module}.{Name}.ToleranceAlarmRange");
  217. var lastTemp = SC.GetValue<double>($"{Module}.{Name}.LastTemp");
  218. var time = _scAlarmTime.IntValue;
  219. _toleranceChecker.Monitor(_controlTcFeedback, lastTemp - Math.Abs(range), lastTemp + Math.Abs(range), time);
  220. if (_toleranceChecker.Trig)
  221. {
  222. LOG.Write(eEvent.ERR_DEVICE_CHILLER, Module, Display + $" temperature out of tolerance in {time:0} seconds, " +
  223. $"temperature:{_controlTcFeedback}, range in {lastTemp - Math.Abs(range)}-{lastTemp + Math.Abs(range)}");
  224. }
  225. }
  226. else
  227. {
  228. _toleranceChecker.Reset(_scAlarmTime.IntValue);
  229. _toleranceChecker.RST = true;
  230. }
  231. }
  232. catch (Exception ex)
  233. {
  234. LOG.Write(eEvent.ERR_DEVICE_CHILLER, Module, ex.ToString());
  235. }
  236. }
  237. public override void Reset()
  238. {
  239. //_toleranceChecker.RST = true;
  240. }
  241. public override void SetChillerTemp(float value, float offset)
  242. {
  243. int isettemp = Convert.ToInt16((value - offset) * 10);
  244. if (isettemp >= 0)
  245. _driver.SendCmd(ChillerMsgType.Set, message.SET_TEMP + isettemp.ToString("X4"));
  246. else
  247. _driver.SendCmd(ChillerMsgType.Set, message.SET_TEMP + isettemp.ToString("X4").Substring(4, 4));
  248. _controlTcSetPoint = value;
  249. }
  250. public override void SetChillerOnOff(bool on)
  251. {
  252. _driver.SendCmd(ChillerMsgType.Set, on ? message.SET_ON : message.SET_OFF);
  253. }
  254. private void SetAlarmMsg()
  255. {
  256. AlarmMsg[0] = "Low level in tank";
  257. AlarmMsg[1] = "High circulating fluid discharge temp";
  258. AlarmMsg[2] = "Circulating fluid discharge temp. rise";
  259. AlarmMsg[3] = "Circulating fluid discharge temp.";
  260. AlarmMsg[4] = "High circulating fluid return temp.";
  261. AlarmMsg[5] = "High circulating fluid discharge pressure";
  262. AlarmMsg[6] = "Abnormal pump operation";
  263. AlarmMsg[7] = "Circulating fluid discharge pressure rise";
  264. AlarmMsg[8] = "Circulating fluid discharge pressure drop";
  265. AlarmMsg[9] = "High compressor intake temp.";
  266. AlarmMsg[10] = "Low compressor intake temp.";
  267. AlarmMsg[11] = "Low super heat temperature";
  268. AlarmMsg[12] = "High compressor discharge pressure";
  269. //AlarmMsg[13] Unused
  270. AlarmMsg[14] = "Refrigerant circuit pressure (high pressure side) drop";
  271. AlarmMsg[15] = "Refrigerant circuit pressure (low pressure side) rise";
  272. AlarmMsg[16] = "Refrigerant circuit pressure (low pressure side) drop";
  273. AlarmMsg[17] = "Compressor overload";
  274. AlarmMsg[18] = "Communication error";
  275. AlarmMsg[19] = "Memory error";
  276. AlarmMsg[20] = "DC line fuse cut";
  277. AlarmMsg[21] = "Circulating fluid discharge temp. sensor failure";
  278. AlarmMsg[22] = "Circulating fluid return temp. sensor failure";
  279. AlarmMsg[23] = "Compressor intake temp. sensor failure";
  280. AlarmMsg[24] = "Circulating fluid discharge pressure sensor failure";
  281. AlarmMsg[25] = "Compressor discharge pressure sensor failure";
  282. AlarmMsg[26] = "Compressor intake pressure sensor failure";
  283. AlarmMsg[27] = "Maintenance of pump";
  284. AlarmMsg[28] = "Maintenance of fan motor";
  285. AlarmMsg[29] = "Maintenance of compressor";
  286. AlarmMsg[30] = "Contact input 1 signal detection alarm";
  287. AlarmMsg[31] = "Contact input 2 signal detection alarm";
  288. AlarmMsg[32] = "Water leakage";
  289. AlarmMsg[33] = "Electric resistivity/conductivity level rise";
  290. AlarmMsg[34] = "Electric resistivity/conductivity level drop";
  291. AlarmMsg[35] = "Electric resistivity/conductivity sensor error";
  292. //AlarmMsg[36] Unused
  293. NeedToStop[0] = true;
  294. NeedToStop[1] = true;
  295. NeedToStop[4] = true;
  296. NeedToStop[5] = true;
  297. NeedToStop[6] = true;
  298. NeedToStop[9] = true;
  299. NeedToStop[10] = true;
  300. NeedToStop[11] = true;
  301. NeedToStop[12] = true;
  302. NeedToStop[14] = true;
  303. NeedToStop[15] = true;
  304. NeedToStop[16] = true;
  305. NeedToStop[17] = true;
  306. NeedToStop[19] = true;
  307. NeedToStop[20] = true;
  308. NeedToStop[21] = true;
  309. NeedToStop[22] = true;
  310. NeedToStop[23] = true;
  311. NeedToStop[24] = true;
  312. NeedToStop[25] = true;
  313. NeedToStop[26] = true;
  314. NeedToStop[30] = true;
  315. NeedToStop[31] = true;
  316. NeedToStop[32] = true;
  317. }
  318. }
  319. public class SMCMutiChillerMessage
  320. {
  321. public string Start = ":";
  322. public string End = "\r\n";
  323. public string SlaveAddress = "00";
  324. public string Function_R_M = "03";
  325. public string Function_W_S = "06";
  326. public string Function_W_M = "10";
  327. public string Function_RW_M = "17";
  328. public string Data_Address_GetTemp = "0000";
  329. public string Data_Address_GetPress = "0002";
  330. public string Data_Address_GetElec = "0003";
  331. public string Data_Address_Status1 = "0004";
  332. public string Data_Address_Alarm1 = "0005";
  333. public string Data_Address_Alarm2 = "0006";
  334. public string Data_Address_Alarm3 = "0007";
  335. public string Data_Address_Status2 = "0009";
  336. public string Data_Address_SetTemp = "000B";
  337. public string Data_Address_SetRun = "000C";
  338. public string SET_ON => SlaveAddress + Function_W_S + Data_Address_SetRun + "0001";
  339. public string SET_OFF => SlaveAddress + Function_W_S + Data_Address_SetRun + "0000";
  340. public string SET_TEMP => SlaveAddress + Function_W_S + Data_Address_SetTemp;
  341. public string GET_ALL => SlaveAddress + Function_R_M + Data_Address_GetTemp + "000B";
  342. public SMCMutiChillerMessage(string SlaveAddress)
  343. {
  344. this.SlaveAddress = SlaveAddress;
  345. }
  346. }
  347. public static class ChillerFactory
  348. {
  349. private static Dictionary<string, SMCChillerDrive> port2share = new Dictionary<string, SMCChillerDrive>();
  350. public static SMCChillerDrive QuoteDrive(string portname, string address, string chillertype)
  351. {
  352. if (port2share.ContainsKey(portname))
  353. {
  354. port2share[portname].AddAddress(address, chillertype);
  355. return port2share[portname];
  356. }
  357. else
  358. {
  359. //不包含该参数
  360. SMCChillerDrive sMCChillerDrive = new SMCChillerDrive(portname);
  361. port2share.Add(portname, sMCChillerDrive);
  362. sMCChillerDrive.AddAddress(address, chillertype);
  363. return sMCChillerDrive;
  364. }
  365. }
  366. }
  367. }