123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using System;
- using System.Security.AccessControl;
- using System.Xml;
- 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.Util;
- namespace Aitex.Core.RT.Device.Unit
- {
- public class IoSensor : BaseDevice, IDevice
- {
- private DIAccessor _di = null;
- private DOAccessor _do = null;
- public DIAccessor SensorDI => _di;
- public DOAccessor SensorDO => _do;
- private R_TRIG _trigTextOut = new R_TRIG();
- private bool _textOutTrigValue;
- public bool AlarmTrigValue
- {
- get { return _textOutTrigValue&&!string.IsNullOrEmpty(_alarmText); }
- }
- private string _warningText;
- private string _alarmText;
- private string _infoText;
- public Action WarningAction
- {
- get;
- set;
- }
- public event Action<IoSensor, bool> OnSignalChanged;
- public bool Value
- {
- get
- {
- if (_di != null)
- return _di.Value;
- if (_do != null)
- return _do.Value;
- return false;
- }
- }
- private AITSensorData DeviceData
- {
- get
- {
- AITSensorData data = new AITSensorData()
- {
- DeviceName = Name,
- DeviceSchematicId = DeviceID,
- DisplayName = Display,
- Value = Value,
- };
- return data;
- }
- }
- private bool _previous;
-
- public IoSensor(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");
- _di = ParseDiNode("di", node, ioModule);// IO.DI[node.GetAttribute("di")];
- //_do = ParseDoNode("do", node, ioModule);
- _infoText = node.GetAttribute("infoText");
- _warningText = node.GetAttribute("warningText");
- _alarmText = node.GetAttribute("alarmText");
-
- _textOutTrigValue = Convert.ToBoolean(string.IsNullOrEmpty(node.GetAttribute("textOutTrigValue")) ? "false" : node.GetAttribute("textOutTrigValue"));
- }
- public bool Initialize()
- {
- DATA.Subscribe($"{Module}.{Name}", () => DeviceData);
- DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
- DATA.Subscribe($"{Module}.{Name}.Value", () => Value);
- return true;
- }
- public void Terminate()
- {
- }
- public void Monitor()
- {
- try
- {
- if(Name == "SensorLowArmHasWafer" || Name == "SensorUpArmHasWafer" || Name == "SensorTMRBReady") return;
- _trigTextOut.CLK = (Value == _textOutTrigValue) ;
- if (_trigTextOut.Q)
- {
- if (WarningAction != null)
- {
- WarningAction();
- }
- else if (!string.IsNullOrEmpty(_warningText.Trim()))
- {
- EV.PostWarningLog(Module, _warningText);
- }else if (!string.IsNullOrEmpty(_alarmText.Trim()))
- {
- EV.PostAlarmLog(Module, _alarmText);
- }else if (!string.IsNullOrEmpty(_infoText.Trim()))
- {
- EV.PostInfoLog(Module, _infoText);
- }
- }
- if (_previous != Value)
- {
- if (OnSignalChanged != null)
- OnSignalChanged(this, Value);
- _previous = Value;
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- }
- public void Reset()
- {
- _trigTextOut.RST = true;
- }
- }
- }
|