IoFFU.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Device.Unit;
  4. using Aitex.Core.RT.IOCore;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using MECF.Framework.Common.CommonData.DeviceData;
  8. using MECF.Framework.Common.Equipment;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Xml;
  15. using static MECF.Framework.Common.CommonData.DeviceData.AITFFUData;
  16. namespace FurnaceRT.Devices
  17. {
  18. public class IoFFU : BaseDevice, IDevice
  19. {
  20. #region Filed
  21. private DIAccessor _diDataWriteDone;
  22. private DIAccessor _diDataWriteError;
  23. private DIAccessor _diDataReadError;
  24. private AIAccessor _aiGroupNumber;
  25. private AIAccessor _aiAddressNumber;
  26. private AIAccessor _aiSwitch;
  27. private AIAccessor _aiSetSpeed;
  28. private AIAccessor _aiMaxSpeed;
  29. private AIAccessor _aiReset;
  30. private AIAccessor _aiErrorTimer;
  31. private AIAccessor _aiCurrentSpeed;
  32. private AIAccessor _aiVoltage;
  33. private AIAccessor _aiCurrent;
  34. private AOAccessor _aoSwitch;
  35. private AOAccessor _aoSetSpeed;
  36. private AOAccessor _aoReset;
  37. private DOAccessor _doEnable;
  38. private DOAccessor _doWriteCommand;
  39. private SCConfigItem _scFFULSPEED;
  40. private SCConfigItem _scFFUHSPEED;
  41. protected SCConfigItem _scSetSpeed;
  42. private bool _isFloatAioType = false;
  43. #endregion
  44. #region Property
  45. public int GroupNumber
  46. {
  47. get
  48. {
  49. if (_aiGroupNumber != null)
  50. {
  51. return (int)(_isFloatAioType ? _aiGroupNumber.FloatValue : _aiGroupNumber.Value);
  52. }
  53. return 0;
  54. }
  55. }
  56. public int AddressNumber
  57. {
  58. get
  59. {
  60. if (_aiAddressNumber != null)
  61. {
  62. return (int)(_isFloatAioType ? _aiAddressNumber.FloatValue : _aiAddressNumber.Value);
  63. }
  64. return 0;
  65. }
  66. }
  67. public bool IsEnable
  68. {
  69. get
  70. {
  71. if (_aoSwitch != null)
  72. return _aoSwitch.FloatValue > 0;
  73. return false;
  74. }
  75. }
  76. public bool IsSwitch
  77. {
  78. get
  79. {
  80. if (_aiSwitch != null)
  81. {
  82. var temp = (int)(_isFloatAioType ? _aiSwitch.FloatValue : _aiSwitch.Value);
  83. return temp == 0 ? false : true;
  84. }
  85. return false;
  86. }
  87. }
  88. public int SetSpeed
  89. {
  90. get
  91. {
  92. if (_aiSetSpeed != null)
  93. {
  94. return (int)(_isFloatAioType ? _aiSetSpeed.FloatValue : _aiSetSpeed.Value);
  95. }
  96. return 0;
  97. }
  98. }
  99. public int MaxSpeed
  100. {
  101. get
  102. {
  103. if (_aiMaxSpeed != null)
  104. {
  105. return (int)(_isFloatAioType ? _aiMaxSpeed.FloatValue : _aiMaxSpeed.Value);
  106. }
  107. return 0;
  108. }
  109. }
  110. public bool IsReset
  111. {
  112. get
  113. {
  114. if (_aiReset != null)
  115. {
  116. var temp = (int)(_isFloatAioType ? _aiReset.FloatValue : _aiReset.Value);
  117. return temp == 0 ? false : true;
  118. }
  119. return false;
  120. }
  121. }
  122. public int ErrorTimer
  123. {
  124. get
  125. {
  126. if (_aiErrorTimer != null)
  127. {
  128. return (int)(_isFloatAioType ? _aiErrorTimer.FloatValue : _aiErrorTimer.Value);
  129. }
  130. return 0;
  131. }
  132. }
  133. public int CurrentSpeed
  134. {
  135. get
  136. {
  137. if (_aiCurrentSpeed != null)
  138. {
  139. return (int)(_isFloatAioType ? _aiCurrentSpeed.FloatValue : _aiCurrentSpeed.Value);
  140. }
  141. return 0;
  142. }
  143. }
  144. public int Voltage
  145. {
  146. get
  147. {
  148. if (_aiVoltage != null)
  149. {
  150. return (int)(_isFloatAioType ? _aiVoltage.FloatValue : _aiVoltage.Value);
  151. }
  152. return 0;
  153. }
  154. }
  155. public int Current
  156. {
  157. get
  158. {
  159. if (_aiCurrent != null)
  160. {
  161. return (int)(_isFloatAioType ? _aiCurrent.FloatValue : _aiCurrent.Value);
  162. }
  163. return 0;
  164. }
  165. }
  166. public bool IsWriteError => _diDataWriteError != null ? _diDataWriteError.Value : false;
  167. public bool IsReadError => _diDataReadError != null ? _diDataReadError.Value : false;
  168. #endregion
  169. private AITFFUData DeviceData
  170. {
  171. get
  172. {
  173. AITFFUData data = new AITFFUData()
  174. {
  175. SetPoint = _aoSetSpeed != null ? _aoSetSpeed.FloatValue : 0,
  176. DisplayName = Name,
  177. IsSwitchOn = GetFFUStatusEnum() == FFUStatusEnum.ON,
  178. Feedback = CurrentSpeed,
  179. Max = _scFFUHSPEED != null ? Convert.ToInt32((double)_scFFUHSPEED.Value) : 0,
  180. Min = _scFFULSPEED != null ? Convert.ToInt32((double)_scFFULSPEED.Value) : 0
  181. };
  182. return data;
  183. }
  184. }
  185. private FFUStatusEnum GetFFUStatusEnum()
  186. {
  187. if (_aiSwitch == null)
  188. return FFUStatusEnum.Unknown;
  189. if (_aiSwitch.FloatValue == 1)
  190. return FFUStatusEnum.OFF;
  191. if (_aiSwitch.FloatValue == 2)
  192. return FFUStatusEnum.ON;
  193. return FFUStatusEnum.Unknown;
  194. }
  195. public IoFFU(string module, XmlElement node, string ioModule = "")
  196. {
  197. base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  198. base.Name = node.GetAttribute("id");
  199. base.Display = node.GetAttribute("display");
  200. base.DeviceID = node.GetAttribute("schematicId");
  201. _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
  202. _diDataWriteDone = ParseDiNode("diDataWriteDone", node, ioModule);
  203. _diDataWriteError = ParseDiNode("diDataWriteError", node, ioModule);
  204. _diDataReadError = ParseDiNode("diDataReadError", node, ioModule);
  205. _aiGroupNumber = ParseAiNode("aiGroupNumber", node, ioModule);
  206. _aiAddressNumber = ParseAiNode("aiAddressNumber", node, ioModule);
  207. _aiSwitch = ParseAiNode("aiSwitch", node, ioModule);
  208. _aiSetSpeed = ParseAiNode("aiSetSpeed", node, ioModule);
  209. _aiMaxSpeed = ParseAiNode("aiMaxSpeed", node, ioModule);
  210. _aiReset = ParseAiNode("aiReset", node, ioModule);
  211. _aiErrorTimer = ParseAiNode("aiErrorTimer", node, ioModule);
  212. _aiCurrentSpeed = ParseAiNode("aiCurrentSpeed", node, ioModule);
  213. _aiVoltage = ParseAiNode("aiVoltage", node, ioModule);
  214. _aiCurrent = ParseAiNode("aiCurrent", node, ioModule);
  215. _aoSwitch = ParseAoNode("aoSwitch", node, ioModule);
  216. _aoSetSpeed = ParseAoNode("aoSetSpeed", node, ioModule);
  217. _aoReset = ParseAoNode("aoReset", node, ioModule);
  218. _doEnable = ParseDoNode("doEnable", node, ioModule);
  219. _doWriteCommand = ParseDoNode("doWriteCommand", node, ioModule);
  220. }
  221. public bool Initialize()
  222. {
  223. _scFFULSPEED = SC.GetConfigItem($"System.FFU.LSPEED");
  224. _scFFUHSPEED = SC.GetConfigItem($"System.FFU.HSPEED");
  225. _scSetSpeed = SC.GetConfigItem($"System.FFU.{Name}.SetSpeed");
  226. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  227. DATA.Subscribe($"{Module}.{Name}.GroupNumber", () => GroupNumber);
  228. DATA.Subscribe($"{Module}.{Name}.AddressNumber", () => AddressNumber);
  229. DATA.Subscribe($"{Module}.{Name}.IsSwitch", () => IsSwitch);
  230. DATA.Subscribe($"{Module}.{Name}.SetSpeed", () => SetSpeed);
  231. DATA.Subscribe($"{Module}.{Name}.MaxSpeed", () => MaxSpeed);
  232. DATA.Subscribe($"{Module}.{Name}.IsReset", () => IsReset);
  233. DATA.Subscribe($"{Module}.{Name}.ErrorTimer", () => ErrorTimer);
  234. DATA.Subscribe($"{Module}.{Name}.CurrentSpeed", () => CurrentSpeed);
  235. DATA.Subscribe($"{Module}.{Name}.Voltage", () => Voltage);
  236. DATA.Subscribe($"{Module}.{Name}.Current", () => Current);
  237. OP.Subscribe($"{Module}.{Name}.SetCurrectSpeed", (string cmd, object[] param) =>
  238. {
  239. SetCurrectSpeed(param);
  240. return true;
  241. });
  242. //OP.Subscribe($"{Module}.{Name}.SetRetract", (string cmd, object[] param) =>
  243. //{
  244. // SetRetract(out string reason);
  245. // return true;
  246. //});
  247. return true;
  248. }
  249. public bool SetCurrectSpeed(object[] param)
  250. {
  251. if (param != null && param.Length > 0)
  252. {
  253. float.TryParse(param[0].ToString(), out float value);
  254. if (_aoSetSpeed != null)
  255. {
  256. _aoSetSpeed.FloatValue = value;
  257. if (_scSetSpeed != null)
  258. SC.SetItemValue(_scSetSpeed.PathName, param[0].ToString());
  259. }
  260. }
  261. return true;
  262. }
  263. public void Monitor()
  264. {
  265. }
  266. public void Reset()
  267. {
  268. }
  269. public void Terminate()
  270. {
  271. }
  272. public bool Unload(out string reason)
  273. {
  274. reason = "";
  275. return true;
  276. }
  277. public bool Load(out string reason)
  278. {
  279. reason = "";
  280. return true;
  281. }
  282. public bool Init(out string reason)
  283. {
  284. reason = "";
  285. return true;
  286. }
  287. public bool Stop()
  288. {
  289. return true;
  290. }
  291. public void SetSwitch(bool isSwitch)
  292. {
  293. if (_aoSwitch != null)
  294. {
  295. _aoSwitch.FloatValue = isSwitch ? 1 : 0;
  296. }
  297. }
  298. }
  299. }