IoFFU.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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)
  195. {
  196. switch (_aiSwitch.FloatValue)
  197. {
  198. case 1:
  199. return FFUStatusEnum.OFF;
  200. case 2:
  201. return FFUStatusEnum.ON;
  202. default:
  203. break;
  204. }
  205. }
  206. if (_aiStatus != null)
  207. {
  208. switch (_aiStatus.FloatValue)
  209. {
  210. case 0:
  211. return FFUStatusEnum.OFF;
  212. case 2:
  213. case 3:
  214. return FFUStatusEnum.OFF;
  215. default:
  216. break;
  217. }
  218. }
  219. return FFUStatusEnum.Unknown;
  220. }
  221. public IoFFU(string module, XmlElement node, string ioModule = "")
  222. {
  223. base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  224. base.Name = node.GetAttribute("id");
  225. base.Display = node.GetAttribute("display");
  226. base.DeviceID = node.GetAttribute("schematicId");
  227. var scRootPath = string.IsNullOrEmpty(node.GetAttribute("scRootPath")) ? Module : node.GetAttribute("scRootPath");
  228. _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
  229. _diDataWriteDone = ParseDiNode("diDataWriteDone", node, ioModule);
  230. _diDataWriteError = ParseDiNode("diDataWriteError", node, ioModule);
  231. _diDataReadError = ParseDiNode("diDataReadError", node, ioModule);
  232. _aiGroupNumber = ParseAiNode("aiGroupNumber", node, ioModule);
  233. _aiAddressNumber = ParseAiNode("aiAddressNumber", node, ioModule);
  234. _aiSwitch = ParseAiNode("aiSwitch", node, ioModule);
  235. _aiSetSpeed = ParseAiNode("aiSetSpeed", node, ioModule);
  236. _aiMaxSpeed = ParseAiNode("aiMaxSpeed", node, ioModule);
  237. _aiReset = ParseAiNode("aiReset", node, ioModule);
  238. _aiErrorTimer = ParseAiNode("aiErrorTimer", node, ioModule);
  239. _aiCurrentSpeed = ParseAiNode("aiCurrentSpeed", node, ioModule);
  240. _aiVoltage = ParseAiNode("aiVoltage", node, ioModule);
  241. _aiCurrent = ParseAiNode("aiCurrent", node, ioModule);
  242. _aiStatus = ParseAiNode("aiStatus", node, ioModule);
  243. _aoSwitch = ParseAoNode("aoSwitch", node, ioModule);
  244. _aoSetSpeed = ParseAoNode("aoSetSpeed", node, ioModule);
  245. _aoReset = ParseAoNode("aoReset", node, ioModule);
  246. _doEnable = ParseDoNode("doEnable", node, ioModule);
  247. _doWriteCommand = ParseDoNode("doWriteCommand", node, ioModule);
  248. _scSetSpeed = ParseScNode("SetSpeed", node, ioModule, $"{scRootPath}.{Name}.SetSpeed");
  249. }
  250. public bool Initialize()
  251. {
  252. _scFFULSPEED = SC.GetConfigItem($"System.FFU.LSPEED");
  253. _scFFUHSPEED = SC.GetConfigItem($"System.FFU.HSPEED");
  254. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  255. DATA.Subscribe($"{Module}.{Name}.SetSpeed", () => SetSpeed);
  256. DATA.Subscribe($"{Module}.{Name}.CurrentSpeed", () => CurrentSpeed);
  257. //DATA.Subscribe($"{Module}.{Name}.GroupNumber", () => GroupNumber);
  258. //DATA.Subscribe($"{Module}.{Name}.AddressNumber", () => AddressNumber);
  259. //DATA.Subscribe($"{Module}.{Name}.IsSwitch", () => IsSwitch);
  260. //DATA.Subscribe($"{Module}.{Name}.MaxSpeed", () => MaxSpeed);
  261. //DATA.Subscribe($"{Module}.{Name}.IsReset", () => IsReset);
  262. //DATA.Subscribe($"{Module}.{Name}.ErrorTimer", () => ErrorTimer);
  263. //DATA.Subscribe($"{Module}.{Name}.Voltage", () => Voltage);
  264. //DATA.Subscribe($"{Module}.{Name}.Current", () => Current);
  265. OP.Subscribe($"{Module}.{Name}.SetCurrectSpeed", (string cmd, object[] param) =>
  266. {
  267. SetCurrectSpeed(param);
  268. return true;
  269. });
  270. //OP.Subscribe($"{Module}.{Name}.SetRetract", (string cmd, object[] param) =>
  271. //{
  272. // SetRetract(out string reason);
  273. // return true;
  274. //});
  275. InitSCAOData();
  276. return true;
  277. }
  278. private void InitSCAOData()
  279. {
  280. if (_scSetSpeed != null && _aoSetSpeed != null)
  281. {
  282. var scValue = _scSetSpeed.Value == null ? 0f : float.Parse(_scSetSpeed.Value.ToString());
  283. SetSpeedMethods(scValue);
  284. }
  285. }
  286. public bool SetCurrectSpeed(object[] param)
  287. {
  288. if (param != null && param.Length > 0)
  289. {
  290. float.TryParse(param[0].ToString(), out float value);
  291. SetSpeedMethods(value);
  292. }
  293. return true;
  294. }
  295. private void SetSpeedMethods(float value)
  296. {
  297. if (_aoSetSpeed != null)
  298. {
  299. _aoSetSpeed.FloatValue = value;
  300. if (_scSetSpeed != null)
  301. SC.SetItemValue(_scSetSpeed.PathName, value.ToString());
  302. }
  303. }
  304. public void Monitor()
  305. {
  306. }
  307. public void Reset()
  308. {
  309. }
  310. public void Terminate()
  311. {
  312. }
  313. public bool Unload(out string reason)
  314. {
  315. reason = "";
  316. return true;
  317. }
  318. public bool Load(out string reason)
  319. {
  320. reason = "";
  321. return true;
  322. }
  323. public bool Init(out string reason)
  324. {
  325. reason = "";
  326. return true;
  327. }
  328. public bool Stop()
  329. {
  330. return true;
  331. }
  332. public void SetSwitch(bool isSwitch)
  333. {
  334. if (_aoSwitch != null)
  335. {
  336. _aoSwitch.FloatValue = isSwitch ? 1 : 0;
  337. }
  338. if (_aoSwitch == null)
  339. {
  340. if (isSwitch)
  341. {
  342. if (string.IsNullOrEmpty(_scSetSpeed?.PathName)) return;//没有配置不做动作
  343. SetSpeedMethods(float.Parse(SC.GetStringValue(_scSetSpeed.PathName)));
  344. }
  345. else
  346. {
  347. SetSpeedMethods(0);
  348. }
  349. }
  350. }
  351. }
  352. }