终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

270 lines
12 KiB

  1. using BPASmartClient.Academy._50L;
  2. using BPASmartClient.CustomResource.UserControls.MessageShow;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Controls.Primitives;
  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 BPASmartClient.Academy.View
  19. {
  20. /// <summary>
  21. /// ReactionKettle500LView.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class ReactionKettle50LView : UserControl
  24. {
  25. private volatile static ReactionKettle50LView _Instance;
  26. public static ReactionKettle50LView GetInstance => _Instance ?? (_Instance = new ReactionKettle50LView());
  27. private ReactionKettle50LView()
  28. {
  29. InitializeComponent();
  30. this.DataContext = ReactionKettle50LViewModel.GetInstance;
  31. }
  32. private void open_Click(object sender, RoutedEventArgs e)
  33. {
  34. if (sender is ButtonBase button && !string.IsNullOrWhiteSpace(button.Tag.ToString().Trim()))
  35. {
  36. if (PlcControl.GetInstance.IsConnect)
  37. {
  38. var tag = button.Tag.ToString().Trim();
  39. BoolAddEnum addr=(BoolAddEnum)Enum.Parse(typeof(BoolAddEnum), tag);
  40. var result= PlcControl.GetInstance.Write(addr, true);
  41. if (result !=null && result.IsSuccess)
  42. {
  43. Notify(EnumPromptType.Success, $"写入成功", $"成功:写入{tag}:True");
  44. }
  45. else
  46. {
  47. Notify(EnumPromptType.Error, $"写入失败", $"失败:写入{tag}:True\n{result.Message}");
  48. }
  49. }
  50. else
  51. {
  52. Notify(EnumPromptType.Error, "失败", "设备未连接");
  53. }
  54. }
  55. }
  56. private void close_Click(object sender, RoutedEventArgs e)
  57. {
  58. if (sender is ButtonBase button && !string.IsNullOrWhiteSpace(button.Tag.ToString().Trim()))
  59. {
  60. if (PlcControl.GetInstance.IsConnect)
  61. {
  62. var tag = button.Tag.ToString().Trim();
  63. BoolAddEnum addr = (BoolAddEnum)Enum.Parse(typeof(BoolAddEnum), tag);
  64. var result = PlcControl.GetInstance.Write(addr, false);
  65. if (result != null && result.IsSuccess)
  66. {
  67. Notify(EnumPromptType.Success, $"写入成功", $"成功:写入{tag}:False");
  68. }
  69. else
  70. {
  71. Notify(EnumPromptType.Error, $"写入失败", $"失败:写入{tag}:False\n{result.Message}");
  72. }
  73. }
  74. else
  75. {
  76. Notify(EnumPromptType.Error, "失败", "设备未连接");
  77. }
  78. }
  79. }
  80. private void Notify(EnumPromptType promptType,string title,string msg)
  81. {
  82. App.Current.Dispatcher.Invoke(new Action(() =>
  83. {
  84. NoticeDemoViewModel.OpenMsg(promptType, App.Current.MainWindow, title, msg);
  85. }));
  86. MessageNotify.GetInstance.ShowRunLog($"人工介入:"+msg);
  87. }
  88. private void auto_click(object sender, RoutedEventArgs e)
  89. {
  90. }
  91. private void TempSet_CLick(object sender, RoutedEventArgs e)
  92. {
  93. if (sender is ButtonBase button && !string.IsNullOrWhiteSpace(button.Tag.ToString().Trim()))
  94. {
  95. if (PlcControl.GetInstance.IsConnect)
  96. {
  97. var tag = button.Tag.ToString().Trim();
  98. switch (tag)
  99. {
  100. case "反应釜升温":
  101. if (float.TryParse(reactorHeatUpTemp.Text,out float reactorHeatTemp) && reactorHeatTemp <= 200f && reactorHeatTemp >= 0f)
  102. {
  103. PlcControl.GetInstance.Write(FloatAddEnum.反应釜设定升温温度, MathF.Round(reactorHeatTemp, 2)).OnSuccess((s) =>
  104. {
  105. PlcControl.GetInstance.Write(BoolAddEnum.反应釜升温, true).OnSuccess((s2) =>
  106. {
  107. Notify(EnumPromptType.Success, $"写入成功", $"成功:写入反应釜升温:{reactorHeatTemp}");
  108. }).OnFailure((s) => {
  109. Notify(EnumPromptType.Error, "写入失败", $"{s.Message}。");
  110. });
  111. }).OnFailure((s) => {
  112. Notify(EnumPromptType.Error, "写入失败", $"{s.Message}。");
  113. });
  114. }
  115. else
  116. {
  117. Notify(EnumPromptType.Error, "写入失败", $"输入的温度不是一个有效的数字,范围0-200℃。");
  118. }
  119. break;
  120. case "反应釜降温":
  121. if (float.TryParse(reactorCoolDownTemp.Text, out float reactorCoolTemp) && reactorCoolTemp<=200f && reactorCoolTemp>=0f)
  122. {
  123. PlcControl.GetInstance.Write(FloatAddEnum.反应釜设定降温温度, MathF.Round(reactorCoolTemp, 2)).OnSuccess((s) =>
  124. {
  125. PlcControl.GetInstance.Write(BoolAddEnum.反应釜降温, true).OnSuccess((s2) =>
  126. {
  127. Notify(EnumPromptType.Success, $"写入成功", $"成功:写入反应釜降温:{reactorCoolTemp}");
  128. }).OnFailure((s) => {
  129. Notify(EnumPromptType.Error, "写入失败", $"{s.Message}。");
  130. });
  131. }).OnFailure((s) => {
  132. Notify(EnumPromptType.Error, "写入失败", $"{s.Message}。");
  133. });
  134. }
  135. else
  136. {
  137. Notify(EnumPromptType.Error, "写入失败", $"输入的温度不是一个有效的数字,范围0-200℃。");
  138. }
  139. break;
  140. case "冷凝水罐降温":
  141. if (float.TryParse(ColdWaterTankCoolDownTemp.Text, out float CWTTemp) && CWTTemp <= 200f && CWTTemp >= 0f)
  142. {
  143. PlcControl.GetInstance.Write(FloatAddEnum.冷凝水罐设定降温温度, MathF.Round(CWTTemp, 2)).OnSuccess((s) =>
  144. {
  145. PlcControl.GetInstance.Write(BoolAddEnum.冷凝水罐降温, true).OnSuccess((s2) =>
  146. {
  147. Notify(EnumPromptType.Success, $"写入成功", $"成功:写入冷凝水罐降温:{CWTTemp}");
  148. }).OnFailure((s) => {
  149. Notify(EnumPromptType.Error, "写入失败", $"{s.Message}。");
  150. });
  151. }).OnFailure((s) => {
  152. Notify(EnumPromptType.Error, "写入失败", $"{s.Message}。");
  153. });
  154. }
  155. else
  156. {
  157. Notify(EnumPromptType.Error, "写入失败", $"输入的温度不是一个有效的数字,范围0-200℃。");
  158. }
  159. break;
  160. }
  161. }
  162. else
  163. {
  164. Notify(EnumPromptType.Error, "失败", "设备未连接");
  165. }
  166. }
  167. }
  168. private void TempCLose_CLick(object sender, RoutedEventArgs e)
  169. {
  170. close_Click(sender, e);
  171. }
  172. private void TempAdjust_Click(object sender, RoutedEventArgs e)
  173. {
  174. if (PlcControl.GetInstance.IsConnect)
  175. {
  176. if (float.TryParse(reactorTempAdjustValue.Text, out float reactorAdjustTemp))
  177. {
  178. PlcControl.GetInstance.Write(FloatAddEnum.反应釜温度校准, MathF.Round(reactorAdjustTemp, 2)).OnSuccess((s) =>
  179. {
  180. Notify(EnumPromptType.Success, $"写入校准成功", $"成功:写入反应釜温度校准:{reactorAdjustTemp}");
  181. }).OnFailure((s) =>
  182. {
  183. Notify(EnumPromptType.Error, "写入校准失败", $"{s.Message}。");
  184. });
  185. }
  186. else
  187. {
  188. Notify(EnumPromptType.Error, "写入校准失败", $"【反应釜温度校准】输入的温度不是一个有效的数字");
  189. }
  190. if (float.TryParse(coldWaterTankTempAdjustValue.Text, out float CWTAdjustValue))
  191. {
  192. PlcControl.GetInstance.Write(FloatAddEnum.冷凝水罐温度校准, MathF.Round(CWTAdjustValue, 2)).OnSuccess((s) =>
  193. {
  194. Notify(EnumPromptType.Success, $"写入校准成功", $"成功:写入冷凝水罐温度校准:{CWTAdjustValue}");
  195. }).OnFailure((s) =>
  196. {
  197. Notify(EnumPromptType.Error, "写入校准失败", $"{s.Message}。");
  198. });
  199. }
  200. else
  201. {
  202. Notify(EnumPromptType.Error, "写入校准失败", $"【冷凝水罐温度校准】输入的温度不是一个有效的数字");
  203. }
  204. }
  205. else
  206. {
  207. Notify(EnumPromptType.Error, "校准失败", "设备未连接");
  208. }
  209. }
  210. private void SetReactorSpeed_Click(object sender, RoutedEventArgs e)
  211. {
  212. if (PlcControl.GetInstance.IsConnect)
  213. {
  214. SetParamValue(reactorRotateStirSpeedValue.Text, FloatAddEnum.反应釜旋转炒制速度, 0, 100);
  215. SetParamValue(reactorRotateSlowSpeedValue.Text, FloatAddEnum.反应釜旋转慢速度, 0, 100);
  216. }
  217. else
  218. {
  219. Notify(EnumPromptType.Error, "写入失败", "设备未连接");
  220. }
  221. }
  222. private void SetParamValue(string text,FloatAddEnum floatAdd,float minValue,float maxValue)
  223. {
  224. if (float.TryParse(text, out float tempValue) && tempValue>=minValue && tempValue<=maxValue)
  225. {
  226. PlcControl.GetInstance.Write(floatAdd, MathF.Round(tempValue, 2)).OnSuccess((s) =>
  227. {
  228. Notify(EnumPromptType.Success, $"写入成功", $"成功:写入【{floatAdd.ToString()}】:{tempValue}");
  229. }).OnFailure((s) =>
  230. {
  231. Notify(EnumPromptType.Error, "写入失败", $"{s.Message}。");
  232. });
  233. }
  234. else
  235. {
  236. Notify(EnumPromptType.Error, "写入失败", $"【{floatAdd.ToString()}】输入的温度不是一个有效的数字,限值{minValue} -- {maxValue}。");
  237. }
  238. }
  239. private void steamParamsSet_Click(object sender, RoutedEventArgs e)
  240. {
  241. if (PlcControl.GetInstance.IsConnect)
  242. {
  243. SetParamValue(steamValveApertureValve.Text, FloatAddEnum.蒸汽比例阀开度, 0, 100);
  244. SetParamValue(reactorSteamPressureLimitValue.Text, FloatAddEnum.反应釜蒸汽压力上限, -0.1F, 0.6F);
  245. SetParamValue(reactorPressureLimitValue.Text, FloatAddEnum.反应釜压力上限, 0F, 1F);
  246. }
  247. else
  248. {
  249. Notify(EnumPromptType.Error, "写入失败", "设备未连接");
  250. }
  251. }
  252. }
  253. }