IoHighTemperatureHeater.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.IOCore;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using MECF.Framework.Common.CommonData.DeviceData;
  9. using System;
  10. using System.Xml;
  11. using Venus_Core;
  12. namespace Venus_RT.Devices.IODevices
  13. {
  14. public class IoHighTemperatureHeater : BaseDevice, IDevice
  15. {
  16. private readonly DIAccessor _diPowerOnFeedback;
  17. private readonly DOAccessor _doPowerOn;
  18. private readonly AIAccessor _aiTemperatureFeedback;
  19. private readonly AOAccessor _aoTemperatureSetPoint;
  20. private readonly DIAccessor _diGoPosition1Feedback;
  21. private readonly DOAccessor _doGoPosition1On;
  22. private readonly DIAccessor _diGoPosition2Feedback;
  23. private readonly DOAccessor _doGoPosition2On;
  24. private readonly DIAccessor _diGoPosition3Feedback;
  25. private readonly DOAccessor _doGoPosition3On;
  26. private readonly DIAccessor _diGoPosition4Feedback;
  27. private readonly DOAccessor _doGoPosition4On;
  28. private readonly DIAccessor _diGoPosition5Feedback;
  29. private readonly DOAccessor _doGoPosition5On;
  30. private readonly DIAccessor _diGoOriginFeedback;
  31. private readonly DOAccessor _doGoOriginOn;
  32. private readonly AOAccessor _aoLiftServoPosition1;
  33. private readonly AOAccessor _aoLiftServoPosition2;
  34. private readonly AOAccessor _aoLiftServoPosition3;
  35. private readonly AOAccessor _aoLiftServoPosition4;
  36. private readonly AOAccessor _aoLiftServoPosition5;
  37. private readonly AOAccessor _aoOriginSearchHighSpeed;
  38. private readonly AOAccessor _aoOriginSearchLowSpeed;
  39. private readonly AOAccessor _aoAbsMoveSpeed;
  40. private readonly AOAccessor _aoMaximusMoveSpeed;
  41. private readonly AOAccessor _aoSoftDownLimit;
  42. private readonly AOAccessor _aoSoftUpLimit;
  43. private readonly AOAccessor _aoRatio;
  44. private readonly DeviceTimer _originTimer = new DeviceTimer();
  45. private readonly DeviceTimer _position1Timer = new DeviceTimer();
  46. private readonly DeviceTimer _position2Timer = new DeviceTimer();
  47. private readonly DeviceTimer _position3Timer = new DeviceTimer();
  48. private readonly DeviceTimer _position4Timer = new DeviceTimer();
  49. private readonly DeviceTimer _position5Timer = new DeviceTimer();
  50. private int _goPositionTime = 60 * 1000;
  51. private AITHighTemperatureHeaterData DeviceData
  52. {
  53. get
  54. {
  55. return new AITHighTemperatureHeaterData
  56. {
  57. Module = Module,
  58. DeviceName = Name,
  59. DisplayName = Display,
  60. HighTemperatureHeaterPosition = CurrentPosition.ToString(),
  61. HighTemperatureHeaterIson = HighTemperatureHeaterIsOn,
  62. HighTemperatureHeaterTemperature = HighTemperatureHighHeaterTemperature,
  63. HighTemperatureHeaterRatio = HighTemperatureHeaterRatio
  64. };
  65. }
  66. }
  67. public HighTemperatureHeaterPosition CurrentPosition
  68. {
  69. get
  70. {
  71. if (_diGoOriginFeedback.Value == true && _diGoPosition1Feedback.Value == false && _diGoPosition2Feedback.Value == false && _diGoPosition3Feedback.Value == false && _diGoPosition4Feedback.Value == false && _diGoPosition5Feedback.Value == false)
  72. {
  73. return HighTemperatureHeaterPosition.Origin;
  74. }
  75. if (_diGoOriginFeedback.Value == false && _diGoPosition1Feedback.Value == true && _diGoPosition2Feedback.Value == false && _diGoPosition3Feedback.Value == false && _diGoPosition4Feedback.Value == false && _diGoPosition5Feedback.Value == false)
  76. {
  77. return HighTemperatureHeaterPosition.Position1;
  78. }
  79. else if (_diGoOriginFeedback.Value == false && _diGoPosition1Feedback.Value == false && _diGoPosition2Feedback.Value == true && _diGoPosition3Feedback.Value == false && _diGoPosition4Feedback.Value == false && _diGoPosition5Feedback.Value == false)
  80. {
  81. return HighTemperatureHeaterPosition.Position2;
  82. }
  83. else if (_diGoOriginFeedback.Value == false && _diGoPosition1Feedback.Value == false && _diGoPosition2Feedback.Value == false && _diGoPosition3Feedback.Value == true && _diGoPosition4Feedback.Value == false && _diGoPosition5Feedback.Value == false)
  84. {
  85. return HighTemperatureHeaterPosition.Position3;
  86. }
  87. else if (_diGoOriginFeedback.Value == false && _diGoPosition1Feedback.Value == false && _diGoPosition2Feedback.Value == false && _diGoPosition3Feedback.Value == false && _diGoPosition4Feedback.Value == true && _diGoPosition5Feedback.Value == false)
  88. {
  89. return HighTemperatureHeaterPosition.Position4;
  90. }
  91. else if (_diGoOriginFeedback.Value == false && _diGoPosition1Feedback.Value == false && _diGoPosition2Feedback.Value == false && _diGoPosition3Feedback.Value == false && _diGoPosition4Feedback.Value == false && _diGoPosition5Feedback.Value == true)
  92. {
  93. return HighTemperatureHeaterPosition.Position5;
  94. }
  95. else
  96. {
  97. return HighTemperatureHeaterPosition.UnKnow;
  98. }
  99. }
  100. }
  101. public bool HighTemperatureHeaterIsOn
  102. {
  103. get
  104. {
  105. if (_diPowerOnFeedback.Value == true && _doPowerOn.Value == true)
  106. {
  107. return true;
  108. }
  109. else
  110. {
  111. return false;
  112. }
  113. }
  114. set
  115. {
  116. _doPowerOn.Value = value;
  117. }
  118. }
  119. public float HighTemperatureHighHeaterTemperature
  120. {
  121. get
  122. {
  123. if (_aiTemperatureFeedback == null) return -1;
  124. return _GetRealFloat(_aiTemperatureFeedback);
  125. }
  126. set
  127. {
  128. _SetRealFloat(_aoTemperatureSetPoint, value);
  129. }
  130. }
  131. public float HighTemperatureHeaterRatio
  132. {
  133. get
  134. {
  135. if (_aoRatio == null) return -1;
  136. return _GetRealFloat(_aoRatio);
  137. }
  138. set
  139. {
  140. _SetRealFloat(_aoRatio, value);
  141. }
  142. }
  143. public IoHighTemperatureHeater(string module, XmlElement node, string ioModule = "")
  144. {
  145. base.Module = module;
  146. base.Name = node.GetAttribute("id");
  147. base.Display = node.GetAttribute("display");
  148. base.DeviceID = node.GetAttribute("schematicId");
  149. _diPowerOnFeedback = ParseDiNode("diPowerOnFeedback", node, ioModule);
  150. _doPowerOn = ParseDoNode("doPowerOn", node, ioModule);
  151. _aiTemperatureFeedback = ParseAiNode("aiTemperatureFeedback", node, ioModule);
  152. _aoTemperatureSetPoint = ParseAoNode("aoTemperatureSetPoint", node, ioModule);
  153. _diGoPosition1Feedback = ParseDiNode("diGoPosition1Feedback", node, ioModule);
  154. _doGoPosition1On = ParseDoNode("doGoPosition1On", node, ioModule);
  155. _diGoPosition2Feedback = ParseDiNode("diGoPosition2Feedback", node, ioModule);
  156. _doGoPosition2On = ParseDoNode("doGoPosition2On", node, ioModule);
  157. _diGoPosition3Feedback = ParseDiNode("diGoPosition3Feedback", node, ioModule);
  158. _doGoPosition3On = ParseDoNode("doGoPosition3On", node, ioModule);
  159. _diGoPosition4Feedback = ParseDiNode("diGoPosition4Feedback", node, ioModule);
  160. _doGoPosition4On = ParseDoNode("doGoPosition4On", node, ioModule);
  161. _diGoPosition5Feedback = ParseDiNode("diGoPosition5Feedback", node, ioModule);
  162. _doGoPosition5On = ParseDoNode("doGoPosition5On", node, ioModule);
  163. _diGoOriginFeedback = ParseDiNode("diGoOriginFeedback", node, ioModule);
  164. _doGoOriginOn = ParseDoNode("doGoOriginOn", node, ioModule);
  165. _aoLiftServoPosition1 = ParseAoNode("aoLiftServoPosition1", node, ioModule);
  166. _aoLiftServoPosition2 = ParseAoNode("aoLiftServoPosition2", node, ioModule);
  167. _aoLiftServoPosition3 = ParseAoNode("aoLiftServoPosition3", node, ioModule);
  168. _aoLiftServoPosition4 = ParseAoNode("aoLiftServoPosition4", node, ioModule);
  169. _aoLiftServoPosition5 = ParseAoNode("aoLiftServoPosition5", node, ioModule);
  170. _aoOriginSearchHighSpeed = ParseAoNode("aoOriginSearchHighSpeed", node, ioModule);
  171. _aoOriginSearchLowSpeed = ParseAoNode("aoOriginSearchLowSpeed", node, ioModule);
  172. _aoAbsMoveSpeed = ParseAoNode("aoAbsMoveSpeed", node, ioModule);
  173. _aoMaximusMoveSpeed = ParseAoNode("aoMaximusMoveSpeed", node, ioModule);
  174. _aoSoftDownLimit = ParseAoNode("aoSoftDownLimit", node, ioModule);
  175. _aoSoftUpLimit = ParseAoNode("aoSoftUpLimit", node, ioModule);
  176. _aoRatio= ParseAoNode("aoRatio", node, ioModule);
  177. }
  178. public bool GotoPosition(HighTemperatureHeaterPosition highTemperatureHeaterPosition)
  179. {
  180. if (CurrentPosition == highTemperatureHeaterPosition)
  181. {
  182. return true;
  183. }
  184. switch (highTemperatureHeaterPosition)
  185. {
  186. case HighTemperatureHeaterPosition.Origin:
  187. _doGoOriginOn.Value = true;
  188. _originTimer.Start(_goPositionTime);
  189. break;
  190. case HighTemperatureHeaterPosition.Position1:
  191. _doGoPosition1On.Value = true;
  192. _position1Timer.Start(_goPositionTime);
  193. break;
  194. case HighTemperatureHeaterPosition.Position2:
  195. _doGoPosition2On.Value = true;
  196. _position2Timer.Start(_goPositionTime);
  197. break;
  198. case HighTemperatureHeaterPosition.Position3:
  199. _doGoPosition3On.Value = true;
  200. _position3Timer.Start(_goPositionTime);
  201. break;
  202. case HighTemperatureHeaterPosition.Position4:
  203. _doGoPosition4On.Value = true;
  204. _position4Timer.Start(_goPositionTime);
  205. break;
  206. case HighTemperatureHeaterPosition.Position5:
  207. _doGoPosition5On.Value = true;
  208. _position5Timer.Start(_goPositionTime);
  209. break;
  210. }
  211. return true;
  212. }
  213. public bool Initialize()
  214. {
  215. OP.Subscribe($"{Module}.{Name}.GotoPosition", (cmd, args) =>
  216. {
  217. var currentPosition = (HighTemperatureHeaterPosition)Enum.Parse(typeof(HighTemperatureHeaterPosition), args[0].ToString());
  218. GotoPosition(currentPosition);
  219. return true;
  220. });
  221. OP.Subscribe($"{Module}.{Name}.SwitchHighTemperatureHeater", (cmd, args) =>
  222. {
  223. HighTemperatureHeaterIsOn = Convert.ToBoolean(args[0].ToString());
  224. return true;
  225. });
  226. OP.Subscribe($"{Module}.{Name}.SetHighTemperatureHeaterTemperature", (cmd, args) =>
  227. {
  228. HighTemperatureHighHeaterTemperature = Convert.ToSingle(args[0]);
  229. return true;
  230. });
  231. OP.Subscribe($"{Module}.{Name}.SetHighTemperatureHeaterRatio", (cmd, args) =>
  232. {
  233. HighTemperatureHeaterRatio = Convert.ToSingle(args[0]);
  234. return true;
  235. });
  236. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData,SubscriptionAttribute.FLAG.IgnoreSaveDB);
  237. DATA.Subscribe($"{Module}.{Name}.Temperature", () => DeviceData.HighTemperatureHeaterTemperature);
  238. DATA.Subscribe($"{Module}.{Name}.Position", () => (int)CurrentPosition-1);
  239. _SetRealFloat(_aoLiftServoPosition1, 20);
  240. _SetRealFloat(_aoLiftServoPosition2, -30);
  241. _SetRealFloat(_aoLiftServoPosition3, -40);
  242. _SetRealFloat(_aoLiftServoPosition4, 20);
  243. _SetRealFloat(_aoLiftServoPosition5, 50);
  244. _SetRealFloat(_aoOriginSearchHighSpeed, 10);
  245. _SetRealFloat(_aoOriginSearchLowSpeed, 5);
  246. _SetRealFloat(_aoAbsMoveSpeed, 10);
  247. _SetRealFloat(_aoMaximusMoveSpeed, 20);
  248. _SetRealFloat(_aoSoftDownLimit, 100);
  249. _SetRealFloat(_aoSoftUpLimit, 300);
  250. return true;
  251. }
  252. public void Stop()
  253. {
  254. }
  255. public void Terminate()
  256. {
  257. }
  258. public void Monitor()
  259. {
  260. if (_originTimer.IsTimeout())
  261. {
  262. _originTimer.Stop();
  263. if (_diGoOriginFeedback.Value == false)
  264. {
  265. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime / 1000} s 内未到原点");
  266. }
  267. }
  268. else if (_originTimer.IsIdle() == false)
  269. {
  270. if (_diGoOriginFeedback.Value == true)
  271. {
  272. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} to Origin");
  273. _doGoOriginOn.Value = false;
  274. _originTimer.Stop();
  275. }
  276. }
  277. if (_position1Timer.IsTimeout())
  278. {
  279. _position1Timer.Stop();
  280. if (_diGoPosition1Feedback.Value == false)
  281. {
  282. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime / 1000} s 内未到Position1");
  283. }
  284. }
  285. else if (_position1Timer.IsIdle() == false)
  286. {
  287. if (_diGoPosition1Feedback.Value == true)
  288. {
  289. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} to Position1");
  290. _doGoPosition1On.Value = false;
  291. _position1Timer.Stop();
  292. }
  293. }
  294. if (_position2Timer.IsTimeout())
  295. {
  296. _position2Timer.Stop();
  297. if (_diGoPosition2Feedback.Value == false)
  298. {
  299. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime / 1000} s 内未到Position2");
  300. }
  301. }
  302. else if (_position2Timer.IsIdle() == false)
  303. {
  304. if (_diGoPosition2Feedback.Value == true)
  305. {
  306. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} to Position2");
  307. _doGoPosition2On.Value = false;
  308. _position2Timer.Stop();
  309. }
  310. }
  311. if (_position3Timer.IsTimeout())
  312. {
  313. _position3Timer.Stop();
  314. if (_diGoPosition3Feedback.Value == false)
  315. {
  316. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime / 1000} s 内未到Position3");
  317. }
  318. }
  319. else if (_position3Timer.IsIdle() == false)
  320. {
  321. if (_diGoPosition3Feedback.Value == true)
  322. {
  323. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} to Position3");
  324. _doGoPosition3On.Value = false;
  325. _position3Timer.Stop();
  326. }
  327. }
  328. if (_position4Timer.IsTimeout())
  329. {
  330. _position4Timer.Stop();
  331. if (_diGoPosition4Feedback.Value == false)
  332. {
  333. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime / 1000} s 内未到Position4");
  334. }
  335. }
  336. else if (_position4Timer.IsIdle() == false)
  337. {
  338. if (_diGoPosition4Feedback.Value == true)
  339. {
  340. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} to Position4");
  341. _doGoPosition4On.Value = false;
  342. _position4Timer.Stop();
  343. }
  344. }
  345. if (_position5Timer.IsTimeout())
  346. {
  347. _position5Timer.Stop();
  348. if (_diGoPosition5Feedback.Value == false)
  349. {
  350. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime / 1000} s 内未到Position5");
  351. }
  352. }
  353. else if (_position5Timer.IsIdle() == false)
  354. {
  355. if (_diGoPosition5Feedback.Value == true)
  356. {
  357. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} to Position5");
  358. _doGoPosition5On.Value = false;
  359. _position5Timer.Stop();
  360. }
  361. }
  362. _SetRealFloat(_aoLiftServoPosition1, (float)SC.GetValue<double>($"{Module}.HighTemperatureChiller.LiftServoPosition1"));
  363. _SetRealFloat(_aoLiftServoPosition2, (float)SC.GetValue<double>($"{Module}.HighTemperatureChiller.LiftServoPosition2"));
  364. _SetRealFloat(_aoLiftServoPosition3, (float)SC.GetValue<double>($"{Module}.HighTemperatureChiller.LiftServoPosition3"));
  365. _SetRealFloat(_aoLiftServoPosition4, (float)SC.GetValue<double>($"{Module}.HighTemperatureChiller.LiftServoPosition4"));
  366. _SetRealFloat(_aoLiftServoPosition5, (float)SC.GetValue<double>($"{Module}.HighTemperatureChiller.LiftServoPosition5"));
  367. _SetRealFloat(_aoOriginSearchHighSpeed, (float)SC.GetValue<double>($"{Module}.HighTemperatureChiller.OriginSearchHighSpeed"));
  368. _SetRealFloat(_aoOriginSearchLowSpeed, (float)SC.GetValue<double>($"{Module}.HighTemperatureChiller.OriginSearchLowSpeed"));
  369. _SetRealFloat(_aoAbsMoveSpeed, (float)SC.GetValue<double>($"{Module}.HighTemperatureChiller.AbsMoveSpeed"));
  370. _SetRealFloat(_aoMaximusMoveSpeed, (float)SC.GetValue<double>($"{Module}.HighTemperatureChiller.MaximusMoveSpeed"));
  371. _SetRealFloat(_aoSoftDownLimit, (float)SC.GetValue<double>($"{Module}.HighTemperatureChiller.SoftDownLimit"));
  372. _SetRealFloat(_aoSoftUpLimit, (float)SC.GetValue<double>($"{Module}.HighTemperatureChiller.SoftUpLimit"));
  373. }
  374. public void Reset()
  375. {
  376. }
  377. }
  378. }