using Aitex.Core.Common.DeviceData; using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Device; using Aitex.Core.RT.IOCore; using Aitex.Core.RT.Log; using Aitex.Core.RT.SCCore; using Aitex.Core.RT.Tolerance; using Aitex.Core.UI.View.Common; using Aitex.Core.Util; using CdioCs; using MECF.Framework.Common.CommonData.DeviceData; using MECF.Framework.Common.Equipment; using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using System.Xml; using Venus_Core; namespace Venus_RT.Devices.IODevices { public class IoMagnet : BaseDevice, IDevice { public enum MagnetStatus { Unknown, OFF, ON, ERROR } public IoMagnet(string module, XmlElement node, string ioModule = "") { base.Module = module; Name = "AIoMagnet"; //base.Name = node.GetAttribute("id"); base.Display = node.GetAttribute("display"); base.DeviceID = node.GetAttribute("schematicId"); this.Status = MagnetStatus.Unknown; _aiMagnet1U = ParseAiNode("aiMagnet1U", node, ioModule); _aiMagnet1V = ParseAiNode("aiMagnet1V", node, ioModule); _aiMagnet1W = ParseAiNode("aiMagnet1W", node, ioModule); _aiMagnet2V = ParseAiNode("aiMagnet2V", node, ioModule); _aiMagnet2U = ParseAiNode("aiMagnet2U", node, ioModule); _aiMagnet2W = ParseAiNode("aiMagnet2W", node, ioModule); _diMagnetOn = ParseDiNode("diPowerOn", node, ioModule); _aoMagnetintensity= ParseAoNode("aoSetPoint", node, ioModule); _aoMagnetWaveForm = ParseAoNode("aoWaveSsquare", node, ioModule); _aoMagnetFieldRadio = ParseAoNode("aoMagnetFieldRadio", node, ioModule); _aoMagnetCycle = ParseAoNode("aoCycletime", node, ioModule); _aoMinMagnet = ParseAoNode("aoCurrentLimit", node, ioModule); _ao1Aoutput= ParseAoNode("ao1Aoutput", node, ioModule); _ao1Boutput = ParseAoNode("ao1Boutput", node, ioModule); _ao2Aoutput = ParseAoNode("ao2Aoutput", node, ioModule); _ao2Boutput = ParseAoNode("ao2Boutput", node, ioModule); } public MagnetStatus Status { get; set; } private readonly AIAccessor _aiMagnet1U; private readonly AIAccessor _aiMagnet1V; private readonly AIAccessor _aiMagnet1W; private readonly AIAccessor _aiMagnet2U; private readonly AIAccessor _aiMagnet2V; private readonly AIAccessor _aiMagnet2W; private readonly DIAccessor _diMagnetOn; private readonly AOAccessor _aoMagnetintensity; private readonly AOAccessor _aoMagnetWaveForm; private readonly AOAccessor _aoMagnetFieldRadio; private readonly AOAccessor _aoMagnetCycle; private readonly AOAccessor _aoMinMagnet; private readonly AOAccessor _ao1Aoutput; private readonly AOAccessor _ao1Boutput; private readonly AOAccessor _ao2Aoutput; private readonly AOAccessor _ao2Boutput; private ToleranceChecker _toleranceChecker = new ToleranceChecker(); public bool Initialize() { DATA.Subscribe($"{Module}.AIoMagnet.DeviceData", () => DeviceData, SubscriptionAttribute.FLAG.IgnoreSaveDB); _SetRealFloat(_aoMagnetWaveForm, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetwareform").Value)); _SetRealFloat(_aoMagnetCycle, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetcycleperiod").Value)); _SetRealFloat(_aoMinMagnet, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Min_Magnet_Coil_Current").Value)); _SetRealFloat(_aoMagnetFieldRadio, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.MagentFieldRatio").Value)); _SetRealFloat(_ao1Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1A_output_full_scale").Value)); _SetRealFloat(_ao1Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1B_output_full_scale").Value)); _SetRealFloat(_ao2Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2A_output_full_scale").Value)); _SetRealFloat(_ao2Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2B_output_full_scale").Value)); return true; } public AITMagnetData DeviceData { get { AITMagnetData deviceData = new AITMagnetData { Magnet1UFeedBack = Magent1U, Magnet1VFeedBack = Magent1V, Magnet1WFeedBack = Magent1W, Magnet2UFeedBack = Magent2U, Magnet2VFeedBack = Magent2V, Magnet2WFeedBack = Magent2W, IsMagnetOn = MagnetOn, MagnetIntensity= MagnetPowerIntensity }; return deviceData; } } public void Setpoint(AOAccessor ao,float config) { if (_GetRealFloat(ao) != config) { _SetRealFloat(ao, config); } } public void Monitor() { //Setpoint(_aoMagnetFieldRadio, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.MagentFieldRatio").Value)); Setpoint(_ao1Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1A_output_full_scale").Value)); Setpoint(_ao1Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_1B_output_full_scale").Value)); Setpoint(_ao2Aoutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2A_output_full_scale").Value)); Setpoint(_ao2Boutput, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnet_2B_output_full_scale").Value)); Setpoint(_aoMagnetCycle, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetcycleperiod").Value)); //Setpoint(_aoMagnetWaveForm, Convert.ToSingle(SC.GetConfigItem($"{Module}.Magnet.Magnetwareform").Value)); } public float Magent1V { get { if (_aiMagnet1V == null) return -1; float real = _GetRealFloat(_aiMagnet1V); return (float)Math.Round(real, 1); } } public float Magent1U { get { if (_aiMagnet1U == null) return -1; float real = _GetRealFloat(_aiMagnet1U); return (float)Math.Round(real, 1); } } public bool MagnetOn { get { return _diMagnetOn != null && _diMagnetOn.Value; } } public float Magent1W { get { if (_aiMagnet1W == null) return -1; float real = _GetRealFloat(_aiMagnet1W); return (float)Math.Round(real, 1); } } public float Magent2U { get { if (_aiMagnet2U == null) return -1; float real = _GetRealFloat(_aiMagnet2U); return (float)Math.Round(real, 1); } } public float Magent2V { get { if (_aiMagnet2V == null) return -1; float real = _GetRealFloat(_aiMagnet2V); return (float)Math.Round(real, 1); } } public bool SetMagnetPower(float val) { _SetRealFloat(_aoMagnetintensity, val); return true; } public bool SetFieldRatio(float val) { _SetRealFloat(_aoMagnetFieldRadio, val); return true; } public bool SetWaveform(int val) { _SetRealFloat(_aoMagnetWaveForm, val); return true; } public float Magent2W { get { if (_aiMagnet2W == null) return -1; float real = _GetRealFloat(_aiMagnet2W); return (float)Math.Round(real, 1); } } public float MagnetPowerIntensity { get { if (_aoMagnetintensity == null) return -1; float real = _GetRealFloat(_aoMagnetintensity); return real; } } public void Reset() { _SetRealFloat(_aoMagnetintensity, 0); } public void Terminate() { _SetRealFloat(_aoMagnetintensity, 0); } } }