123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- 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 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 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);
- }
- 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 = 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)
- return FFUStatusEnum.Unknown;
- if (_aiSwitch.FloatValue == 1)
- return FFUStatusEnum.OFF;
- if (_aiSwitch.FloatValue == 2)
- 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");
- _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);
- _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);
- }
- public bool Initialize()
- {
- _scFFULSPEED = SC.GetConfigItem($"System.FFU.LSPEED");
- _scFFUHSPEED = SC.GetConfigItem($"System.FFU.HSPEED");
- _scSetSpeed = SC.GetConfigItem($"System.FFU.{Name}.SetSpeed");
- DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
- DATA.Subscribe($"{Module}.{Name}.GroupNumber", () => GroupNumber);
- DATA.Subscribe($"{Module}.{Name}.AddressNumber", () => AddressNumber);
- DATA.Subscribe($"{Module}.{Name}.IsSwitch", () => IsSwitch);
- DATA.Subscribe($"{Module}.{Name}.SetSpeed", () => SetSpeed);
- DATA.Subscribe($"{Module}.{Name}.MaxSpeed", () => MaxSpeed);
- DATA.Subscribe($"{Module}.{Name}.IsReset", () => IsReset);
- DATA.Subscribe($"{Module}.{Name}.ErrorTimer", () => ErrorTimer);
- DATA.Subscribe($"{Module}.{Name}.CurrentSpeed", () => CurrentSpeed);
- 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;
- //});
- return true;
- }
- public bool SetCurrectSpeed(object[] param)
- {
- if (param != null && param.Length > 0)
- {
- float.TryParse(param[0].ToString(), out float value);
- if (_aoSetSpeed != null)
- {
- _aoSetSpeed.FloatValue = value;
- if (_scSetSpeed != null)
- SC.SetItemValue(_scSetSpeed.PathName, param[0].ToString());
- }
- }
- return true;
- }
- 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;
- }
- }
- }
- }
|