using System; using System.Collections.Generic; using System.Linq; using System.Text; 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 IoCylinder : BaseDevice, IDevice { [Subscription(AITCylinderProperty.UpPositionFeedback)] public bool UpPositionFeedback { get { return _diUpPosition != null && _diUpPosition.Value; } } [Subscription(AITCylinderProperty.DownPositionFeedback)] public bool DownPositionFeedback { get { return _diDownPosition != null && _diDownPosition.Value; } } [Subscription(AITCylinderProperty.LeftPositionFeedback)] public bool LeftPositionFeedback { get { return _diLeftPosition != null && _diLeftPosition.Value; } } [Subscription(AITCylinderProperty.RightPositionFeedback)] public bool RightPositionFeedback { get { return _diRightPosition != null && _diRightPosition.Value; } } [Subscription(AITCylinderProperty.UpPositionSetPoint)] public bool UpPositionSetPoint { get { return _doUpPosition != null && _doUpPosition.Value; } set { if (_doUpPosition != null) _doUpPosition.Value = value; } } [Subscription(AITCylinderProperty.DownPositionSetPoint)] public bool DownPositionSetPoint { get { return _doDownPosition != null && _doDownPosition.Value; } set { if (_doDownPosition != null) _doDownPosition.Value = value; } } [Subscription(AITCylinderProperty.LeftPositionSetPoint)] public bool LeftPositionSetPoint { get { return _doLeftPosition != null && _doLeftPosition.Value; } set { if (_doLeftPosition != null) _doLeftPosition.Value = value; } } [Subscription(AITCylinderProperty.RightPositionSetPoint)] public bool RightPositionSetPoint { get { return _doRightPosition != null && _doRightPosition.Value; } set { if (_doRightPosition != null) _doRightPosition.Value = value; } } private DIAccessor _diUpPosition; private DIAccessor _diDownPosition; private DIAccessor _diLeftPosition; private DIAccessor _diRightPosition; private DOAccessor _doUpPosition; private DOAccessor _doDownPosition; private DOAccessor _doLeftPosition; private DOAccessor _doRightPosition; public IoCylinder(string module, XmlElement node) { base.Module = module; base.Name = node.GetAttribute("id"); base.Display = node.GetAttribute("display"); base.DeviceID = node.GetAttribute("schematicId"); _diUpPosition = ParseDiNode("diUp", node); _diDownPosition = ParseDiNode("diDown", node); _diLeftPosition = ParseDiNode("diLeft", node); _diRightPosition = ParseDiNode("diRight", node); _doUpPosition = ParseDoNode("doUp", node); _doDownPosition = ParseDoNode("doDown", node); _doLeftPosition = ParseDoNode("doLeft", node); _doRightPosition = ParseDoNode("doRight", node); } public bool Initialize() { DATA.Subscribe(string.Format("Device.{0}.{1}", Module, Name), () => { AITCylinderData data = new AITCylinderData() { DeviceName = Name, DeviceSchematicId = DeviceID, DisplayName = Display, UpPositionFeedback = UpPositionFeedback, DownPositionSetPoint = DownPositionSetPoint, UpPositionSetPoint = UpPositionSetPoint, DownPositionFeedback = DownPositionFeedback, LeftPositionFeedback = LeftPositionFeedback, LeftPositionSetPoint = LeftPositionSetPoint, RightPositionFeedback = RightPositionFeedback, RightPositionSetPoint = RightPositionSetPoint, }; return data; }, SubscriptionAttribute.FLAG.IgnoreSaveDB); DEVICE.Register(string.Format("{0}.{1}", Name, AITCylinderOperation.MoveUp), (out string reason, int time, object[] param) => { reason = string.Format("{0} Move up", Display); if (_doUpPosition != null && !_doUpPosition.SetValue(true, out reason)) return false; if (_doDownPosition != null && !_doDownPosition.SetValue(false, out reason)) return false; return true; }); DEVICE.Register(string.Format("{0}.{1}", Name, AITCylinderOperation.MoveDown), (out string reason, int time, object[] param) => { reason = string.Format("{0} Move down", Display); if (_doUpPosition != null && !_doUpPosition.SetValue(false, out reason)) return false; if (_doDownPosition != null && !_doDownPosition.SetValue(true, out reason)) return false; return true; }); DEVICE.Register(string.Format("{0}.{1}", Name, AITCylinderOperation.MoveLeft), (out string reason, int time, object[] param) => { reason = string.Format("{0} Move left", Display); if (_doLeftPosition != null && !_doLeftPosition.SetValue(true, out reason)) return false; if (_doRightPosition != null && !_doRightPosition.SetValue(false, out reason)) return false; return true; }); DEVICE.Register(string.Format("{0}.{1}", Name, AITCylinderOperation.MoveRight), (out string reason, int time, object[] param) => { reason = string.Format("{0} Move right", Display); if (_doLeftPosition != null && !_doLeftPosition.SetValue(false, out reason)) return false; if (_doRightPosition != null && !_doRightPosition.SetValue(true, out reason)) return false; return true; }); return true; } public void Terminate() { } public void Monitor() { try { } catch (Exception ex) { LOG.Write(ex); } } public void Reset() { } public void StopMove() { } public bool MoveUpDown(bool bUp, out string reason) { reason = ""; if (_doUpPosition != null && !_doUpPosition.SetValue(bUp, out reason)) return false; if (_doDownPosition != null && !_doDownPosition.SetValue(!bUp, out reason)) return false; return true; } public bool MoveLeftRight(bool bLeft, out string reason) { reason = ""; if (_doLeftPosition != null && !_doLeftPosition.SetValue(bLeft, out reason)) return false; if (_doRightPosition != null && !_doRightPosition.SetValue(!bLeft, out reason)) return false; return true; } } }