IoHighTemperatureHeater.cs 14 KB

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