123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.Utilities;
- using System;
- using System.Collections.Generic;
- using System.Xml;
- namespace Aitex.Core.RT.Device.Unit
- {
- public class IoThrottleValve2 : BaseDevice, IDevice
- {
- public PressureCtrlMode PressureMode
- {
- get
- {
- if (_aoPressureMode != null)
- {
- foreach (var ioMode in _ctrlModeIoValue)
- {
- if (_isFloatAioType)
- {
- if ((int)_aoPressureMode.FloatValue == ioMode.Value)
- {
- return ioMode.Key;
- }
- }
- else
- {
- if (_aoPressureMode.Value == ioMode.Value)
- {
- return ioMode.Key;
- }
- }
- }
- return PressureCtrlMode.Undefined;
- }
- return PressureCtrlMode.Undefined;
- }
- set
- {
- if (_isFloatAioType)
- _aoPressureMode.FloatValue = _ctrlModeIoValue[value];
- else
- {
- _aoPressureMode.Value = (short)_ctrlModeIoValue[value];
- }
- }
- }
- public float PositionSetpoint
- {
- get
- {
- return _aoPositionSetPoint == null ? 0 : (_isFloatAioType? _aoPositionSetPoint.FloatValue: _aoPositionSetPoint.Value);
- }
- set
- {
- if (_isFloatAioType)
- {
- _aoPositionSetPoint.FloatValue = value;
- }
- else
- {
- _aoPositionSetPoint.Value = (short)value;
- }
- }
- }
- public float PositionFeedback
- {
- get
- {
- return _aiPositionFeedback == null ? 0 : (_isFloatAioType ? _aiPositionFeedback.FloatValue: _aiPositionFeedback.Value);
- }
- }
- public float PressureSetpoint
- {
- get
- {
- return _aoPressureSetPoint == null ? 0 : (_isFloatAioType ? _aoPressureSetPoint.FloatValue:_aoPressureSetPoint.Value);
- }
- set
- {
- if (_isFloatAioType)
- {
- _aoPressureSetPoint.FloatValue = value;
- }
- else
- {
- _aoPressureSetPoint.Value = (short)value;
- }
- }
- }
- public float PressureFeedback
- {
- get
- {
- return _aiPressureFeedback == null ? 0 : (_isFloatAioType ? _aiPressureFeedback.FloatValue:_aiPressureFeedback.Value);
- }
- }
- private AITThrottleValveData DeviceData
- {
- get
- {
- AITThrottleValveData data = new AITThrottleValveData()
- {
- Module = Module,
- DeviceName = Name,
- DeviceSchematicId = DeviceID,
- DisplayName = Display,
- Mode = (int)PressureMode,
- PositionFeedback = PositionFeedback,
- PositionSetPoint = PositionSetpoint,
- PressureFeedback = PressureFeedback,
- PressureSetPoint = PressureSetpoint,
- MaxValuePosition = 100,
- MaxValuePressure = _unitPressure == "Torr" ? 760 : 760000,
- UnitPressure = _unitPressure,
- };
- return data;
- }
- }
- private AOAccessor _aoPressureMode = null;
- private AIAccessor _aiPositionFeedback = null;
- private AOAccessor _aoPositionSetPoint = null;
- private AIAccessor _aiPressureFeedback = null;
- private AOAccessor _aoPressureSetPoint = null;
- private string _unitPressure;
- private Dictionary<PressureCtrlMode, int> _ctrlModeIoValue = new Dictionary<PressureCtrlMode, int>();
-
- private bool _isFloatAioType = false;
- public IoThrottleValve2(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");
- _unitPressure = node.GetAttribute("unit");
- _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
- _aoPressureMode = ParseAoNode("aoPressureMode", node, ioModule);
- _aiPositionFeedback = ParseAiNode("aiPositionFeedback", node, ioModule);
- _aoPositionSetPoint = ParseAoNode("aoPositionSetPoint", node, ioModule);
- _aiPressureFeedback = ParseAiNode("aiPressureFeedback", node, ioModule);
- _aoPressureSetPoint = ParseAoNode("aoPressureSetPoint", node, ioModule);
- EnumLoop<PressureCtrlMode>.ForEach(x => _ctrlModeIoValue[x] = -1);
- if (!string.IsNullOrEmpty(node.GetAttribute("modeValuePressure")))
- {
- _ctrlModeIoValue[PressureCtrlMode.TVPressureCtrl] = int.Parse(node.GetAttribute("modeValuePressure"));
- }
- if (!string.IsNullOrEmpty(node.GetAttribute("modeValuePosition")))
- {
- _ctrlModeIoValue[PressureCtrlMode.TVPositionCtrl] = int.Parse(node.GetAttribute("modeValuePosition"));
- }
- if (!string.IsNullOrEmpty(node.GetAttribute("modeValueOpen")))
- {
- _ctrlModeIoValue[PressureCtrlMode.TVOpen] = int.Parse(node.GetAttribute("modeValueOpen"));
- }
- if (!string.IsNullOrEmpty(node.GetAttribute("modeValueClose")))
- {
- _ctrlModeIoValue[PressureCtrlMode.TVClose] = int.Parse(node.GetAttribute("modeValueClose"));
- }
- }
- public bool Initialize()
- {
- DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
- DATA.Subscribe($"{Module}.{Name}.PositionSetPoint", () => PositionSetpoint);
- DATA.Subscribe($"{Module}.{Name}.PositionFeedback", () => PositionFeedback);
- DATA.Subscribe($"{Module}.{Name}.PressureSetPoint", () => PressureSetpoint);
- DATA.Subscribe($"{Module}.{Name}.PressureFeedback", () => PressureFeedback);
- DATA.Subscribe($"{Module}.{Name}.Mode", () => PressureMode);
- OP.Subscribe($"{Module}.{Name}.{AITThrottleValveOperation.SetMode}", SetMode);
- OP.Subscribe($"{Module}.{Name}.{AITThrottleValveOperation.SetPosition}", SetPosition);
- OP.Subscribe($"{Module}.{Name}.{AITThrottleValveOperation.SetPressure}", SetPressure);
- return true;
- }
- public bool SetMode(PressureCtrlMode mode, out string reason)
- {
- PressureMode = mode;
- reason = $"{Display} set to {mode}";
- EV.PostInfoLog(Module, reason);
- return true;
- }
- private bool SetMode(out string reason, int time, object[] param)
- {
- return SetMode((PressureCtrlMode)Enum.Parse(typeof(PressureCtrlMode), (string)param[0], true),
- out reason);
- }
- public bool SetPosition(float position, out string reason)
- {
- PositionSetpoint = position;
- reason = $"{Display} position set to {position}";
- EV.PostInfoLog(Module, reason);
- return true;
- }
- private bool SetPosition(out string reason, int time, object[] param)
- {
- return SetPosition(Convert.ToSingle(param[0].ToString()), out reason);
- }
- private bool SetPressure(out string reason, int time, object[] param)
- {
- return SetPressure(Convert.ToSingle(param[0].ToString()), out reason);
- }
- public bool SetPressure(float pressure, out string reason)
- {
- PressureSetpoint = pressure;
- reason = $"{Display} pressure set to {pressure} {_unitPressure}";
- EV.PostInfoLog(Module, reason);
- return true;
- }
- public void Terminate()
- {
- }
- public void Monitor()
- {
- try
- {
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- }
- public void Reset()
- {
- }
- }
- }
|