IoFFU.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.IOCore;
  4. using Aitex.Core.RT.OperationCenter;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Xml;
  11. namespace FurnaceRT.Devices
  12. {
  13. public class IoFFU : BaseDevice, IDevice
  14. {
  15. #region Filed
  16. private DIAccessor _diDataWriteDone;
  17. private DIAccessor _diDataWriteError;
  18. private DIAccessor _diDataReadError;
  19. private AIAccessor _aiGroupNumber;
  20. private AIAccessor _aiAddressNumber;
  21. private AIAccessor _aiSwitch;
  22. private AIAccessor _aiSetSpeed;
  23. private AIAccessor _aiMaxSpeed;
  24. private AIAccessor _aiReset;
  25. private AIAccessor _aiErrorTimer;
  26. private AIAccessor _aiCurrentSpeed;
  27. private AIAccessor _aiVoltage;
  28. private AIAccessor _aiCurrent;
  29. private AOAccessor _aoSwitch;
  30. private AOAccessor _aoSetSpeed;
  31. private AOAccessor _aoReset;
  32. private DOAccessor _doEnable;
  33. private DOAccessor _doWriteCommand;
  34. private bool _isFloatAioType = false;
  35. #endregion
  36. #region Property
  37. public int GroupNumber
  38. {
  39. get
  40. {
  41. if (_aiGroupNumber != null)
  42. {
  43. return (int)(_isFloatAioType ? _aiGroupNumber.FloatValue : _aiGroupNumber.Value);
  44. }
  45. return 0;
  46. }
  47. }
  48. public int AddressNumber
  49. {
  50. get
  51. {
  52. if (_aiAddressNumber != null)
  53. {
  54. return (int)(_isFloatAioType ? _aiAddressNumber.FloatValue : _aiAddressNumber.Value);
  55. }
  56. return 0;
  57. }
  58. }
  59. public bool IsEnable
  60. {
  61. get
  62. {
  63. if (_aoSwitch != null)
  64. return _aoSwitch.FloatValue > 0;
  65. return false;
  66. }
  67. }
  68. public bool IsSwitch
  69. {
  70. get
  71. {
  72. if (_aiSwitch != null)
  73. {
  74. var temp = (int)(_isFloatAioType ? _aiSwitch.FloatValue : _aiSwitch.Value);
  75. return temp == 0 ? false : true;
  76. }
  77. return false;
  78. }
  79. }
  80. public int SetSpeed
  81. {
  82. get
  83. {
  84. if (_aiSetSpeed != null)
  85. {
  86. return (int)(_isFloatAioType ? _aiSetSpeed.FloatValue : _aiSetSpeed.Value);
  87. }
  88. return 0;
  89. }
  90. }
  91. public int MaxSpeed
  92. {
  93. get
  94. {
  95. if (_aiMaxSpeed != null)
  96. {
  97. return (int)(_isFloatAioType ? _aiMaxSpeed.FloatValue : _aiMaxSpeed.Value);
  98. }
  99. return 0;
  100. }
  101. }
  102. public bool IsReset
  103. {
  104. get
  105. {
  106. if (_aiReset != null)
  107. {
  108. var temp = (int)(_isFloatAioType ? _aiReset.FloatValue : _aiReset.Value);
  109. return temp == 0 ? false : true;
  110. }
  111. return false;
  112. }
  113. }
  114. public int ErrorTimer
  115. {
  116. get
  117. {
  118. if (_aiErrorTimer != null)
  119. {
  120. return (int)(_isFloatAioType ? _aiErrorTimer.FloatValue : _aiErrorTimer.Value);
  121. }
  122. return 0;
  123. }
  124. }
  125. public int CurrentSpeed
  126. {
  127. get
  128. {
  129. if (_aiCurrentSpeed != null)
  130. {
  131. return (int)(_isFloatAioType ? _aiCurrentSpeed.FloatValue : _aiCurrentSpeed.Value);
  132. }
  133. return 0;
  134. }
  135. }
  136. public int Voltage
  137. {
  138. get
  139. {
  140. if (_aiVoltage != null)
  141. {
  142. return (int)(_isFloatAioType ? _aiVoltage.FloatValue : _aiVoltage.Value);
  143. }
  144. return 0;
  145. }
  146. }
  147. public int Current
  148. {
  149. get
  150. {
  151. if (_aiCurrent != null)
  152. {
  153. return (int)(_isFloatAioType ? _aiCurrent.FloatValue : _aiCurrent.Value);
  154. }
  155. return 0;
  156. }
  157. }
  158. public bool IsWriteError => _diDataWriteError != null ? _diDataWriteError.Value : false;
  159. public bool IsReadError => _diDataReadError != null ? _diDataReadError.Value : false;
  160. #endregion
  161. public IoFFU(string module, XmlElement node, string ioModule = "")
  162. {
  163. base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  164. base.Name = node.GetAttribute("id");
  165. base.Display = node.GetAttribute("display");
  166. base.DeviceID = node.GetAttribute("schematicId");
  167. _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
  168. _diDataWriteDone = ParseDiNode("diDataWriteDone", node, ioModule);
  169. _diDataWriteError = ParseDiNode("diDataWriteError", node, ioModule);
  170. _diDataReadError = ParseDiNode("diDataReadError", node, ioModule);
  171. _aiGroupNumber = ParseAiNode("aiGroupNumber", node, ioModule);
  172. _aiAddressNumber = ParseAiNode("aiAddressNumber", node, ioModule);
  173. _aiSwitch = ParseAiNode("aiSwitch", node, ioModule);
  174. _aiSetSpeed = ParseAiNode("aiSetSpeed", node, ioModule);
  175. _aiMaxSpeed = ParseAiNode("aiMaxSpeed", node, ioModule);
  176. _aiReset = ParseAiNode("aiReset", node, ioModule);
  177. _aiErrorTimer = ParseAiNode("aiErrorTimer", node, ioModule);
  178. _aiCurrentSpeed = ParseAiNode("aiCurrentSpeed", node, ioModule);
  179. _aiVoltage = ParseAiNode("aiVoltage", node, ioModule);
  180. _aiCurrent = ParseAiNode("aiCurrent", node, ioModule);
  181. _aoSwitch = ParseAoNode("aoSwitch", node, ioModule);
  182. _aoSetSpeed = ParseAoNode("aoSetSpeed", node, ioModule);
  183. _aoReset = ParseAoNode("aoReset", node, ioModule);
  184. _doEnable = ParseDoNode("doEnable", node, ioModule);
  185. _doWriteCommand = ParseDoNode("doWriteCommand", node, ioModule);
  186. }
  187. public bool Initialize()
  188. {
  189. DATA.Subscribe($"{Module}.{Name}.GroupNumber", () => GroupNumber);
  190. DATA.Subscribe($"{Module}.{Name}.AddressNumber", () => AddressNumber);
  191. DATA.Subscribe($"{Module}.{Name}.IsSwitch", () => IsSwitch);
  192. DATA.Subscribe($"{Module}.{Name}.SetSpeed", () => SetSpeed);
  193. DATA.Subscribe($"{Module}.{Name}.MaxSpeed", () => MaxSpeed);
  194. DATA.Subscribe($"{Module}.{Name}.IsReset", () => IsReset);
  195. DATA.Subscribe($"{Module}.{Name}.ErrorTimer", () => ErrorTimer);
  196. DATA.Subscribe($"{Module}.{Name}.CurrentSpeed", () => CurrentSpeed);
  197. DATA.Subscribe($"{Module}.{Name}.Voltage", () => Voltage);
  198. DATA.Subscribe($"{Module}.{Name}.Current", () => Current);
  199. //OP.Subscribe($"{Module}.{Name}.SetRetract", (string cmd, object[] param) =>
  200. //{
  201. // SetRetract(out string reason);
  202. // return true;
  203. //});
  204. return true;
  205. }
  206. public void Monitor()
  207. {
  208. }
  209. public void Reset()
  210. {
  211. }
  212. public void Terminate()
  213. {
  214. }
  215. public bool Unload(out string reason)
  216. {
  217. reason = "";
  218. return true;
  219. }
  220. public bool Load(out string reason)
  221. {
  222. reason = "";
  223. return true;
  224. }
  225. public bool Init(out string reason)
  226. {
  227. reason = "";
  228. return true;
  229. }
  230. public bool Stop()
  231. {
  232. return true;
  233. }
  234. public void SetSwitch(bool isSwitch)
  235. {
  236. if (_aoSwitch != null)
  237. {
  238. _aoSwitch.FloatValue = isSwitch ? 1 : 0;
  239. }
  240. }
  241. }
  242. }