IoMagnet.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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.RT.SCCore;
  8. using Aitex.Core.RT.Tolerance;
  9. using Aitex.Core.UI.Control;
  10. using Aitex.Core.UI.View.Common;
  11. using Aitex.Core.Util;
  12. using CdioCs;
  13. using MECF.Framework.Common.CommonData.DeviceData;
  14. using MECF.Framework.Common.Equipment;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Security.Cryptography;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Xml;
  22. using Venus_Core;
  23. namespace Venus_RT.Devices.IODevices
  24. {
  25. public class IoMagnet : BaseDevice, IDevice
  26. {
  27. public enum MagnetStatus
  28. {
  29. Unknown,
  30. OFF,
  31. ON,
  32. ERROR
  33. }
  34. public IoMagnet(string module, XmlElement node, string ioModule = "")
  35. {
  36. base.Module = module;
  37. Name = "AIoMagnet";
  38. //base.Name = node.GetAttribute("id");
  39. base.Display = node.GetAttribute("display");
  40. base.DeviceID = node.GetAttribute("schematicId");
  41. this.Status = MagnetStatus.Unknown;
  42. _doMagnetOpen = ParseDoNode("doMagnetsContactOn", node, ioModule);
  43. _aiMagnet1U = ParseAiNode("aiMagnet1U", node, ioModule);
  44. _aiMagnet1V = ParseAiNode("aiMagnet1V", node, ioModule);
  45. _aiMagnet1W = ParseAiNode("aiMagnet1W", node, ioModule);
  46. _aiMagnet2V = ParseAiNode("aiMagnet2V", node, ioModule);
  47. _aiMagnet2U = ParseAiNode("aiMagnet2U", node, ioModule);
  48. _aiMagnet2W = ParseAiNode("aiMagnet2W", node, ioModule);
  49. _diMagnetOn = ParseDiNode("diPowerOn", node, ioModule);
  50. _aoMagnetintensity = ParseAoNode("aoSetPoint", node, ioModule);
  51. _aoMagnetWaveForm = ParseAoNode("aoWaveSsquare", node, ioModule);
  52. _aoMagnetFieldRadio = ParseAoNode("aoMagnetFieldRadio", node, ioModule);
  53. _aoMagnetCycle = ParseAoNode("aoCycletime", node, ioModule);
  54. _aoMinMagnet = ParseAoNode("aoCurrentLimit", node, ioModule);
  55. _ao1Aoutput = ParseAoNode("ao1Aoutput", node, ioModule);
  56. _ao1Boutput = ParseAoNode("ao1Boutput", node, ioModule);
  57. _ao2Aoutput = ParseAoNode("ao2Aoutput", node, ioModule);
  58. _ao2Boutput = ParseAoNode("ao2Boutput", node, ioModule);
  59. }
  60. public MagnetStatus Status { get; set; }
  61. private readonly AIAccessor _aiMagnet1U;
  62. private readonly AIAccessor _aiMagnet1V;
  63. private readonly AIAccessor _aiMagnet1W;
  64. private readonly AIAccessor _aiMagnet2U;
  65. private readonly AIAccessor _aiMagnet2V;
  66. private readonly AIAccessor _aiMagnet2W;
  67. private readonly DIAccessor _diMagnetOn;
  68. private readonly AOAccessor _aoMagnetintensity;
  69. private readonly AOAccessor _aoMagnetWaveForm;
  70. private readonly AOAccessor _aoMagnetFieldRadio;
  71. private readonly AOAccessor _aoMagnetCycle;
  72. private readonly AOAccessor _aoMinMagnet;
  73. private readonly AOAccessor _ao1Aoutput;
  74. private readonly AOAccessor _ao1Boutput;
  75. private readonly AOAccessor _ao2Aoutput;
  76. private readonly AOAccessor _ao2Boutput;
  77. private DOAccessor _doMagnetOpen;
  78. private ToleranceChecker _toleranceChecker = new ToleranceChecker();
  79. public bool Initialize()
  80. {
  81. DATA.Subscribe($"{Module}.AIoMagnet.DeviceData", () => DeviceData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  82. OP.Subscribe("System.SetMagnet", Setmagnet);
  83. _SetRealFloat(_aoMagnetWaveForm, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetwaveform").Value));
  84. _SetRealFloat(_aoMagnetCycle, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetcycleperiod").Value));
  85. _SetRealFloat(_aoMinMagnet, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Min_Magnet_Coil_Current").Value));
  86. _SetRealFloat(_aoMagnetFieldRadio, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.MagnetFieldRatio").Value));
  87. _SetRealFloat(_ao1Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1A_output_full_scale").Value));
  88. _SetRealFloat(_ao1Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1B_output_full_scale").Value));
  89. _SetRealFloat(_ao2Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2A_output_full_scale").Value));
  90. _SetRealFloat(_ao2Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2B_output_full_scale").Value));
  91. return true;
  92. }
  93. private bool Setmagnet(string cmd, object[] parameters)
  94. {
  95. if (parameters[0].ToString().Contains("Magnetwaveform"))
  96. {
  97. Setpoint(_aoMagnetWaveForm, Convert.ToSingle(parameters[1]));
  98. }
  99. else if (parameters[0].ToString().Contains("MagnetFieldRatio"))
  100. {
  101. _SetRealFloat(_aoMagnetFieldRadio, Convert.ToSingle(parameters[1]));
  102. }
  103. else if (parameters[0].ToString().Contains("Magnetcycleperiod"))
  104. {
  105. _SetRealFloat(_aoMagnetCycle, Convert.ToSingle(parameters[1]));
  106. }
  107. return true;
  108. }
  109. public AITMagnetData DeviceData
  110. {
  111. get
  112. {
  113. AITMagnetData deviceData = new AITMagnetData
  114. {
  115. Magnet1UFeedBack = Magent1U,
  116. Magnet1VFeedBack = Magent1V,
  117. Magnet1WFeedBack = Magent1W,
  118. Magnet2UFeedBack = Magent2U,
  119. Magnet2VFeedBack = Magent2V,
  120. Magnet2WFeedBack = Magent2W,
  121. IsMagnetOn = MagnetOn,
  122. MagnetIntensity = MagnetPowerIntensity
  123. };
  124. return deviceData;
  125. }
  126. }
  127. public void Setpoint(AOAccessor ao, float config)
  128. {
  129. if (_GetRealFloat(ao) != config)
  130. {
  131. _SetRealFloat(ao, config);
  132. }
  133. }
  134. public void Monitor()
  135. {
  136. //Setpoint(_aoMagnetFieldRadio, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.MagentFieldRatio").Value));
  137. Setpoint(_ao1Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1A_output_full_scale").Value));
  138. Setpoint(_ao1Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1B_output_full_scale").Value));
  139. Setpoint(_ao2Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2A_output_full_scale").Value));
  140. Setpoint(_ao2Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2B_output_full_scale").Value));
  141. if(_aoMagnetCycle.Value!= Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetcycleperiod").Value))
  142. _SetRealFloat(_aoMagnetCycle, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetcycleperiod").Value));
  143. //Setpoint(_aoMagnetCycle, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetcycleperiod").Value));
  144. //Setpoint(_aoMagnetWaveForm, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetwareform").Value));
  145. }
  146. public float Magent1V
  147. {
  148. get
  149. {
  150. if (_aiMagnet1V == null) return -1;
  151. float real = _GetRealFloat(_aiMagnet1V);
  152. return (float)Math.Round(real, 1);
  153. }
  154. }
  155. public float Magent1U
  156. {
  157. get
  158. {
  159. if (_aiMagnet1U == null) return -1;
  160. float real = _GetRealFloat(_aiMagnet1U);
  161. return (float)Math.Round(real, 1);
  162. }
  163. }
  164. public bool MagnetOn
  165. {
  166. get { return _diMagnetOn != null && _diMagnetOn.Value; }
  167. }
  168. public float Magent1W
  169. {
  170. get
  171. {
  172. if (_aiMagnet1W == null) return -1;
  173. float real = _GetRealFloat(_aiMagnet1W);
  174. return (float)Math.Round(real, 1);
  175. }
  176. }
  177. public float Magent2U
  178. {
  179. get
  180. {
  181. if (_aiMagnet2U == null) return -1;
  182. float real = _GetRealFloat(_aiMagnet2U);
  183. return (float)Math.Round(real, 1);
  184. }
  185. }
  186. public float Magent2V
  187. {
  188. get
  189. {
  190. if (_aiMagnet2V == null) return -1;
  191. float real = _GetRealFloat(_aiMagnet2V);
  192. return (float)Math.Round(real, 1);
  193. }
  194. }
  195. public bool SetMagnetPower(float val)
  196. {
  197. _SetRealFloat(_aoMagnetintensity, val);
  198. return true;
  199. }
  200. public bool SetFieldRatio(float val)
  201. {
  202. _SetRealFloat(_aoMagnetFieldRadio, val);
  203. return true;
  204. }
  205. public bool SetWaveform(int val)
  206. {
  207. _SetRealFloat(_aoMagnetWaveForm, val);
  208. return true;
  209. }
  210. public float Magent2W
  211. {
  212. get
  213. {
  214. if (_aiMagnet2W == null) return -1;
  215. float real = _GetRealFloat(_aiMagnet2W);
  216. return (float)Math.Round(real, 1);
  217. }
  218. }
  219. public float MagnetPowerIntensity
  220. {
  221. get
  222. {
  223. if (_aoMagnetintensity == null) return -1;
  224. float real = _GetRealFloat(_aoMagnetintensity);
  225. return real;
  226. }
  227. }
  228. public void Reset()
  229. {
  230. _doMagnetOpen.SetValue(true, out string reason);
  231. _SetRealFloat(_aoMagnetintensity, 0);
  232. }
  233. public void Terminate()
  234. {
  235. _SetRealFloat(_aoMagnetintensity, 0);
  236. }
  237. }
  238. }