IoHighTemperatureHeater.cs 20 KB

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