IoFFU.cs 12 KB

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