SMCShareChiller.cs 15 KB

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