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

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