123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- 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;
- private R_TRIG _trigError = new R_TRIG();
- private bool _lowIsNormal; //0 正常,1报警
- private string _warningText;
- private string _alarmText;
- private string _infoText;
- public Action WarningAction
- {
- get;
- set;
- }
- [Subscription(AITSensorProperty.Value)]
- public bool Value
- {
- get
- {
- if (_di != null)
- return _di.Value;
- if (_do != null)
- return _do.Value;
- return NormalValue;
- }
- }
- public bool NormalValue
- {
- get
- {
- return !_lowIsNormal;
- }
- }
- public bool IsError
- {
- get
- {
- return Value != NormalValue;
- }
- }
- public IoSensor(string module, XmlElement node)
- {
- base.Module = module;
- base.Name = node.GetAttribute("id");
- base.Display = node.GetAttribute("display");
- base.DeviceID = node.GetAttribute("schematicId");
- _di = ParseDiNode("di", node);// IO.DI[node.GetAttribute("di")];
- _do = ParseDoNode("do", node);
- _infoText = node.GetAttribute("infoText");
- _warningText = node.GetAttribute("warningText");
- _alarmText = node.GetAttribute("alarmText");
- _lowIsNormal = Convert.ToBoolean(node.GetAttribute("isLowAsNormal"));
- }
- public bool Initialize()
- {
- DATA.Subscribe(string.Format("Device.{0}.{1}", Module, Name), () =>
- {
- AITSensorData data = new AITSensorData()
- {
- DeviceName = Name,
- DeviceSchematicId = DeviceID,
- DisplayName = Display,
- Value = Value,
- IsError = IsError,
- };
- return data;
- }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- return true;
- }
- public void Terminate()
- {
- }
- public void Monitor()
- {
- try
- {
- _trigError.CLK = IsError;
- if (_trigError.Q)
- {
- if (WarningAction != null)
- {
- WarningAction();
- }
- else if (!string.IsNullOrEmpty(_warningText.Trim()))
- {
- EV.PostMessage(Module, EventEnum.DefaultWarning, _warningText);
- }else if (!string.IsNullOrEmpty(_alarmText.Trim()))
- {
- EV.PostMessage(Module, EventEnum.DefaultAlarm, _alarmText);
- }else if (!string.IsNullOrEmpty(_infoText.Trim()))
- {
- EV.PostMessage(Module, EventEnum.GeneralInfo, _infoText);
- }
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- }
- public void Reset()
- {
- _trigError.RST = true;
- }
- }
- }
|