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