IoHighTemperatureHeater.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.IOCore;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.Util;
  8. using MECF.Framework.Common.CommonData.DeviceData;
  9. using MECF.Framework.Common.Equipment;
  10. using System;
  11. using System.Xml;
  12. using Venus_Core;
  13. namespace Venus_RT.Devices.IODevices
  14. {
  15. public class IoHighTemperatureHeater : BaseDevice, IDevice
  16. {
  17. private readonly DIAccessor _diPowerOnFeedback;
  18. private readonly DOAccessor _doPowerOn;
  19. private readonly AIAccessor _aiTemperatureFeedback;
  20. private readonly AOAccessor _aoTemperatureSetPoint;
  21. private readonly DIAccessor _diGoPosition1Feedback;
  22. private readonly DOAccessor _doGoPosition1On;
  23. private readonly DIAccessor _diGoPosition2Feedback;
  24. private readonly DOAccessor _doGoPosition2On;
  25. private readonly DIAccessor _diGoPosition3Feedback;
  26. private readonly DOAccessor _doGoPosition3On;
  27. private readonly DIAccessor _diGoOriginFeedback;
  28. private readonly DOAccessor _doGoOriginOn;
  29. private readonly DeviceTimer _originTimer = new DeviceTimer();
  30. private readonly DeviceTimer _position1Timer = new DeviceTimer();
  31. private readonly DeviceTimer _position2Timer = new DeviceTimer();
  32. private readonly DeviceTimer _position3Timer = new DeviceTimer();
  33. private int _goPositionTime = 5 * 1000;
  34. private AITHighTemperatureHeaterData DeviceData
  35. {
  36. get
  37. {
  38. return new AITHighTemperatureHeaterData
  39. {
  40. Module = Module,
  41. DeviceName = Name,
  42. DisplayName = Display,
  43. HighTemperatureHeaterPosition = CurrentPosition.ToString(),
  44. HighTemperatureHeaterIson = HighTemperatureHeaterIsOn,
  45. HighTemperatureHeaterTemperature = HighTemperatureHighHeaterTemperature
  46. };
  47. }
  48. }
  49. public HighTemperatureHeaterPosition CurrentPosition
  50. {
  51. get
  52. {
  53. if (_diGoOriginFeedback.Value == true && _diGoPosition1Feedback.Value == false && _diGoPosition2Feedback.Value == false && _diGoPosition3Feedback.Value == false)
  54. {
  55. return HighTemperatureHeaterPosition.Origin;
  56. }
  57. else if (_diGoOriginFeedback.Value == false && _diGoPosition1Feedback.Value == true && _diGoPosition2Feedback.Value == false && _diGoPosition3Feedback.Value == false)
  58. {
  59. return HighTemperatureHeaterPosition.Position1;
  60. }
  61. else if (_diGoOriginFeedback.Value == false && _diGoPosition1Feedback.Value == false && _diGoPosition2Feedback.Value == true && _diGoPosition3Feedback.Value == false)
  62. {
  63. return HighTemperatureHeaterPosition.Position2;
  64. }
  65. else if (_diGoOriginFeedback.Value == false && _diGoPosition1Feedback.Value == false && _diGoPosition2Feedback.Value == false && _diGoPosition3Feedback.Value == true)
  66. {
  67. return HighTemperatureHeaterPosition.Position3;
  68. }
  69. else
  70. {
  71. return HighTemperatureHeaterPosition.Error;
  72. }
  73. }
  74. }
  75. public bool HighTemperatureHeaterIsOn
  76. {
  77. get
  78. {
  79. if (_diPowerOnFeedback.Value == true && _doPowerOn.Value == true)
  80. {
  81. return true;
  82. }
  83. else
  84. {
  85. return false;
  86. }
  87. }
  88. set
  89. {
  90. _doPowerOn.Value = value;
  91. }
  92. }
  93. public float HighTemperatureHighHeaterTemperature
  94. {
  95. get
  96. {
  97. if (_aiTemperatureFeedback == null) return -1;
  98. //return _aiMonitorTcFeedback.Value;
  99. return _GetRealFloat(_aiTemperatureFeedback);
  100. }
  101. set
  102. {
  103. _SetRealFloat(_aoTemperatureSetPoint, value);
  104. }
  105. }
  106. public IoHighTemperatureHeater(string module, XmlElement node, string ioModule = "")
  107. {
  108. base.Module = module;
  109. base.Name = node.GetAttribute("id");
  110. base.Display = node.GetAttribute("display");
  111. base.DeviceID = node.GetAttribute("schematicId");
  112. _diPowerOnFeedback = ParseDiNode("diPowerOnFeedback", node, ioModule);
  113. _doPowerOn = ParseDoNode("doPowerOn", node, ioModule);
  114. _aiTemperatureFeedback = ParseAiNode("aiTemperatureFeedback", node, ioModule);
  115. _aoTemperatureSetPoint = ParseAoNode("aoTemperatureSetPoint", node, ioModule);
  116. _diGoPosition1Feedback = ParseDiNode("diGoPosition1Feedback", node, ioModule);
  117. _doGoPosition1On = ParseDoNode("doGoPosition1On", node, ioModule);
  118. _diGoPosition2Feedback = ParseDiNode("diGoPosition2Feedback", node, ioModule);
  119. _doGoPosition2On = ParseDoNode("doGoPosition2On", node, ioModule);
  120. _diGoPosition3Feedback = ParseDiNode("diGoPosition3Feedback", node, ioModule);
  121. _doGoPosition3On = ParseDoNode("doGoPosition3On", node, ioModule);
  122. _diGoOriginFeedback = ParseDiNode("diGoOriginFeedback", node, ioModule);
  123. _doGoOriginOn = ParseDoNode("doGoOriginOn", node, ioModule);
  124. }
  125. public bool GotoPosition(HighTemperatureHeaterPosition highTemperatureHeaterPosition)
  126. {
  127. if (CurrentPosition == highTemperatureHeaterPosition)
  128. {
  129. return true;
  130. }
  131. switch (highTemperatureHeaterPosition)
  132. {
  133. case HighTemperatureHeaterPosition.Origin:
  134. _doGoOriginOn.Value = true;
  135. _originTimer.Start(_goPositionTime);
  136. break;
  137. case HighTemperatureHeaterPosition.Position1:
  138. _doGoPosition1On.Value = true;
  139. _position1Timer.Start(_goPositionTime);
  140. break;
  141. case HighTemperatureHeaterPosition.Position2:
  142. _doGoPosition2On.Value = true;
  143. _position2Timer.Start(_goPositionTime);
  144. break;
  145. case HighTemperatureHeaterPosition.Position3:
  146. _doGoPosition3On.Value = true;
  147. _position3Timer.Start(_goPositionTime);
  148. break;
  149. }
  150. return true;
  151. }
  152. public bool Initialize()
  153. {
  154. OP.Subscribe($"{Module}.{Name}.GotoPosition", (cmd, args) => {
  155. var currentPosition = (HighTemperatureHeaterPosition)Enum.Parse(typeof(HighTemperatureHeaterPosition), args[0].ToString());
  156. GotoPosition(currentPosition);
  157. return true;
  158. });
  159. OP.Subscribe($"{Module}.{Name}.SwitchHighTemperatureHeater", (cmd, args) => {
  160. HighTemperatureHeaterIsOn = Convert.ToBoolean(args[0].ToString());
  161. return true;
  162. });
  163. OP.Subscribe($"{Module}.{Name}.SetHighTemperatureHeaterTemperature", (cmd, args) => {
  164. HighTemperatureHighHeaterTemperature = Convert.ToSingle( args[0]);
  165. return true;
  166. });
  167. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  168. return true;
  169. }
  170. public void Stop()
  171. {
  172. }
  173. public void Terminate()
  174. {
  175. }
  176. public void Monitor()
  177. {
  178. if (_originTimer.IsTimeout())
  179. {
  180. _originTimer.Stop();
  181. if (_diGoOriginFeedback.Value == false)
  182. {
  183. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime/1000} s 内未到原点");
  184. }
  185. }
  186. else if (_originTimer.IsIdle()==false)
  187. {
  188. if (_diGoOriginFeedback.Value == true)
  189. {
  190. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} 到 原点");
  191. _doGoOriginOn.Value = false;
  192. _originTimer.Stop();
  193. }
  194. }
  195. if (_position1Timer.IsTimeout())
  196. {
  197. _position1Timer.Stop();
  198. if (_diGoPosition1Feedback.Value == false)
  199. {
  200. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime/1000} s 内未到Position1");
  201. }
  202. }
  203. else if (_position1Timer.IsIdle() == false)
  204. {
  205. if (_diGoPosition1Feedback.Value == true)
  206. {
  207. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} 到 Position1");
  208. _doGoPosition1On.Value = false;
  209. _position1Timer.Stop();
  210. }
  211. }
  212. if (_position2Timer.IsTimeout())
  213. {
  214. _position2Timer.Stop();
  215. if (_diGoPosition2Feedback.Value == false)
  216. {
  217. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime/1000} s 内未到Position2");
  218. }
  219. }
  220. else if (_position2Timer.IsIdle() == false)
  221. {
  222. if (_diGoPosition2Feedback.Value == true)
  223. {
  224. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} 到 Position2");
  225. _doGoPosition2On.Value = false;
  226. _position2Timer.Stop();
  227. }
  228. }
  229. if (_position3Timer.IsTimeout())
  230. {
  231. _position3Timer.Stop();
  232. if (_diGoPosition3Feedback.Value == false)
  233. {
  234. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, $"{Name} {_goPositionTime/1000} s 内未到Position3");
  235. }
  236. }
  237. else if (_position3Timer.IsIdle() == false)
  238. {
  239. if (_diGoPosition3Feedback.Value == true)
  240. {
  241. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{Name} 到 Position3");
  242. _doGoPosition3On.Value = false;
  243. _position3Timer.Stop();
  244. }
  245. }
  246. }
  247. public void Reset()
  248. {
  249. }
  250. }
  251. }