|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- using BPASmartClient.Academy.Model;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.CustomResource.UserControls;
- using LiveCharts;
- using LiveCharts.Wpf;
- using Newtonsoft.Json.Linq;
- using OxyPlot;
- using OxyPlot.Axes;
- using OxyPlot.Series;
- using S7.Net.Types;
- 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;
- using static System.Net.Mime.MediaTypeNames;
- using SqlSugar;
-
- namespace BPASmartClient.Academy.View
- {
- /// <summary>
- /// DeviceMotionView.xaml 的交互逻辑
- /// </summary>
- public partial class DeviceMotionView : UserControl
- {
- private volatile static DeviceMotionView _Instance;
- public static DeviceMotionView GetInstance => _Instance ?? (_Instance = new DeviceMotionView());
- private DeviceMotionView()
- {
- InitializeComponent();
- this.DataContext = DeviceMotionViewModel.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<bool>($"DB1.DBX1000.{bit}", true);
- }
- else if (bit < 16)
- {
- Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1001.{bit - 8}", true);
- }
- else
- {
- Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1002.{bit - 16}", 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<bool>($"DB1.DBX1000.{bit}", false);
- }
- else if (bit < 16)
- {
- Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1001.{bit - 8}", false);
- }
- else
- {
- Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX1002.{bit - 16}", 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<bool>("DB1.DBX1001.7", true);
- Simens_PLC.GetInstance.siemens.Write<int>("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<bool>("DB1.DBX1001.6", true);
- //Simens_PLC.GetInstance.siemens.Write<ushort>("DB1.DBD100", (ushort)(time*10));
- Simens_PLC.GetInstance.siemens.Write<int>("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<bool>("DB1.DBX1003.0", true);
- //Simens_PLC.GetInstance.siemens.Write<ushort>("DB1.DBD100", (ushort)(time*10));
- Simens_PLC.GetInstance.siemens.Write<int>("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<int>("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<int>("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<int>("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<int>("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<int>("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<bool>("DB1.DBX1001.6", false);
- break;
- case "反应釜升温":
- Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1001.7", false);
- break;
- case "反应釜降温":
- Simens_PLC.GetInstance.siemens.Write<bool>("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<bool>("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<bool>($"DB1.DBX3000.{radioButton.Tag}", true);
- }
- else
- {
- Simens_PLC.GetInstance.siemens.Write<bool>($"DB1.DBX3000.{radioButton.Tag}", false);
- }
- }
-
- }
-
- //private void xxx_MouseMove(object sender, MouseEventArgs e)
- //{
- // CartesianChart liveCharts = sender as CartesianChart;
- // var possition = e.GetPosition(liveCharts);
-
- //}
- //Double old;
- //private void xxx_MouseDown(object sender, MouseButtonEventArgs e)
- //{
- // CartesianChart liveCharts = sender as CartesianChart;
- // var point = e.GetPosition(liveCharts);
- // old = liveCharts.AxisX[0].(point.X);
- //}
-
- //private void Zoom_MouseWheel(object sender, MouseWheelEventArgs e)
- //{
- // double MinValue = xxx.AxisX[0].MinValue;
- // double MaxValue = xxx.AxisX[0].MaxValue;
- // ChartValues<DataValue> twValues = new ChartValues<DataValue>();
- // ChartValues<DataValue> tvValues = new ChartValues<DataValue>();
- // ChartValues<DataValue> tmValues = new ChartValues<DataValue>();
- // Sqlite.GetInstance.saveDatas.ForEach(t =>
- // {
- // if (t.Date.Ticks >= MinValue && t.Date.Ticks <= MaxValue)
- // {
- // twValues.Add(new DataValue() { DateTime = t.Date, Value = t.TempWok });
- // tvValues.Add(new DataValue() { DateTime = t.Date, Value = t.TempVent });
- // tmValues.Add(new DataValue() { DateTime = t.Date, Value = t.TempMaterial });
- // }
-
- // });
- // xxx.Series[0].Values = twValues;
- // xxx.Series[1].Values = tvValues;
- // xxx.Series[2].Values = tmValues;
-
- //}
- }
- }
|