IoMagnet.cs 8.5 KB

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