IoMagnet.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. //Setpoint(_aoMagnetCycle, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetcycleperiod").Value));
  142. //Setpoint(_aoMagnetWaveForm, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetwareform").Value));
  143. }
  144. public float Magent1V
  145. {
  146. get
  147. {
  148. if (_aiMagnet1V == null) return -1;
  149. float real = _GetRealFloat(_aiMagnet1V);
  150. return (float)Math.Round(real, 1);
  151. }
  152. }
  153. public float Magent1U
  154. {
  155. get
  156. {
  157. if (_aiMagnet1U == null) return -1;
  158. float real = _GetRealFloat(_aiMagnet1U);
  159. return (float)Math.Round(real, 1);
  160. }
  161. }
  162. public bool MagnetOn
  163. {
  164. get { return _diMagnetOn != null && _diMagnetOn.Value; }
  165. }
  166. public float Magent1W
  167. {
  168. get
  169. {
  170. if (_aiMagnet1W == null) return -1;
  171. float real = _GetRealFloat(_aiMagnet1W);
  172. return (float)Math.Round(real, 1);
  173. }
  174. }
  175. public float Magent2U
  176. {
  177. get
  178. {
  179. if (_aiMagnet2U == null) return -1;
  180. float real = _GetRealFloat(_aiMagnet2U);
  181. return (float)Math.Round(real, 1);
  182. }
  183. }
  184. public float Magent2V
  185. {
  186. get
  187. {
  188. if (_aiMagnet2V == null) return -1;
  189. float real = _GetRealFloat(_aiMagnet2V);
  190. return (float)Math.Round(real, 1);
  191. }
  192. }
  193. public bool SetMagnetPower(float val)
  194. {
  195. _SetRealFloat(_aoMagnetintensity, val);
  196. return true;
  197. }
  198. public bool SetFieldRatio(float val)
  199. {
  200. _SetRealFloat(_aoMagnetFieldRadio, val);
  201. return true;
  202. }
  203. public bool SetWaveform(int val)
  204. {
  205. _SetRealFloat(_aoMagnetWaveForm, val);
  206. return true;
  207. }
  208. public float Magent2W
  209. {
  210. get
  211. {
  212. if (_aiMagnet2W == null) return -1;
  213. float real = _GetRealFloat(_aiMagnet2W);
  214. return (float)Math.Round(real, 1);
  215. }
  216. }
  217. public float MagnetPowerIntensity
  218. {
  219. get
  220. {
  221. if (_aoMagnetintensity == null) return -1;
  222. float real = _GetRealFloat(_aoMagnetintensity);
  223. return real;
  224. }
  225. }
  226. public void Reset()
  227. {
  228. _doMagnetOpen.SetValue(true, out string reason);
  229. _SetRealFloat(_aoMagnetintensity, 0);
  230. }
  231. public void Terminate()
  232. {
  233. _SetRealFloat(_aoMagnetintensity, 0);
  234. }
  235. }
  236. }