IoCylinder.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml;
  6. using Aitex.Core.Common.DeviceData;
  7. using Aitex.Core.RT.DataCenter;
  8. using Aitex.Core.RT.Event;
  9. using Aitex.Core.RT.IOCore;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.Util;
  12. namespace Aitex.Core.RT.Device.Unit
  13. {
  14. public class IoCylinder : BaseDevice, IDevice
  15. {
  16. [Subscription(AITCylinderProperty.UpPositionFeedback)]
  17. public bool UpPositionFeedback
  18. {
  19. get
  20. {
  21. return _diUpPosition != null && _diUpPosition.Value;
  22. }
  23. }
  24. [Subscription(AITCylinderProperty.DownPositionFeedback)]
  25. public bool DownPositionFeedback
  26. {
  27. get
  28. {
  29. return _diDownPosition != null && _diDownPosition.Value;
  30. }
  31. }
  32. [Subscription(AITCylinderProperty.LeftPositionFeedback)]
  33. public bool LeftPositionFeedback
  34. {
  35. get
  36. {
  37. return _diLeftPosition != null && _diLeftPosition.Value;
  38. }
  39. }
  40. [Subscription(AITCylinderProperty.RightPositionFeedback)]
  41. public bool RightPositionFeedback
  42. {
  43. get
  44. {
  45. return _diRightPosition != null && _diRightPosition.Value;
  46. }
  47. }
  48. [Subscription(AITCylinderProperty.UpPositionSetPoint)]
  49. public bool UpPositionSetPoint
  50. {
  51. get
  52. {
  53. return _doUpPosition != null && _doUpPosition.Value;
  54. }
  55. set
  56. {
  57. if (_doUpPosition != null)
  58. _doUpPosition.Value = value;
  59. }
  60. }
  61. [Subscription(AITCylinderProperty.DownPositionSetPoint)]
  62. public bool DownPositionSetPoint
  63. {
  64. get
  65. {
  66. return _doDownPosition != null && _doDownPosition.Value;
  67. }
  68. set
  69. {
  70. if (_doDownPosition != null)
  71. _doDownPosition.Value = value;
  72. }
  73. }
  74. [Subscription(AITCylinderProperty.LeftPositionSetPoint)]
  75. public bool LeftPositionSetPoint
  76. {
  77. get
  78. {
  79. return _doLeftPosition != null && _doLeftPosition.Value;
  80. }
  81. set
  82. {
  83. if (_doLeftPosition != null)
  84. _doLeftPosition.Value = value;
  85. }
  86. }
  87. [Subscription(AITCylinderProperty.RightPositionSetPoint)]
  88. public bool RightPositionSetPoint
  89. {
  90. get
  91. {
  92. return _doRightPosition != null && _doRightPosition.Value;
  93. }
  94. set
  95. {
  96. if (_doRightPosition != null)
  97. _doRightPosition.Value = value;
  98. }
  99. }
  100. private DIAccessor _diUpPosition;
  101. private DIAccessor _diDownPosition;
  102. private DIAccessor _diLeftPosition;
  103. private DIAccessor _diRightPosition;
  104. private DOAccessor _doUpPosition;
  105. private DOAccessor _doDownPosition;
  106. private DOAccessor _doLeftPosition;
  107. private DOAccessor _doRightPosition;
  108. public IoCylinder(string module, XmlElement node)
  109. {
  110. base.Module = module;
  111. base.Name = node.GetAttribute("id");
  112. base.Display = node.GetAttribute("display");
  113. base.DeviceID = node.GetAttribute("schematicId");
  114. _diUpPosition = ParseDiNode("diUp", node);
  115. _diDownPosition = ParseDiNode("diDown", node);
  116. _diLeftPosition = ParseDiNode("diLeft", node);
  117. _diRightPosition = ParseDiNode("diRight", node);
  118. _doUpPosition = ParseDoNode("doUp", node);
  119. _doDownPosition = ParseDoNode("doDown", node);
  120. _doLeftPosition = ParseDoNode("doLeft", node);
  121. _doRightPosition = ParseDoNode("doRight", node);
  122. }
  123. public bool Initialize()
  124. {
  125. DATA.Subscribe(string.Format("Device.{0}.{1}", Module, Name), () =>
  126. {
  127. AITCylinderData data = new AITCylinderData()
  128. {
  129. DeviceName = Name,
  130. DeviceSchematicId = DeviceID,
  131. DisplayName = Display,
  132. UpPositionFeedback = UpPositionFeedback,
  133. DownPositionSetPoint = DownPositionSetPoint,
  134. UpPositionSetPoint = UpPositionSetPoint,
  135. DownPositionFeedback = DownPositionFeedback,
  136. LeftPositionFeedback = LeftPositionFeedback,
  137. LeftPositionSetPoint = LeftPositionSetPoint,
  138. RightPositionFeedback = RightPositionFeedback,
  139. RightPositionSetPoint = RightPositionSetPoint,
  140. };
  141. return data;
  142. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  143. DEVICE.Register(string.Format("{0}.{1}", Name, AITCylinderOperation.MoveUp),
  144. (out string reason, int time, object[] param) =>
  145. {
  146. reason = string.Format("{0} Move up", Display);
  147. if (_doUpPosition != null && !_doUpPosition.SetValue(true, out reason))
  148. return false;
  149. if (_doDownPosition != null && !_doDownPosition.SetValue(false, out reason))
  150. return false;
  151. return true;
  152. });
  153. DEVICE.Register(string.Format("{0}.{1}", Name, AITCylinderOperation.MoveDown),
  154. (out string reason, int time, object[] param) =>
  155. {
  156. reason = string.Format("{0} Move down",
  157. Display);
  158. if (_doUpPosition != null && !_doUpPosition.SetValue(false, out reason))
  159. return false;
  160. if (_doDownPosition != null && !_doDownPosition.SetValue(true, out reason))
  161. return false;
  162. return true;
  163. });
  164. DEVICE.Register(string.Format("{0}.{1}", Name, AITCylinderOperation.MoveLeft),
  165. (out string reason, int time, object[] param) =>
  166. {
  167. reason = string.Format("{0} Move left",
  168. Display);
  169. if (_doLeftPosition != null && !_doLeftPosition.SetValue(true, out reason))
  170. return false;
  171. if (_doRightPosition != null && !_doRightPosition.SetValue(false, out reason))
  172. return false;
  173. return true;
  174. });
  175. DEVICE.Register(string.Format("{0}.{1}", Name, AITCylinderOperation.MoveRight),
  176. (out string reason, int time, object[] param) =>
  177. {
  178. reason = string.Format("{0} Move right",
  179. Display);
  180. if (_doLeftPosition != null && !_doLeftPosition.SetValue(false, out reason))
  181. return false;
  182. if (_doRightPosition != null && !_doRightPosition.SetValue(true, out reason))
  183. return false;
  184. return true;
  185. });
  186. return true;
  187. }
  188. public void Terminate()
  189. {
  190. }
  191. public void Monitor()
  192. {
  193. try
  194. {
  195. }
  196. catch (Exception ex)
  197. {
  198. LOG.Write(ex);
  199. }
  200. }
  201. public void Reset()
  202. {
  203. }
  204. public void StopMove()
  205. {
  206. }
  207. public bool MoveUpDown(bool bUp, out string reason)
  208. {
  209. reason = "";
  210. if (_doUpPosition != null && !_doUpPosition.SetValue(bUp, out reason))
  211. return false;
  212. if (_doDownPosition != null && !_doDownPosition.SetValue(!bUp, out reason))
  213. return false;
  214. return true;
  215. }
  216. public bool MoveLeftRight(bool bLeft, out string reason)
  217. {
  218. reason = "";
  219. if (_doLeftPosition != null && !_doLeftPosition.SetValue(bLeft, out reason))
  220. return false;
  221. if (_doRightPosition != null && !_doRightPosition.SetValue(!bLeft, out reason))
  222. return false;
  223. return true;
  224. }
  225. }
  226. }