IoFFU.cs 12 KB

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