优化IoPSU对象代码结构。
This commit is contained in:
SL 2023-07-19 14:07:29 +08:00
parent 1044f996c5
commit e4c96cd50d
1 changed files with 90 additions and 146 deletions

View File

@ -1,165 +1,69 @@
using Aitex.Core.RT.DataCenter;
using Aitex.Core.RT.Device;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.IOCore;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.OperationCenter;
using Aitex.Core.RT.SCCore;
using Aitex.Core.Util;
using MECF.Framework.Common.CommonData.DeviceData;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Temps.AE;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Temps;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace Aitex.Core.RT.Device.Devices
{
public class IoPSU : BaseDevice, IDevice
{
public float OutputVoltageFeedBack
{
get
{
return _aiOutputVoltage == null ? 0 : (_isFloatAioType ? _aiOutputVoltage.FloatValue : _aiOutputVoltage.Value);
}
}
#region Variables
public float OutputArmsFeedBack
{
get
{
return _aiOutputArms == null ? 0 : (_isFloatAioType ? _aiOutputArms.FloatValue : _aiOutputArms.Value);
}
}
public double Resistance
{
get
{
return OutputArmsFeedBack == 0 ? 0 : ((int)(OutputVoltageFeedBack / OutputArmsFeedBack * 1000)) / 1000.0;
}
}
public float OutputPowerFeedBack
{
get
{
return _aiOutputPower == null ? 0 : (_isFloatAioType ? _aiOutputPower.FloatValue : _aiOutputPower.Value);
}
}
public bool StatusFeedBack
{
get
{
return _diStatus == null ? false : _diStatus.Value;
}
}
public float SimVoltageFeedBack
{
get
{
return _aiSimVoltage == null ? 0 : (_isFloatAioType ? _aiSimVoltage.FloatValue : _aiSimVoltage.Value);
}
}
public float SimArmsFeedBack
{
get
{
return _aiSimArms == null ? 0 : (_isFloatAioType ? _aiSimArms.FloatValue : _aiSimArms.Value);
}
}
public bool AlarmFeedBack
{
get
{
return _diAlarm == null ? false : _diAlarm.Value;
}
}
public float ConstantSetPoint
{
get
{
return _aoConstant == null ? 0 : (_isFloatAioType ? _aoConstant.FloatValue : _aoConstant.Value);
}
set
{
if (_isFloatAioType)
{
_aoConstant.FloatValue = value;
}
else
{
_aoConstant.Value = (short)value;
}
}
}
public bool AllHeatEnable
{
get
{
return _diHeatEnable == null ? false : _diHeatEnable.Value;
}
}
private bool _isFloatAioType = false;
private AIAccessor _aiOutputVoltage = null;
private AIAccessor _aiOutputArms = null;
private AIAccessor _aiOutputPower = null;
private AIAccessor _aiSimVoltage = null;
private AIAccessor _aiSimArms = null;
private readonly bool _isFloatAioType;
private readonly AIAccessor _aiOutputVoltage;
private readonly AIAccessor _aiOutputArms;
private readonly AIAccessor _aiOutputPower;
private readonly AIAccessor _aiSimVoltage;
private readonly AIAccessor _aiSimArms;
//private AOAccessor _aoEnable = null;
//private AOAccessor _aoReset = null;
private AOAccessor _aoConstant = null;
private readonly AOAccessor _aoConstant;
private DIAccessor _diStatus = null;
private DIAccessor _diAlarm = null;
private DIAccessor _diHeatEnable = null;
private DIAccessor _diCommunicationError = null;
private readonly DIAccessor _diStatus;
private readonly DIAccessor _diAlarm;
private readonly DIAccessor _diHeatEnable;
private DIAccessor _diCommunicationError;
private DOAccessor _doReset;
private DOAccessor _doStatus;
private DOAccessor _doHeatEnable;
private DOAccessor _doRelatedEnable; //每个Enable同时关联的InnerMiddleOut Enable
private readonly DOAccessor _doReset;
private readonly DOAccessor _doStatus;
private readonly DOAccessor _doHeatEnable;
private readonly DOAccessor _doRelatedEnable; //每个Enable同时关联的InnerMiddleOut Enable
private string _infoText = "";
private string _commInfoText = "";
private R_TRIG _alarmTrig = new R_TRIG();
private R_TRIG _commAlarmTrig = new R_TRIG();
private R_TRIG _enableTrig = new R_TRIG();
private R_TRIG _enableTrig2 = new R_TRIG();
private readonly R_TRIG _alarmTrig = new();
private readonly R_TRIG _commAlarmTrig = new();
private readonly R_TRIG _enableTrig = new();
private readonly R_TRIG _enableTrig2 = new();
private R_TRIG _trigVoltage = new R_TRIG();
private R_TRIG _trigCurrent = new R_TRIG();
private readonly R_TRIG _trigVoltage = new();
private readonly R_TRIG _trigCurrent = new();
private R_TRIG _trigResistance = new R_TRIG();
private readonly R_TRIG _trigResistance = new();
private DeviceTimer _timer = new DeviceTimer();
private DeviceTimer _timerResistance = new DeviceTimer();
private readonly DeviceTimer _timer = new();
private readonly DeviceTimer _timerResistance = new();
public Func<bool, bool> FuncCheckInterLock;
#endregion
#region Constructors
public IoPSU(string module, XmlElement node, string ioModule = "")
{
var attrModule = node.GetAttribute("module");
base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
base.Name = node.GetAttribute("id");
base.Display = node.GetAttribute("display");
base.DeviceID = node.GetAttribute("schematicId");
Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
Name = node.GetAttribute("id");
Display = node.GetAttribute("display");
DeviceID = node.GetAttribute("schematicId");
_aiOutputVoltage = ParseAiNode("aiOutputVoltage", node, ioModule);
_aiOutputArms = ParseAiNode("aiOutputArms", node, ioModule);
@ -185,7 +89,50 @@ namespace Aitex.Core.RT.Device.Devices
}
string reason = string.Empty;
#endregion
#region Properties
public float OutputVoltageFeedBack => _aiOutputVoltage == null ? 0 : (_isFloatAioType ? _aiOutputVoltage.FloatValue : _aiOutputVoltage.Value);
public float OutputArmsFeedBack => _aiOutputArms == null ? 0 : (_isFloatAioType ? _aiOutputArms.FloatValue : _aiOutputArms.Value);
public double Resistance => OutputArmsFeedBack == 0 ? 0 : ((int)(OutputVoltageFeedBack / OutputArmsFeedBack * 1000)) / 1000.0;
public float OutputPowerFeedBack => _aiOutputPower == null ? 0 : (_isFloatAioType ? _aiOutputPower.FloatValue : _aiOutputPower.Value);
public bool StatusFeedBack => _diStatus?.Value ?? false;
public float SimVoltageFeedBack => _aiSimVoltage == null ? 0 : (_isFloatAioType ? _aiSimVoltage.FloatValue : _aiSimVoltage.Value);
public float SimArmsFeedBack => _aiSimArms == null ? 0 : (_isFloatAioType ? _aiSimArms.FloatValue : _aiSimArms.Value);
public bool AlarmFeedBack => _diAlarm?.Value ?? false;
public float ConstantSetPoint
{
get => _aoConstant == null ? 0 : (_isFloatAioType ? _aoConstant.FloatValue : _aoConstant.Value);
set
{
if (_isFloatAioType)
{
_aoConstant.FloatValue = value;
}
else
{
_aoConstant.Value = (short)value;
}
}
}
public bool AllHeatEnable => _diHeatEnable?.Value ?? false;
#endregion
#region Methods
public bool Initialize()
{
DATA.Subscribe($"{Module}.{Name}.OutputVoltageFeedBack", () => OutputVoltageFeedBack);
@ -201,22 +148,22 @@ namespace Aitex.Core.RT.Device.Devices
OP.Subscribe($"{Module}.{Name}.SetHeadHeaterEnable", (function, args) =>
{
bool isTrue = Convert.ToBoolean(args[0]);
SetHeadHeaterEnable(isTrue, out reason);
var isTrue = Convert.ToBoolean(args[0]);
SetHeadHeaterEnable(isTrue, out _);
return true;
});
OP.Subscribe($"{Module}.{Name}.SetPSUEnable", (function, args) =>
{
bool isTrue = Convert.ToBoolean(args[0]);
SetPSUEnable(isTrue, out reason);
var isTrue = Convert.ToBoolean(args[0]);
SetPSUEnable(isTrue, out _);
return true;
});
OP.Subscribe($"{Module}.{Name}.SetPSUReset", (function, args) =>
{
bool isTrue = Convert.ToBoolean(args[0]);
SetPSUReset(isTrue, out reason);
var isTrue = Convert.ToBoolean(args[0]);
SetPSUReset(isTrue, out _);
return true;
});
@ -225,8 +172,6 @@ namespace Aitex.Core.RT.Device.Devices
public bool SetPSUEnable(bool setValue, out string reason)
{
reason = "";
if (!_doStatus.Check(setValue, out reason))
{
EV.PostWarningLog(Module, reason);
@ -279,8 +224,6 @@ namespace Aitex.Core.RT.Device.Devices
public bool SetPSUReset(bool setValue, out string reason)
{
reason = "";
if (!_doReset.Check(setValue, out reason))
{
EV.PostWarningLog(Module, reason);
@ -304,7 +247,7 @@ namespace Aitex.Core.RT.Device.Devices
{
}
public void Monitor()
protected override void HandleMonitor()
{
try
{
@ -342,8 +285,8 @@ namespace Aitex.Core.RT.Device.Devices
private void MonitorAlarm()
{
//检查电阻值是否在合理范围
double dbResistorMax = SC.GetValue<double>($"PM.{Module}.Heater.{Name}ResistanceMax");
int timeOut = SC.GetValue<int>($"PM.{Module}.Heater.ResistanceCheckTimeOut");
var dbResistorMax = SC.GetValue<double>($"PM.{Module}.Heater.{Name}ResistanceMax");
var timeOut = SC.GetValue<int>($"PM.{Module}.Heater.ResistanceCheckTimeOut");
if (Resistance > dbResistorMax && _timerResistance.IsIdle())
{
@ -364,7 +307,7 @@ namespace Aitex.Core.RT.Device.Devices
private void MonitorEnableTimer()
{
if (base.Name == "PSU2")
if (Name == "PSU2")
{
_enableTrig.CLK = !_diHeatEnable.Value;
if (_enableTrig.Q)
@ -383,7 +326,7 @@ namespace Aitex.Core.RT.Device.Devices
{
get
{
object temp=new object();
var temp=new object();
if (SC.GetConfigItem("AETemp.EnableDevice").BoolValue)
{
temp = DATA.Poll($"{Module}.AETemp.Middle");
@ -398,5 +341,6 @@ namespace Aitex.Core.RT.Device.Devices
}
}
#endregion
}
}