终端一体化运控平台
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.
 
 
 

430 lines
17 KiB

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