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

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