1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System.Xml;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.IOCore;
- namespace Aitex.Core.RT.Device.Unit
- {
- public class IoTrigger : BaseDevice, IDevice
- {
- private DOAccessor _doTrigger = null;
- private AOAccessor _aoTrigger = null;
- public DOAccessor DoTrigger => _doTrigger;
- public IoTrigger(string module, XmlElement node, string ioModule = "")
- {
- base.Module = module;
- base.Name = node.GetAttribute("id");
- base.Display = node.GetAttribute("display");
- base.DeviceID = node.GetAttribute("schematicId");
- _doTrigger = ParseDoNode("doTrigger", node, ioModule);
- _aoTrigger = ParseAoNode("aoTrigger", node, ioModule);
- }
- public bool Value
- {
- get
- {
- if (_doTrigger != null)
- return _doTrigger.Value;
- if (_aoTrigger != null)
- return _aoTrigger.FloatValue > 0;
- return false;
- }
- }
- public float AOValue
- {
- get
- {
- if (_aoTrigger != null)
- return _aoTrigger.FloatValue;
- return 0f;
- }
- }
- public bool SetPulseTrigger(bool value, out string reason)
- {
- reason = "";
- _doTrigger?.SetPulseValue(value, 1500);
- return true;
- }
- public bool SetTrigger(bool value, out string reason)
- {
- reason = "";
- _doTrigger?.SetValue(value, out reason);
- if(_aoTrigger != null)
- _aoTrigger.FloatValue = value ? 1 : 0;
- return true;
- }
- public bool SetAOTrigger(float value, out string reason)
- {
- reason = "";
- if (_aoTrigger != null)
- _aoTrigger.FloatValue = value;
- return true;
- }
- public bool Initialize()
- {
- if (_aoTrigger != null)
- DATA.Subscribe($"{Module}.{Name}.AOValue", () => AOValue);
- return true;
- }
- public void Terminate()
- {
- }
- public void Monitor()
- {
-
- }
- public void Reset()
- {
-
- }
- }
- }
|