IoMagnet.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. _doMagnetOpen = ParseDoNode("doMagnetsContactOn", node, ioModule);
  41. _aiMagnet1U = ParseAiNode("aiMagnet1U", node, ioModule);
  42. _aiMagnet1V = ParseAiNode("aiMagnet1V", node, ioModule);
  43. _aiMagnet1W = ParseAiNode("aiMagnet1W", node, ioModule);
  44. _aiMagnet2V = ParseAiNode("aiMagnet2V", node, ioModule);
  45. _aiMagnet2U = ParseAiNode("aiMagnet2U", node, ioModule);
  46. _aiMagnet2W = ParseAiNode("aiMagnet2W", node, ioModule);
  47. _diMagnetOn = ParseDiNode("diPowerOn", node, ioModule);
  48. _aoMagnetintensity= ParseAoNode("aoSetPoint", node, ioModule);
  49. _aoMagnetWaveForm = ParseAoNode("aoWaveSsquare", node, ioModule);
  50. _aoMagnetFieldRadio = ParseAoNode("aoMagnetFieldRadio", node, ioModule);
  51. _aoMagnetCycle = ParseAoNode("aoCycletime", node, ioModule);
  52. _aoMinMagnet = ParseAoNode("aoCurrentLimit", node, ioModule);
  53. _ao1Aoutput= ParseAoNode("ao1Aoutput", node, ioModule);
  54. _ao1Boutput = ParseAoNode("ao1Boutput", node, ioModule);
  55. _ao2Aoutput = ParseAoNode("ao2Aoutput", node, ioModule);
  56. _ao2Boutput = ParseAoNode("ao2Boutput", node, ioModule);
  57. }
  58. public MagnetStatus Status { get; set; }
  59. private readonly AIAccessor _aiMagnet1U;
  60. private readonly AIAccessor _aiMagnet1V;
  61. private readonly AIAccessor _aiMagnet1W;
  62. private readonly AIAccessor _aiMagnet2U;
  63. private readonly AIAccessor _aiMagnet2V;
  64. private readonly AIAccessor _aiMagnet2W;
  65. private readonly DIAccessor _diMagnetOn;
  66. private readonly AOAccessor _aoMagnetintensity;
  67. private readonly AOAccessor _aoMagnetWaveForm;
  68. private readonly AOAccessor _aoMagnetFieldRadio;
  69. private readonly AOAccessor _aoMagnetCycle;
  70. private readonly AOAccessor _aoMinMagnet;
  71. private readonly AOAccessor _ao1Aoutput;
  72. private readonly AOAccessor _ao1Boutput;
  73. private readonly AOAccessor _ao2Aoutput;
  74. private readonly AOAccessor _ao2Boutput;
  75. private DOAccessor _doMagnetOpen;
  76. private ToleranceChecker _toleranceChecker = new ToleranceChecker();
  77. public bool Initialize()
  78. {
  79. DATA.Subscribe($"{Module}.AIoMagnet.DeviceData", () => DeviceData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  80. _SetRealFloat(_aoMagnetWaveForm, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetwareform").Value));
  81. _SetRealFloat(_aoMagnetCycle, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetcycleperiod").Value));
  82. _SetRealFloat(_aoMinMagnet, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Min_Magnet_Coil_Current").Value));
  83. _SetRealFloat(_aoMagnetFieldRadio, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.MagnetFieldRatio").Value));
  84. _SetRealFloat(_ao1Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1A_output_full_scale").Value));
  85. _SetRealFloat(_ao1Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1B_output_full_scale").Value));
  86. _SetRealFloat(_ao2Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2A_output_full_scale").Value));
  87. _SetRealFloat(_ao2Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2B_output_full_scale").Value));
  88. return true;
  89. }
  90. public AITMagnetData DeviceData
  91. {
  92. get
  93. {
  94. AITMagnetData deviceData = new AITMagnetData
  95. {
  96. Magnet1UFeedBack = Magent1U,
  97. Magnet1VFeedBack = Magent1V,
  98. Magnet1WFeedBack = Magent1W,
  99. Magnet2UFeedBack = Magent2U,
  100. Magnet2VFeedBack = Magent2V,
  101. Magnet2WFeedBack = Magent2W,
  102. IsMagnetOn = MagnetOn,
  103. MagnetIntensity= MagnetPowerIntensity
  104. };
  105. return deviceData;
  106. }
  107. }
  108. public void Setpoint(AOAccessor ao,float config)
  109. {
  110. if (_GetRealFloat(ao) != config)
  111. {
  112. _SetRealFloat(ao, config);
  113. }
  114. }
  115. public void Monitor()
  116. {
  117. //Setpoint(_aoMagnetFieldRadio, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.MagentFieldRatio").Value));
  118. Setpoint(_ao1Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1A_output_full_scale").Value));
  119. Setpoint(_ao1Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1B_output_full_scale").Value));
  120. Setpoint(_ao2Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2A_output_full_scale").Value));
  121. Setpoint(_ao2Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2B_output_full_scale").Value));
  122. Setpoint(_aoMagnetCycle, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetcycleperiod").Value));
  123. //Setpoint(_aoMagnetWaveForm, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetwareform").Value));
  124. }
  125. public float Magent1V
  126. {
  127. get
  128. {
  129. if (_aiMagnet1V == null) return -1;
  130. float real = _GetRealFloat(_aiMagnet1V);
  131. return (float)Math.Round(real, 1);
  132. }
  133. }
  134. public float Magent1U
  135. {
  136. get
  137. {
  138. if (_aiMagnet1U == null) return -1;
  139. float real = _GetRealFloat(_aiMagnet1U);
  140. return (float)Math.Round(real, 1);
  141. }
  142. }
  143. public bool MagnetOn
  144. {
  145. get { return _diMagnetOn != null && _diMagnetOn.Value; }
  146. }
  147. public float Magent1W
  148. {
  149. get
  150. {
  151. if (_aiMagnet1W == null) return -1;
  152. float real = _GetRealFloat(_aiMagnet1W);
  153. return (float)Math.Round(real, 1);
  154. }
  155. }
  156. public float Magent2U
  157. {
  158. get
  159. {
  160. if (_aiMagnet2U == null) return -1;
  161. float real = _GetRealFloat(_aiMagnet2U);
  162. return (float)Math.Round(real, 1);
  163. }
  164. }
  165. public float Magent2V
  166. {
  167. get
  168. {
  169. if (_aiMagnet2V == null) return -1;
  170. float real = _GetRealFloat(_aiMagnet2V);
  171. return (float)Math.Round(real, 1);
  172. }
  173. }
  174. public bool SetMagnetPower(float val)
  175. {
  176. _SetRealFloat(_aoMagnetintensity, val);
  177. return true;
  178. }
  179. public bool SetFieldRatio(float val)
  180. {
  181. _SetRealFloat(_aoMagnetFieldRadio, val);
  182. return true;
  183. }
  184. public bool SetWaveform(int val)
  185. {
  186. _SetRealFloat(_aoMagnetWaveForm, val);
  187. return true;
  188. }
  189. public float Magent2W
  190. {
  191. get
  192. {
  193. if (_aiMagnet2W == null) return -1;
  194. float real = _GetRealFloat(_aiMagnet2W);
  195. return (float)Math.Round(real, 1);
  196. }
  197. }
  198. public float MagnetPowerIntensity
  199. {
  200. get
  201. {
  202. if (_aoMagnetintensity == null) return -1;
  203. float real = _GetRealFloat(_aoMagnetintensity);
  204. return real;
  205. }
  206. }
  207. public void Reset()
  208. {
  209. _doMagnetOpen.SetValue(true, out string reason);
  210. _SetRealFloat(_aoMagnetintensity, 0);
  211. }
  212. public void Terminate()
  213. {
  214. _SetRealFloat(_aoMagnetintensity, 0);
  215. }
  216. }
  217. }