TemperatureControllerControl.xaml.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. using Aitex.Core.Common;
  2. using LiveCharts;
  3. using MECF.Framework.Common.OperationCenter;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace CyberX8_Themes.UserControls
  19. {
  20. /// <summary>
  21. /// TemperatureControllerControl.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class TemperatureControllerControl : UserControl
  24. {
  25. #region 属性
  26. public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register(
  27. "ModuleName", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  28. /// <summary>
  29. /// 模块名称
  30. /// </summary>
  31. public string ModuleName
  32. {
  33. get
  34. {
  35. return (string)this.GetValue(ModuleNameProperty);
  36. }
  37. set
  38. {
  39. this.SetValue(ModuleNameProperty, value);
  40. }
  41. }
  42. public static readonly DependencyProperty ModuleTitleProperty = DependencyProperty.Register(
  43. "ModuleTitle", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  44. /// <summary>
  45. /// 标题
  46. /// </summary>
  47. public string ModuleTitle
  48. {
  49. get
  50. {
  51. return (string)this.GetValue(ModuleTitleProperty);
  52. }
  53. set
  54. {
  55. this.SetValue(ModuleTitleProperty, value);
  56. }
  57. }
  58. public static readonly DependencyProperty DisableStatusProperty = DependencyProperty.Register(
  59. "DisableStatus", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  60. /// <summary>
  61. /// 可用性状态
  62. /// </summary>
  63. public string DisableStatus
  64. {
  65. get
  66. {
  67. return (string)this.GetValue(DisableStatusProperty);
  68. }
  69. set
  70. {
  71. this.SetValue(DisableStatusProperty, value);
  72. }
  73. }
  74. public static readonly DependencyProperty IsEnableProperty = DependencyProperty.Register(
  75. "IsEnable", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  76. /// <summary>
  77. ///IsEnable
  78. /// </summary>
  79. public bool IsEnable
  80. {
  81. get
  82. {
  83. return (bool)this.GetValue(IsEnableProperty);
  84. }
  85. set
  86. {
  87. this.SetValue(IsEnableProperty, value);
  88. }
  89. }
  90. public static readonly DependencyProperty IsApplyEnableProperty = DependencyProperty.Register(
  91. "IsApplyEnable", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  92. /// <summary>
  93. ///IsApplyEnable
  94. /// </summary>
  95. public bool IsApplyEnable
  96. {
  97. get
  98. {
  99. return (bool)this.GetValue(IsApplyEnableProperty);
  100. }
  101. set
  102. {
  103. this.SetValue(IsApplyEnableProperty, value);
  104. }
  105. }
  106. public static readonly DependencyProperty StatusProperty = DependencyProperty.Register(
  107. "Status", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata("Normal", FrameworkPropertyMetadataOptions.AffectsRender));
  108. /// <summary>
  109. /// 状态
  110. /// </summary>
  111. public string Status
  112. {
  113. get
  114. {
  115. return (string)this.GetValue(StatusProperty);
  116. }
  117. set
  118. {
  119. this.SetValue(StatusProperty, value);
  120. }
  121. }
  122. public static readonly DependencyProperty AutoStatusProperty = DependencyProperty.Register(
  123. "AutoStatus", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata("Auto", FrameworkPropertyMetadataOptions.AffectsRender));
  124. /// <summary>
  125. /// 自动性状态
  126. /// </summary>
  127. public string AutoStatus
  128. {
  129. get
  130. {
  131. return (string)this.GetValue(AutoStatusProperty);
  132. }
  133. set
  134. {
  135. this.SetValue(AutoStatusProperty, value);
  136. }
  137. }
  138. public static readonly DependencyProperty IsConnectedProperty = DependencyProperty.Register(
  139. "IsConnected", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  140. /// <summary>
  141. /// IsConnected
  142. /// </summary>
  143. public bool IsConnected
  144. {
  145. get
  146. {
  147. return (bool)this.GetValue(IsConnectedProperty);
  148. }
  149. set
  150. {
  151. this.SetValue(IsConnectedProperty, value);
  152. }
  153. }
  154. public static readonly DependencyProperty TemperatureReachedProperty = DependencyProperty.Register(
  155. "TemperatureReached", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  156. /// <summary>
  157. /// TemperatureReached
  158. /// </summary>
  159. public bool TemperatureReached
  160. {
  161. get
  162. {
  163. return (bool)this.GetValue(TemperatureReachedProperty);
  164. }
  165. set
  166. {
  167. this.SetValue(TemperatureReachedProperty, value);
  168. }
  169. }
  170. public static readonly DependencyProperty DeltaExceededProperty = DependencyProperty.Register(
  171. "DeltaExceeded", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  172. /// <summary>
  173. /// DeltaExceeded
  174. /// </summary>
  175. public bool DeltaExceeded
  176. {
  177. get
  178. {
  179. return (bool)this.GetValue(DeltaExceededProperty);
  180. }
  181. set
  182. {
  183. this.SetValue(DeltaExceededProperty, value);
  184. }
  185. }
  186. #region Alarm
  187. public static readonly DependencyProperty AlarmDataProperty = DependencyProperty.Register(
  188. "AlarmData", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(AlarmDataChanged)));
  189. /// <summary>
  190. /// AlarmData
  191. /// </summary>
  192. public string AlarmData
  193. {
  194. get
  195. {
  196. return (string)this.GetValue(AlarmDataProperty);
  197. }
  198. set
  199. {
  200. this.SetValue(AlarmDataProperty, value);
  201. }
  202. }
  203. private static void AlarmDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  204. {
  205. if (e.NewValue != null)
  206. {
  207. string alarm = (string)e.NewValue;
  208. string[] strAry = alarm.Split('-');
  209. int result = 0;
  210. if (strAry.Length == 12)
  211. {
  212. result += SetAlarmProperty(d, HighTempCutoffProperty, strAry[3] == "1");
  213. result += SetAlarmProperty(d, LowTempCutoffProperty, strAry[2] == "1");
  214. result += SetAlarmProperty(d, FanProperty, strAry[1] == "1");
  215. result += SetAlarmProperty(d, OutputFailureProperty, strAry[0] == "1");
  216. result += SetAlarmProperty(d, TempLimitWarnProperty, strAry[7] == "1");
  217. result += SetAlarmProperty(d, RemoteOffProperty, strAry[6] == "1");
  218. result += SetAlarmProperty(d, ThermostatProperty, strAry[5] == "1");
  219. result += SetAlarmProperty(d, PowerFailureProperty, strAry[4] == "1");
  220. result += SetAlarmProperty(d, ExtSensorFailureProperty, strAry[11] == "1");
  221. result += SetAlarmProperty(d, IntSensorFailureProperty, strAry[10] == "1");
  222. result += SetAlarmProperty(d, AutoTuningProperty, strAry[9] == "1");
  223. result += SetAlarmProperty(d, LeakProperty, strAry[8] == "1");
  224. //if (result == 0)
  225. //{
  226. // d.SetValue(StatusProperty, "Normal");
  227. //}
  228. //else
  229. //{
  230. // d.SetValue(StatusProperty, "Error");
  231. //}
  232. }
  233. }
  234. }
  235. private static int SetAlarmProperty(DependencyObject d,DependencyProperty dependency, bool value)
  236. {
  237. d.SetValue(dependency, value);
  238. return value ? 1 : 0;
  239. }
  240. public static readonly DependencyProperty AutoTuningProperty = DependencyProperty.Register(
  241. "AutoTuning", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  242. /// <summary>
  243. /// AutoTuning
  244. /// </summary>
  245. public bool AutoTuning
  246. {
  247. get
  248. {
  249. return (bool)this.GetValue(AutoTuningProperty);
  250. }
  251. set
  252. {
  253. this.SetValue(AutoTuningProperty, value);
  254. }
  255. }
  256. public static readonly DependencyProperty FanProperty = DependencyProperty.Register(
  257. "Fan", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  258. /// <summary>
  259. /// Fan
  260. /// </summary>
  261. public bool Fan
  262. {
  263. get
  264. {
  265. return (bool)this.GetValue(FanProperty);
  266. }
  267. set
  268. {
  269. this.SetValue(FanProperty, value);
  270. }
  271. }
  272. public static readonly DependencyProperty RemoteOffProperty = DependencyProperty.Register(
  273. "RemoteOff", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  274. /// <summary>
  275. /// RemoteOff
  276. /// </summary>
  277. public bool RemoteOff
  278. {
  279. get
  280. {
  281. return (bool)this.GetValue(RemoteOffProperty);
  282. }
  283. set
  284. {
  285. this.SetValue(RemoteOffProperty, value);
  286. }
  287. }
  288. public static readonly DependencyProperty ExtSensorFailureProperty = DependencyProperty.Register(
  289. "ExtSensorFailure", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  290. /// <summary>
  291. /// ExtSensorFailure
  292. /// </summary>
  293. public bool ExtSensorFailure
  294. {
  295. get
  296. {
  297. return (bool)this.GetValue(ExtSensorFailureProperty);
  298. }
  299. set
  300. {
  301. this.SetValue(ExtSensorFailureProperty, value);
  302. }
  303. }
  304. public static readonly DependencyProperty HighTempCutoffProperty = DependencyProperty.Register(
  305. "HighTempCutoff", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  306. /// <summary>
  307. /// HighTempCutoff
  308. /// </summary>
  309. public bool HighTempCutoff
  310. {
  311. get
  312. {
  313. return (bool)this.GetValue(HighTempCutoffProperty);
  314. }
  315. set
  316. {
  317. this.SetValue(HighTempCutoffProperty, value);
  318. }
  319. }
  320. public static readonly DependencyProperty LowTempCutoffProperty = DependencyProperty.Register(
  321. "LowTempCutoff", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  322. /// <summary>
  323. /// LowTempCutoff
  324. /// </summary>
  325. public bool LowTempCutoff
  326. {
  327. get
  328. {
  329. return (bool)this.GetValue(LowTempCutoffProperty);
  330. }
  331. set
  332. {
  333. this.SetValue(LowTempCutoffProperty, value);
  334. }
  335. }
  336. public static readonly DependencyProperty OutputFailureProperty = DependencyProperty.Register(
  337. "OutputFailure", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  338. /// <summary>
  339. /// OutputFailure
  340. /// </summary>
  341. public bool OutputFailure
  342. {
  343. get
  344. {
  345. return (bool)this.GetValue(OutputFailureProperty);
  346. }
  347. set
  348. {
  349. this.SetValue(OutputFailureProperty, value);
  350. }
  351. }
  352. public static readonly DependencyProperty IntSensorFailureProperty = DependencyProperty.Register(
  353. "IntSensorFailure", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  354. /// <summary>
  355. /// IntSensorFailure
  356. /// </summary>
  357. public bool IntSensorFailure
  358. {
  359. get
  360. {
  361. return (bool)this.GetValue(IntSensorFailureProperty);
  362. }
  363. set
  364. {
  365. this.SetValue(IntSensorFailureProperty, value);
  366. }
  367. }
  368. public static readonly DependencyProperty TempLimitWarnProperty = DependencyProperty.Register(
  369. "TempLimitWarn", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  370. /// <summary>
  371. /// TempLimitWarn
  372. /// </summary>
  373. public bool TempLimitWarn
  374. {
  375. get
  376. {
  377. return (bool)this.GetValue(TempLimitWarnProperty);
  378. }
  379. set
  380. {
  381. this.SetValue(TempLimitWarnProperty, value);
  382. }
  383. }
  384. public static readonly DependencyProperty PowerFailureProperty = DependencyProperty.Register(
  385. "PowerFailure", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  386. /// <summary>
  387. /// PowerFailure
  388. /// </summary>
  389. public bool PowerFailure
  390. {
  391. get
  392. {
  393. return (bool)this.GetValue(PowerFailureProperty);
  394. }
  395. set
  396. {
  397. this.SetValue(PowerFailureProperty, value);
  398. }
  399. }
  400. public static readonly DependencyProperty LeakProperty = DependencyProperty.Register(
  401. "Leak", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  402. /// <summary>
  403. /// Leak
  404. /// </summary>
  405. public bool Leak
  406. {
  407. get
  408. {
  409. return (bool)this.GetValue(LeakProperty);
  410. }
  411. set
  412. {
  413. this.SetValue(LeakProperty, value);
  414. }
  415. }
  416. public static readonly DependencyProperty ThermostatProperty = DependencyProperty.Register(
  417. "Thermostat", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  418. /// <summary>
  419. /// Thermostat
  420. /// </summary>
  421. public bool Thermostat
  422. {
  423. get
  424. {
  425. return (bool)this.GetValue(ThermostatProperty);
  426. }
  427. set
  428. {
  429. this.SetValue(ThermostatProperty, value);
  430. }
  431. }
  432. #endregion
  433. public static readonly DependencyProperty SetPointValueProperty = DependencyProperty.Register(
  434. "SetPointValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
  435. /// <summary>
  436. /// SetPointValue
  437. /// </summary>
  438. public double SetPointValue
  439. {
  440. get
  441. {
  442. return (double)this.GetValue(SetPointValueProperty);
  443. }
  444. set
  445. {
  446. this.SetValue(SetPointValueProperty, value);
  447. }
  448. }
  449. public static readonly DependencyProperty SetPointMinValueProperty = DependencyProperty.Register(
  450. "SetPointMinValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
  451. /// <summary>
  452. /// SetPointMinValue
  453. /// </summary>
  454. public double SetPointMinValue
  455. {
  456. get
  457. {
  458. return (double)this.GetValue(SetPointMinValueProperty);
  459. }
  460. set
  461. {
  462. this.SetValue(SetPointMinValueProperty, value);
  463. }
  464. }
  465. public static readonly DependencyProperty SetPointMaxValueProperty = DependencyProperty.Register(
  466. "SetPointMaxValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
  467. /// <summary>
  468. /// SetPointMaxValue
  469. /// </summary>
  470. public double SetPointMaxValue
  471. {
  472. get
  473. {
  474. return (double)this.GetValue(SetPointMaxValueProperty);
  475. }
  476. set
  477. {
  478. this.SetValue(SetPointMaxValueProperty, value);
  479. }
  480. }
  481. public static readonly DependencyProperty TargetTemperatureValueProperty = DependencyProperty.Register(
  482. "TargetTemperatureValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
  483. /// <summary>
  484. /// TargetTemperatureValue
  485. /// </summary>
  486. public double TargetTemperatureValue
  487. {
  488. get
  489. {
  490. return (double)this.GetValue(TargetTemperatureValueProperty);
  491. }
  492. set
  493. {
  494. this.SetValue(TargetTemperatureValueProperty, value);
  495. }
  496. }
  497. public static readonly DependencyProperty ReserviorValueProperty = DependencyProperty.Register(
  498. "ReserviorValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
  499. /// <summary>
  500. /// ReserviorValue
  501. /// </summary>
  502. public double ReserviorValue
  503. {
  504. get
  505. {
  506. return (double)this.GetValue(ReserviorValueProperty);
  507. }
  508. set
  509. {
  510. this.SetValue(ReserviorValueProperty, value);
  511. }
  512. }
  513. public static readonly DependencyProperty HeatExchangerValueProperty = DependencyProperty.Register(
  514. "HeatExchangerValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
  515. /// <summary>
  516. /// HeatExchangerValue
  517. /// </summary>
  518. public double HeatExchangerValue
  519. {
  520. get
  521. {
  522. return (double)this.GetValue(HeatExchangerValueProperty);
  523. }
  524. set
  525. {
  526. this.SetValue(HeatExchangerValueProperty, value);
  527. }
  528. }
  529. #region 曲线
  530. public static readonly DependencyProperty ReserviorSeriesProperty = DependencyProperty.Register("ReserviorSeries", typeof(ChartValues<double>), typeof(TemperatureControllerControl),
  531. new FrameworkPropertyMetadata(new ChartValues<double>(), FrameworkPropertyMetadataOptions.AffectsRender));
  532. /// <summary>
  533. /// ReserviorSeries
  534. /// </summary>
  535. public ChartValues<double> ReserviorSeries
  536. {
  537. get
  538. {
  539. return (ChartValues<double>)this.GetValue(ReserviorSeriesProperty);
  540. }
  541. set
  542. {
  543. this.SetValue(ReserviorSeriesProperty, value);
  544. }
  545. }
  546. public static readonly DependencyProperty HeatExchangerSeriesProperty = DependencyProperty.Register("HeatExchangerSeries", typeof(ChartValues<double>), typeof(TemperatureControllerControl),
  547. new FrameworkPropertyMetadata(new ChartValues<double>(), FrameworkPropertyMetadataOptions.AffectsRender));
  548. /// <summary>
  549. /// HeatExchangerSeries
  550. /// </summary>
  551. public ChartValues<double> HeatExchangerSeries
  552. {
  553. get
  554. {
  555. return (ChartValues<double>)this.GetValue(HeatExchangerSeriesProperty);
  556. }
  557. set
  558. {
  559. this.SetValue(HeatExchangerSeriesProperty, value);
  560. }
  561. }
  562. public static readonly DependencyProperty LabelSeriesProperty = DependencyProperty.Register("LabelSeries", typeof(ChartValues<string>), typeof(TemperatureControllerControl),
  563. new FrameworkPropertyMetadata(new ChartValues<string>(), FrameworkPropertyMetadataOptions.AffectsRender));
  564. /// <summary>
  565. /// LabelSeries
  566. /// </summary>
  567. public ChartValues<string> LabelSeries
  568. {
  569. get
  570. {
  571. return (ChartValues<string>)this.GetValue(LabelSeriesProperty);
  572. }
  573. set
  574. {
  575. this.SetValue(LabelSeriesProperty, value);
  576. }
  577. }
  578. #endregion
  579. #endregion
  580. /// <summary>
  581. /// 构造函数
  582. /// </summary>
  583. public TemperatureControllerControl()
  584. {
  585. InitializeComponent();
  586. }
  587. #region Button Click
  588. private void Disable_Click(object sender, RoutedEventArgs e)
  589. {
  590. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Disable");
  591. }
  592. private void Enable_Click(object sender, RoutedEventArgs e)
  593. {
  594. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Enable");
  595. }
  596. private void Apply_Click(object sender, RoutedEventArgs e)
  597. {
  598. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Apply", SetPointValue, SetPointMinValue,SetPointMaxValue);
  599. }
  600. #endregion
  601. }
  602. }