IoHighTemperatureHeater.cs 17 KB

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