终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

399 lignes
16 KiB

  1. using BPASmartClient.CustomResource.UserControls.MessageShow;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace BPASmartClient.Academy.View
  17. {
  18. /// <summary>
  19. /// DeviceMotion_2View.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class DeviceMotion_2View : UserControl
  22. {
  23. private volatile static DeviceMotion_2View _Instance;
  24. public static DeviceMotion_2View GetInstance => _Instance ?? (_Instance = new DeviceMotion_2View());
  25. private DeviceMotion_2View()
  26. {
  27. InitializeComponent();
  28. this.DataContext = DeviceMotion_2ViewModel.GetInstance;
  29. this.Loaded += DeviceMotionView_Loaded;
  30. }
  31. private void DeviceMotionView_Loaded(object sender, RoutedEventArgs e)
  32. {
  33. Simens_PLC.GetInstance.connect = o =>
  34. {
  35. App.Current.Dispatcher.Invoke(() =>
  36. {
  37. if (o)
  38. {
  39. ooo.Opacity = 1;
  40. ooo.IsHitTestVisible = true;
  41. state.Visibility = Visibility.Collapsed;
  42. }
  43. else
  44. {
  45. ooo.Opacity = 0.5;
  46. ooo.IsHitTestVisible = false;
  47. state.Text = "设 备 未 连 接";
  48. //MessageNotify.GetInstance.ShowRunLog("设备未连接");
  49. state.Visibility = Visibility.Visible;
  50. state.Foreground = Brushes.Red;
  51. }
  52. });
  53. };
  54. }
  55. private string tempName = "配料罐升温";
  56. private void auto_click(object sender, RoutedEventArgs e)
  57. {
  58. RadioButton radioButton = (RadioButton)sender;
  59. switch (radioButton.Content.ToString())
  60. {
  61. case "反应釜升温":
  62. tempName = "反应釜升温";
  63. materialTemp.Visibility = Visibility.Collapsed;
  64. wokTemp.Visibility = Visibility.Visible;
  65. wokCooling.Visibility = Visibility.Collapsed;
  66. caliTemp.Visibility = Visibility.Collapsed;
  67. break;
  68. case "配料罐升温":
  69. tempName = "配料罐升温";
  70. materialTemp.Visibility = Visibility.Visible;
  71. wokTemp.Visibility = Visibility.Collapsed;
  72. wokCooling.Visibility = Visibility.Collapsed;
  73. caliTemp.Visibility = Visibility.Collapsed;
  74. break;
  75. case "反应釜降温":
  76. tempName = "反应釜降温";
  77. materialTemp.Visibility = Visibility.Collapsed;
  78. wokTemp.Visibility = Visibility.Collapsed;
  79. wokCooling.Visibility = Visibility.Visible;
  80. caliTemp.Visibility = Visibility.Collapsed;
  81. break;
  82. case "温度校准":
  83. tempName = "温度校准";
  84. materialTemp.Visibility = Visibility.Collapsed;
  85. wokTemp.Visibility = Visibility.Collapsed;
  86. wokCooling.Visibility = Visibility.Collapsed;
  87. caliTemp.Visibility = Visibility.Visible;
  88. break;
  89. default:
  90. break;
  91. }
  92. }
  93. private void Open_Click(object sender, RoutedEventArgs e)
  94. {
  95. RadioButton radioButton = sender as RadioButton;
  96. if (radioButton.Content.ToString().Contains("配料搅拌"))
  97. {
  98. hzSet.Visibility = Visibility.Visible;
  99. motorName.Text = "配料搅拌频率:";
  100. ooo.Opacity = 0.5;
  101. ooo.IsHitTestVisible = false;
  102. }
  103. if (radioButton.Content.ToString().Contains("反应釜搅拌"))
  104. {
  105. hzSet.Visibility = Visibility.Visible;
  106. motorName.Text = "反应釜搅拌频率:";
  107. ooo.Opacity = 0.5;
  108. ooo.IsHitTestVisible = false;
  109. }
  110. if (Simens_PLC.GetInstance.IsConnected)
  111. {
  112. int bit = Convert.ToInt32(radioButton.Tag.ToString());
  113. if (bit < 8)
  114. {
  115. Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1000.{bit}", true);
  116. }
  117. else if (bit < 16)
  118. {
  119. Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1001.{bit - 8}", true);
  120. }
  121. else if(bit<32)
  122. {
  123. Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1002.{bit - 16}", true);
  124. }
  125. else
  126. {
  127. Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1003.{bit - 32}", true);
  128. }
  129. }
  130. }
  131. private void Close_Click(object sender, RoutedEventArgs e)
  132. {
  133. RadioButton radioButton = sender as RadioButton;
  134. if (Simens_PLC.GetInstance.IsConnected)
  135. {
  136. int bit = Convert.ToInt32(radioButton.Tag.ToString());
  137. if (bit < 8)
  138. {
  139. Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1000.{bit}", false);
  140. }
  141. else if (bit < 16)
  142. {
  143. Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1001.{bit - 8}", false);
  144. }
  145. else if (bit < 32)
  146. {
  147. Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1002.{bit - 16}", false);
  148. }
  149. else
  150. {
  151. Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1003.{bit - 32}", false);
  152. }
  153. }
  154. }
  155. private void TempSet_CLick(object sender, RoutedEventArgs e)
  156. {
  157. bool suc;
  158. if (Simens_PLC.GetInstance.IsConnected)
  159. {
  160. switch (tempName)
  161. {
  162. case "反应釜升温":
  163. int tempValue;
  164. suc = int.TryParse(temp_2.Text.ToString(), out tempValue);
  165. if (suc)
  166. {
  167. Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1001.7", true);
  168. Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1020", tempValue);
  169. }
  170. else
  171. {
  172. App.Current.Dispatcher.Invoke(() =>
  173. {
  174. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查温度输入是否正确", 1, 1);
  175. });
  176. }
  177. break;
  178. case "配料罐升温":
  179. suc = int.TryParse(temp_1.Text.ToString(), out tempValue);
  180. //int time;
  181. //suc = int.TryParse(time_1.Text.ToString(), out time);
  182. if (suc)
  183. {
  184. Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1001.6", true);
  185. //Simens_PLC.GetInstance.siemens.Write<ushort>("DB1.DBD100", (ushort)(time*10));
  186. Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1016", tempValue);
  187. }
  188. else
  189. {
  190. App.Current.Dispatcher.Invoke(() =>
  191. {
  192. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查温度输入是否正确", 1, 1);
  193. });
  194. }
  195. break;
  196. case "反应釜降温":
  197. suc = int.TryParse(temp_3.Text.ToString(), out tempValue);
  198. //int time;
  199. //suc = int.TryParse(time_1.Text.ToString(), out time);
  200. if (suc)
  201. {
  202. Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1003.0", true);
  203. //Simens_PLC.GetInstance.siemens.Write<ushort>("DB1.DBD100", (ushort)(time*10));
  204. Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1020", tempValue);
  205. }
  206. else
  207. {
  208. App.Current.Dispatcher.Invoke(() =>
  209. {
  210. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查温度输入是否正确", 1, 1);
  211. });
  212. }
  213. break;
  214. case "温度校准":
  215. bool val = true;
  216. int value;
  217. suc = int.TryParse(tempvent.Text.ToString(), out value);
  218. if (suc)
  219. {
  220. Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1024", value).OnFailure(o =>
  221. {
  222. val = false;
  223. App.Current.Dispatcher.Invoke(() =>
  224. {
  225. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "反应釜排气温度写入失败", 1, 1);
  226. });
  227. });
  228. }
  229. else
  230. {
  231. App.Current.Dispatcher.Invoke(() =>
  232. {
  233. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查排气温度校准输入", 1, 1);
  234. });
  235. }
  236. suc = int.TryParse(tempmaterial.Text.ToString(), out value);
  237. if (suc)
  238. {
  239. Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1028", value).OnFailure(o =>
  240. {
  241. val = false;
  242. App.Current.Dispatcher.Invoke(() =>
  243. {
  244. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "配料罐温度写入失败", 1, 1);
  245. });
  246. });
  247. }
  248. else
  249. {
  250. App.Current.Dispatcher.Invoke(() =>
  251. {
  252. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查配料罐温度校准输入", 1, 1);
  253. });
  254. }
  255. suc = int.TryParse(tempwok.Text.ToString(), out value);
  256. if (suc)
  257. {
  258. Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1032", value).OnFailure(o =>
  259. {
  260. val = false;
  261. App.Current.Dispatcher.Invoke(() =>
  262. {
  263. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "反应釜温度写入失败", 1, 1);
  264. });
  265. });
  266. }
  267. else
  268. {
  269. App.Current.Dispatcher.Invoke(() =>
  270. {
  271. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查反应釜温度校准输入", 1, 1);
  272. });
  273. }
  274. if (val)
  275. {
  276. App.Current.Dispatcher.Invoke(() =>
  277. {
  278. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, App.MainWindow, "成功", "校准完成", 1, 1);
  279. });
  280. }
  281. break;
  282. default:
  283. break;
  284. }
  285. }
  286. }
  287. private void hzSet_Click(object sender, RoutedEventArgs e)
  288. {
  289. hzSet.Visibility = Visibility.Collapsed;
  290. int value;
  291. bool suc = int.TryParse(motorValue.Text.ToString(), out value);
  292. if (suc && Simens_PLC.GetInstance.IsConnected && value >= 20 && value <= 100)
  293. {
  294. if (motorName.Text.ToString().Contains("配料搅拌"))
  295. {
  296. Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1004", value).OnFailure(o =>
  297. {
  298. App.Current.Dispatcher.Invoke(() =>
  299. {
  300. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "频率写入失败", 1, 1);
  301. });
  302. });
  303. }
  304. if (motorName.Text.ToString().Contains("反应釜搅拌"))
  305. {
  306. Simens_PLC.GetInstance.siemens.Write<int>("DB1.DBD1008", value).OnFailure(o =>
  307. {
  308. App.Current.Dispatcher.Invoke(() =>
  309. {
  310. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "频率写入失败", 1, 1);
  311. });
  312. });
  313. }
  314. }
  315. else
  316. {
  317. App.Current.Dispatcher.Invoke(() =>
  318. {
  319. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查频率设备连接、数据格式等", 1, 1);
  320. });
  321. }
  322. ooo.Opacity = 1;
  323. ooo.IsHitTestVisible = true;
  324. }
  325. private void hzCancel_Click(object sender, RoutedEventArgs e)
  326. {
  327. hzSet.Visibility = Visibility.Collapsed;
  328. ooo.Opacity = 1;
  329. ooo.IsHitTestVisible = true;
  330. }
  331. private void TempCLose_CLick(object sender, RoutedEventArgs e)
  332. {
  333. if (Simens_PLC.GetInstance.IsConnected)
  334. {
  335. switch (tempName)
  336. {
  337. case "配料罐升温":
  338. Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1001.6", false);
  339. break;
  340. case "反应釜升温":
  341. Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1001.7", false);
  342. break;
  343. case "反应釜降温":
  344. Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1003.0", false);
  345. break;
  346. default:
  347. break;
  348. }
  349. }
  350. }
  351. private void ClearBtn_CLick(object sender, RoutedEventArgs e)
  352. {
  353. if (Simens_PLC.GetInstance.IsConnected)
  354. {
  355. Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1002.7", true);
  356. }
  357. }
  358. private void new_Click(object sender, RoutedEventArgs e)
  359. {
  360. if (Simens_PLC.GetInstance.IsConnected)
  361. {
  362. RadioButton radioButton = sender as RadioButton;
  363. if (radioButton.Content.ToString().Contains("开"))
  364. {
  365. Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX3000.{radioButton.Tag}", true);
  366. }
  367. else
  368. {
  369. Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX3000.{radioButton.Tag}", false);
  370. }
  371. }
  372. }
  373. }
  374. }