123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- 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;
- }
- }
- }
|