using System; using System.Windows.Forms.VisualStyles; using System.Xml; using Aitex.Core.Common.DeviceData; using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.IOCore; using Aitex.Core.Util; namespace Aitex.Core.RT.Device.Unit { public class IoTrigger : BaseDevice, IDevice { private DOAccessor _doTrigger = null; [Subscription(AITTrigPropertyName.Status)] public bool Value { get { return _doTrigger.Value; } } public IoTrigger(string module, XmlElement node) { base.Module = module; base.Name = node.GetAttribute("id"); base.Display = node.GetAttribute("display"); base.DeviceID = node.GetAttribute("schematicId"); _doTrigger = ParseDoNode("doTrigger", node); } public bool SetTrigger(bool value, out string reason) { return _doTrigger.SetValue(value, out reason); } public bool Initialize() { DATA.Subscribe(string.Format("Device.{0}.{1}", Module , Name), () => { AITTrigData data = new AITTrigData() { DeviceName = Name, DeviceSchematicId = DeviceID, DisplayName = Display, Status = Value, }; return data; }, SubscriptionAttribute.FLAG.IgnoreSaveDB); DEVICE.Register(String.Format("{0}.{1}", Name, AITTrigOperation.TrigOn), (out string reason, int time, object[] param) => { bool ret = SetTrigger(true, out reason); if (ret) { reason = string.Format("{0} On", Name); return true; } return false; }); DEVICE.Register(String.Format("{0}.{1}", Name, AITTrigOperation.TrigOff), (out string reason, int time, object[] param) => { bool ret = SetTrigger(false, out reason); if (ret) { reason = string.Format("{0} Off", Name); return true; } return false; }); return true; } public void Terminate() { } public void Monitor() { } public void Reset() { } } }