SMCShareChiller.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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 bool chillerIsOn;
  40. JetChamber jetChamber;
  41. private SMCMutiChillerMessage message;
  42. public SMCChillerState StatusSMC{get; private set;}
  43. public double SetPointLimitMax
  44. {
  45. get
  46. {
  47. return _scSetPointLimitMax; ;
  48. }
  49. }
  50. public double SetPointLimitMin
  51. {
  52. get
  53. {
  54. return _scSetPointLimitMin; ;
  55. }
  56. }
  57. [Subscription(AITChillerProperty.IsRunning)]
  58. public override bool IsRunning
  59. {
  60. get
  61. {
  62. return chillerIsOn;
  63. }
  64. }
  65. [Subscription(AITChillerProperty.IsError)]
  66. public override bool IsError
  67. {
  68. get
  69. {
  70. return StatusSMC == SMCChillerState.ERROR || StatusSMC == SMCChillerState.Disconnected;
  71. }
  72. }
  73. [Subscription(AITChillerProperty.ControlTcSetPoint)]
  74. public float ControlTcSetPoint
  75. {
  76. get
  77. {
  78. return _controlTcSetPoint;
  79. }
  80. }
  81. [Subscription(AITChillerProperty.ControlTcFeedback)]
  82. public float ControlTcFeedback
  83. {
  84. get
  85. {
  86. return _controlTcFeedback;
  87. }
  88. }
  89. [Subscription(AITChillerProperty.CoolantInletTempFeedback)]
  90. public override float CoolantInletTcFeedback
  91. {
  92. get
  93. {
  94. if (jetChamber == JetChamber.VenusSE)
  95. {
  96. return GetAiValue($"{Module}.AI_Coolant_Inlet_Temp");
  97. }
  98. else
  99. {
  100. return 0;
  101. }
  102. }
  103. }
  104. public override float Temperature
  105. {
  106. get
  107. {
  108. return ControlTcFeedback;
  109. }
  110. }
  111. [Subscription(AITChillerProperty.CoolantOutletTempFeedback)]
  112. public override float CoolantOutletTcFeedback
  113. {
  114. get
  115. {
  116. switch (jetChamber)
  117. {
  118. case JetChamber.VenusSE:
  119. return GetAiValue($"{Module}.AI_Coolant_Outlet_Temp");
  120. case JetChamber.VenusDE:
  121. return GetAiValue($"{Module}.AI_ESC_Coolant_Outlet_Temp");
  122. default:
  123. return 0;
  124. }
  125. }
  126. }
  127. public override AITChillerData DeviceData
  128. {
  129. get
  130. {
  131. AITChillerData deviceData = new AITChillerData
  132. {
  133. Module = Module,
  134. DeviceName = Name,
  135. DeviceModule = Module,
  136. DeviceSchematicId = DeviceID,
  137. DisplayName = Display,
  138. IsError = false,
  139. IsWarning = false,
  140. IsPowerOn = IsRunning,
  141. ScaleMax = SetPointLimitMax,
  142. ScaleMin = SetPointLimitMin,
  143. SetPoint = ControlTcSetPoint,
  144. Temperature = Convert.ToInt16(ControlTcSetPoint),
  145. //FeedBack = CoolantOutletTcFeedback,
  146. CoolantInletFeedBack = CoolantInletTcFeedback,
  147. CoolantOutletFeedBack = CoolantOutletTcFeedback,
  148. Unit = "℃",
  149. };
  150. return deviceData;
  151. }
  152. }
  153. public SMCShareChiller(ModuleName mod, string name) : base(mod.ToString(), name, name, "")
  154. {
  155. _address = SC.GetStringValue($"{mod}.{Name}.Address");
  156. _driver = ChillerFactory.QuoteDrive(SC.GetStringValue($"{mod}.{Name}.Port"), _address, $"{mod}.{Name}");
  157. _scSetPointLimitMax = SC.GetValue<double>($"{mod}.{name}.SetPointLimitMax");
  158. _scSetPointLimitMin = SC.GetValue<double>($"{mod}.{name}.SetPointLimitMin");
  159. //_scEnableAlarm = SC.GetConfigItem($"{mod}.{name}.EnableToleranceAlarm");
  160. //_scAlarmRange = SC.GetConfigItem($"{mod}.{name}.ToleranceAlarmRange");
  161. //_scAlarmTime = SC.GetConfigItem($"{mod}.{name}.ToleranceAlarmTime");
  162. jetChamber = (JetChamber)SC.GetValue<int>($"{mod}.ChamberType");
  163. message = new SMCMutiChillerMessage(_address);
  164. _timerQueryStatus.Start(CHK_ST_INTERVAL);
  165. SetAlarmMsg();
  166. }
  167. public override void Monitor()
  168. {
  169. try
  170. {
  171. if (_timerQueryStatus.IsTimeout() && StatusSMC != SMCChillerState.ERROR)
  172. {
  173. _driver.SendCmd(ChillerMsgType.Get,message.GET_ALL);
  174. _timerQueryStatus.Start(CHK_ST_INTERVAL);
  175. }
  176. if (_driver != null && _driver.QueryData(_address) != null)
  177. {
  178. //LOG.Write(eEvent.INFO_DEVICE_CHILLER,Module,$"Address:{_address},");
  179. Statusflag = _driver.QueryData(_address).Statusflag;
  180. Alarmflag = _driver.QueryData(_address).Alarmflag;
  181. _controlTcFeedback = _driver.QueryData(_address).ControlTcFeedback;
  182. }
  183. else
  184. {
  185. LOG.Write(eEvent.WARN_DEVICE_CHILLER,Module,$"Address:{_address},获取的设备为空或值为空");
  186. return;
  187. }
  188. if (Statusflag[0])
  189. {
  190. StatusSMC = SMCChillerState.ON;
  191. chillerIsOn = true;
  192. }
  193. else
  194. {
  195. StatusSMC = SMCChillerState.OFF;
  196. chillerIsOn = false;
  197. }
  198. for (int i = 0; i < 48; i++)
  199. {
  200. if (Alarmflag[i])
  201. StatusSMC = SMCChillerState.ERROR;
  202. if (Alarmflag[i] && !LastAlarmflag[i])//取报警信号上升沿
  203. {
  204. //报警一次
  205. if (NeedToStop[i])
  206. LOG.Write(eEvent.ERR_DEVICE_CHILLER, Module, AlarmMsg[i]);
  207. else
  208. LOG.Write(eEvent.WARN_DEVICE_CHILLER, Module, AlarmMsg[i]);
  209. }
  210. LastAlarmflag[i] = Alarmflag[i];
  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(ChillerMsgType.Set, message.SET_TEMP + isettemp.ToString("X4"));
  226. _controlTcSetPoint = value;
  227. }
  228. public override void SetChillerOnOff(bool on)
  229. {
  230. _driver.SendCmd(ChillerMsgType.Set, on ? message.SET_ON : message.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 static 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. }