SMCShareChiller.cs 14 KB

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