using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Device; using Aitex.Core.RT.Device.Unit; using Aitex.Core.RT.IOCore; using Aitex.Core.RT.OperationCenter; using Aitex.Core.RT.SCCore; using DocumentFormat.OpenXml.EMMA; using MECF.Framework.Common.CommonData.DeviceData; using MECF.Framework.Common.Equipment; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using static MECF.Framework.Common.CommonData.DeviceData.AITFFUData; namespace FurnaceRT.Devices { public class IoFFU : BaseDevice, IDevice { #region Filed private DIAccessor _diDataWriteDone; private DIAccessor _diDataWriteError; private DIAccessor _diDataReadError; private AIAccessor _aiGroupNumber; private AIAccessor _aiAddressNumber; private AIAccessor _aiSwitch; private AIAccessor _aiSetSpeed; private AIAccessor _aiMaxSpeed; private AIAccessor _aiReset; private AIAccessor _aiErrorTimer; private AIAccessor _aiCurrentSpeed; private AIAccessor _aiVoltage; private AIAccessor _aiCurrent; private AIAccessor _aiStatus; private AOAccessor _aoSwitch; private AOAccessor _aoSetSpeed; private AOAccessor _aoReset; private DOAccessor _doEnable; private DOAccessor _doWriteCommand; private SCConfigItem _scFFULSPEED; private SCConfigItem _scFFUHSPEED; protected SCConfigItem _scSetSpeed; private bool _isFloatAioType = false; #endregion #region Property public int GroupNumber { get { if (_aiGroupNumber != null) { return (int)(_isFloatAioType ? _aiGroupNumber.FloatValue : _aiGroupNumber.Value); } return 0; } } public int AddressNumber { get { if (_aiAddressNumber != null) { return (int)(_isFloatAioType ? _aiAddressNumber.FloatValue : _aiAddressNumber.Value); } return 0; } } public bool IsEnable { get { if (_aoSwitch != null) return _aoSwitch.FloatValue > 0; return false; } } public bool IsSwitch { get { if (_aiSwitch != null) { var temp = (int)(_isFloatAioType ? _aiSwitch.FloatValue : _aiSwitch.Value); return temp == 0 ? false : true; } return false; } } public int SetSpeed { get { if (_aiSetSpeed != null) { return (int)(_isFloatAioType ? _aiSetSpeed.FloatValue : _aiSetSpeed.Value); } if (_aoSetSpeed != null) { return (int)(_isFloatAioType ? _aoSetSpeed.FloatValue : _aoSetSpeed.Value); } return 0; } } public int MaxSpeed { get { if (_aiMaxSpeed != null) { return (int)(_isFloatAioType ? _aiMaxSpeed.FloatValue : _aiMaxSpeed.Value); } return 0; } } public bool IsReset { get { if (_aiReset != null) { var temp = (int)(_isFloatAioType ? _aiReset.FloatValue : _aiReset.Value); return temp == 0 ? false : true; } return false; } } public int ErrorTimer { get { if (_aiErrorTimer != null) { return (int)(_isFloatAioType ? _aiErrorTimer.FloatValue : _aiErrorTimer.Value); } return 0; } } public int CurrentSpeed { get { if (_aiCurrentSpeed != null) { return (int)(_isFloatAioType ? _aiCurrentSpeed.FloatValue : _aiCurrentSpeed.Value); } return 0; } } public int Voltage { get { if (_aiVoltage != null) { return (int)(_isFloatAioType ? _aiVoltage.FloatValue : _aiVoltage.Value); } return 0; } } public int Current { get { if (_aiCurrent != null) { return (int)(_isFloatAioType ? _aiCurrent.FloatValue : _aiCurrent.Value); } return 0; } } public bool IsWriteError => _diDataWriteError != null ? _diDataWriteError.Value : false; public bool IsReadError => _diDataReadError != null ? _diDataReadError.Value : false; #endregion private AITFFUData DeviceData { get { AITFFUData data = new AITFFUData() { SetPoint = _aoSetSpeed != null ? _aoSetSpeed.FloatValue : 0, DisplayName = Display, RTName = Name, IsSwitchOn = GetFFUStatusEnum() == FFUStatusEnum.ON, Feedback = CurrentSpeed, Max = _scFFUHSPEED != null ? Convert.ToInt32((double)_scFFUHSPEED.Value) : 0, Min = _scFFULSPEED != null ? Convert.ToInt32((double)_scFFULSPEED.Value) : 0 }; return data; } } private FFUStatusEnum GetFFUStatusEnum() { if (_aiSwitch != null && _aiSwitch.FloatValue == 1) return FFUStatusEnum.OFF; if (_aiSwitch != null && _aiSwitch.FloatValue == 2) return FFUStatusEnum.ON; if (_aiStatus != null && (_aiStatus.FloatValue == 2 || _aiStatus.FloatValue == 3)) { return FFUStatusEnum.OFF; } if (_aiStatus != null && (_aiStatus.FloatValue == 0)) { return FFUStatusEnum.ON; } return FFUStatusEnum.Unknown; } public IoFFU(string module, XmlElement node, string ioModule = "") { base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module"); base.Name = node.GetAttribute("id"); base.Display = node.GetAttribute("display"); base.DeviceID = node.GetAttribute("schematicId"); var scRootPath = string.IsNullOrEmpty(node.GetAttribute("scRootPath")) ? Module : node.GetAttribute("scRootPath"); _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float"); _diDataWriteDone = ParseDiNode("diDataWriteDone", node, ioModule); _diDataWriteError = ParseDiNode("diDataWriteError", node, ioModule); _diDataReadError = ParseDiNode("diDataReadError", node, ioModule); _aiGroupNumber = ParseAiNode("aiGroupNumber", node, ioModule); _aiAddressNumber = ParseAiNode("aiAddressNumber", node, ioModule); _aiSwitch = ParseAiNode("aiSwitch", node, ioModule); _aiSetSpeed = ParseAiNode("aiSetSpeed", node, ioModule); _aiMaxSpeed = ParseAiNode("aiMaxSpeed", node, ioModule); _aiReset = ParseAiNode("aiReset", node, ioModule); _aiErrorTimer = ParseAiNode("aiErrorTimer", node, ioModule); _aiCurrentSpeed = ParseAiNode("aiCurrentSpeed", node, ioModule); _aiVoltage = ParseAiNode("aiVoltage", node, ioModule); _aiCurrent = ParseAiNode("aiCurrent", node, ioModule); _aiStatus = ParseAiNode("aiStatus", node, ioModule); _aoSwitch = ParseAoNode("aoSwitch", node, ioModule); _aoSetSpeed = ParseAoNode("aoSetSpeed", node, ioModule); _aoReset = ParseAoNode("aoReset", node, ioModule); _doEnable = ParseDoNode("doEnable", node, ioModule); _doWriteCommand = ParseDoNode("doWriteCommand", node, ioModule); _scSetSpeed = ParseScNode("SetSpeed", node, ioModule, $"{scRootPath}.{Name}.SetSpeed"); } public bool Initialize() { _scFFULSPEED = SC.GetConfigItem($"System.FFU.LSPEED"); _scFFUHSPEED = SC.GetConfigItem($"System.FFU.HSPEED"); DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData); DATA.Subscribe($"{Module}.{Name}.SetSpeed", () => SetSpeed); DATA.Subscribe($"{Module}.{Name}.CurrentSpeed", () => CurrentSpeed); //DATA.Subscribe($"{Module}.{Name}.GroupNumber", () => GroupNumber); //DATA.Subscribe($"{Module}.{Name}.AddressNumber", () => AddressNumber); //DATA.Subscribe($"{Module}.{Name}.IsSwitch", () => IsSwitch); //DATA.Subscribe($"{Module}.{Name}.MaxSpeed", () => MaxSpeed); //DATA.Subscribe($"{Module}.{Name}.IsReset", () => IsReset); //DATA.Subscribe($"{Module}.{Name}.ErrorTimer", () => ErrorTimer); //DATA.Subscribe($"{Module}.{Name}.Voltage", () => Voltage); //DATA.Subscribe($"{Module}.{Name}.Current", () => Current); OP.Subscribe($"{Module}.{Name}.SetCurrectSpeed", (string cmd, object[] param) => { SetCurrectSpeed(param); return true; }); //OP.Subscribe($"{Module}.{Name}.SetRetract", (string cmd, object[] param) => //{ // SetRetract(out string reason); // return true; //}); InitSCAOData(); return true; } private void InitSCAOData() { if (_scSetSpeed != null && _aoSetSpeed != null) _aoSetSpeed.FloatValue = (float)_scSetSpeed.DoubleValue; } public bool SetCurrectSpeed(object[] param) { if (param != null && param.Length > 0) { float.TryParse(param[0].ToString(), out float value); SetSpeedMethods(value); } return true; } private void SetSpeedMethods(float value) { if (_aoSetSpeed != null) { _aoSetSpeed.FloatValue = value; if (_scSetSpeed != null) SC.SetItemValue(_scSetSpeed.PathName, value.ToString()); } } public void Monitor() { } public void Reset() { } public void Terminate() { } public bool Unload(out string reason) { reason = ""; return true; } public bool Load(out string reason) { reason = ""; return true; } public bool Init(out string reason) { reason = ""; return true; } public bool Stop() { return true; } public void SetSwitch(bool isSwitch) { if (_aoSwitch != null) { _aoSwitch.FloatValue = isSwitch ? 1 : 0; } if (_aoSwitch == null) { if (isSwitch) { SetSpeedMethods(float.Parse(SC.GetStringValue(_scSetSpeed.PathName))); } else { SetSpeedMethods(0); } } } } }