using BPASmartClient.CustomResource.UserControls.MessageShow; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace BPASmartClient.Academy.View { /// /// DeviceMotion_2View.xaml 的交互逻辑 /// public partial class DeviceMotion_2View : UserControl { private volatile static DeviceMotion_2View _Instance; public static DeviceMotion_2View GetInstance => _Instance ?? (_Instance = new DeviceMotion_2View()); private DeviceMotion_2View() { InitializeComponent(); this.DataContext = DeviceMotion_2ViewModel.GetInstance; this.Loaded += DeviceMotionView_Loaded; } private void DeviceMotionView_Loaded(object sender, RoutedEventArgs e) { Simens_PLC.GetInstance.connect = o => { App.Current.Dispatcher.Invoke(() => { if (o) { ooo.Opacity = 1; ooo.IsHitTestVisible = true; state.Visibility = Visibility.Collapsed; } else { ooo.Opacity = 0.5; ooo.IsHitTestVisible = false; state.Text = "设 备 未 连 接"; //MessageNotify.GetInstance.ShowRunLog("设备未连接"); state.Visibility = Visibility.Visible; state.Foreground = Brushes.Red; } }); }; } private string tempName = "配料罐升温"; private void auto_click(object sender, RoutedEventArgs e) { RadioButton radioButton = (RadioButton)sender; switch (radioButton.Content.ToString()) { case "反应釜升温": tempName = "反应釜升温"; materialTemp.Visibility = Visibility.Collapsed; wokTemp.Visibility = Visibility.Visible; wokCooling.Visibility = Visibility.Collapsed; caliTemp.Visibility = Visibility.Collapsed; break; case "配料罐升温": tempName = "配料罐升温"; materialTemp.Visibility = Visibility.Visible; wokTemp.Visibility = Visibility.Collapsed; wokCooling.Visibility = Visibility.Collapsed; caliTemp.Visibility = Visibility.Collapsed; break; case "反应釜降温": tempName = "反应釜降温"; materialTemp.Visibility = Visibility.Collapsed; wokTemp.Visibility = Visibility.Collapsed; wokCooling.Visibility = Visibility.Visible; caliTemp.Visibility = Visibility.Collapsed; break; case "温度校准": tempName = "温度校准"; materialTemp.Visibility = Visibility.Collapsed; wokTemp.Visibility = Visibility.Collapsed; wokCooling.Visibility = Visibility.Collapsed; caliTemp.Visibility = Visibility.Visible; break; default: break; } } private void Open_Click(object sender, RoutedEventArgs e) { RadioButton radioButton = sender as RadioButton; if (radioButton.Content.ToString().Contains("配料搅拌")) { hzSet.Visibility = Visibility.Visible; motorName.Text = "配料搅拌频率:"; ooo.Opacity = 0.5; ooo.IsHitTestVisible = false; } if (radioButton.Content.ToString().Contains("反应釜搅拌")) { hzSet.Visibility = Visibility.Visible; motorName.Text = "反应釜搅拌频率:"; ooo.Opacity = 0.5; ooo.IsHitTestVisible = false; } if (Simens_PLC.GetInstance.IsConnected) { int bit = Convert.ToInt32(radioButton.Tag.ToString()); if (bit < 8) { Simens_PLC.GetInstance.siemens.Write($"DB1.DBX1000.{bit}", true); } else if (bit < 16) { Simens_PLC.GetInstance.siemens.Write($"DB1.DBX1001.{bit - 8}", true); } else if(bit<32) { Simens_PLC.GetInstance.siemens.Write($"DB1.DBX1002.{bit - 16}", true); } else { Simens_PLC.GetInstance.siemens.Write($"DB1.DBX1003.{bit - 32}", true); } } } private void Close_Click(object sender, RoutedEventArgs e) { RadioButton radioButton = sender as RadioButton; if (Simens_PLC.GetInstance.IsConnected) { int bit = Convert.ToInt32(radioButton.Tag.ToString()); if (bit < 8) { Simens_PLC.GetInstance.siemens.Write($"DB1.DBX1000.{bit}", false); } else if (bit < 16) { Simens_PLC.GetInstance.siemens.Write($"DB1.DBX1001.{bit - 8}", false); } else if (bit < 32) { Simens_PLC.GetInstance.siemens.Write($"DB1.DBX1002.{bit - 16}", false); } else { Simens_PLC.GetInstance.siemens.Write($"DB1.DBX1003.{bit - 32}", false); } } } private void TempSet_CLick(object sender, RoutedEventArgs e) { bool suc; if (Simens_PLC.GetInstance.IsConnected) { switch (tempName) { case "反应釜升温": int tempValue; suc = int.TryParse(temp_2.Text.ToString(), out tempValue); if (suc) { Simens_PLC.GetInstance.siemens.Write("DB1.DBX1001.7", true); Simens_PLC.GetInstance.siemens.Write("DB1.DBD1020", tempValue); } else { App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查温度输入是否正确", 1, 1); }); } break; case "配料罐升温": suc = int.TryParse(temp_1.Text.ToString(), out tempValue); //int time; //suc = int.TryParse(time_1.Text.ToString(), out time); if (suc) { Simens_PLC.GetInstance.siemens.Write("DB1.DBX1001.6", true); //Simens_PLC.GetInstance.siemens.Write("DB1.DBD100", (ushort)(time*10)); Simens_PLC.GetInstance.siemens.Write("DB1.DBD1016", tempValue); } else { App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查温度输入是否正确", 1, 1); }); } break; case "反应釜降温": suc = int.TryParse(temp_3.Text.ToString(), out tempValue); //int time; //suc = int.TryParse(time_1.Text.ToString(), out time); if (suc) { Simens_PLC.GetInstance.siemens.Write("DB1.DBX1003.0", true); //Simens_PLC.GetInstance.siemens.Write("DB1.DBD100", (ushort)(time*10)); Simens_PLC.GetInstance.siemens.Write("DB1.DBD1020", tempValue); } else { App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查温度输入是否正确", 1, 1); }); } break; case "温度校准": bool val = true; int value; suc = int.TryParse(tempvent.Text.ToString(), out value); if (suc) { Simens_PLC.GetInstance.siemens.Write("DB1.DBD1024", value).OnFailure(o => { val = false; App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "反应釜排气温度写入失败", 1, 1); }); }); } else { App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查排气温度校准输入", 1, 1); }); } suc = int.TryParse(tempmaterial.Text.ToString(), out value); if (suc) { Simens_PLC.GetInstance.siemens.Write("DB1.DBD1028", value).OnFailure(o => { val = false; App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "配料罐温度写入失败", 1, 1); }); }); } else { App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查配料罐温度校准输入", 1, 1); }); } suc = int.TryParse(tempwok.Text.ToString(), out value); if (suc) { Simens_PLC.GetInstance.siemens.Write("DB1.DBD1032", value).OnFailure(o => { val = false; App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "反应釜温度写入失败", 1, 1); }); }); } else { App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查反应釜温度校准输入", 1, 1); }); } if (val) { App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, App.MainWindow, "成功", "校准完成", 1, 1); }); } break; default: break; } } } private void hzSet_Click(object sender, RoutedEventArgs e) { hzSet.Visibility = Visibility.Collapsed; int value; bool suc = int.TryParse(motorValue.Text.ToString(), out value); if (suc && Simens_PLC.GetInstance.IsConnected && value >= 20 && value <= 100) { if (motorName.Text.ToString().Contains("配料搅拌")) { Simens_PLC.GetInstance.siemens.Write("DB1.DBD1004", value).OnFailure(o => { App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "频率写入失败", 1, 1); }); }); } if (motorName.Text.ToString().Contains("反应釜搅拌")) { Simens_PLC.GetInstance.siemens.Write("DB1.DBD1008", value).OnFailure(o => { App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "频率写入失败", 1, 1); }); }); } } else { App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", "请检查频率设备连接、数据格式等", 1, 1); }); } ooo.Opacity = 1; ooo.IsHitTestVisible = true; } private void hzCancel_Click(object sender, RoutedEventArgs e) { hzSet.Visibility = Visibility.Collapsed; ooo.Opacity = 1; ooo.IsHitTestVisible = true; } private void TempCLose_CLick(object sender, RoutedEventArgs e) { if (Simens_PLC.GetInstance.IsConnected) { switch (tempName) { case "配料罐升温": Simens_PLC.GetInstance.siemens.Write("DB1.DBX1001.6", false); break; case "反应釜升温": Simens_PLC.GetInstance.siemens.Write("DB1.DBX1001.7", false); break; case "反应釜降温": Simens_PLC.GetInstance.siemens.Write("DB1.DBX1003.0", false); break; default: break; } } } private void ClearBtn_CLick(object sender, RoutedEventArgs e) { if (Simens_PLC.GetInstance.IsConnected) { Simens_PLC.GetInstance.siemens.Write("DB1.DBX1002.7", true); } } private void new_Click(object sender, RoutedEventArgs e) { if (Simens_PLC.GetInstance.IsConnected) { RadioButton radioButton = sender as RadioButton; if (radioButton.Content.ToString().Contains("开")) { Simens_PLC.GetInstance.siemens.Write($"DB1.DBX3000.{radioButton.Tag}", true); } else { Simens_PLC.GetInstance.siemens.Write($"DB1.DBX3000.{radioButton.Tag}", false); } } } } }