From 0bb356e1b8f3e65e73725f4f9df413b44d5174de Mon Sep 17 00:00:00 2001 From: liuwf Date: Mon, 11 Dec 2023 10:52:40 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E9=92=A3=E9=87=91plc=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/MainWindowViewModel.cs | 2 +- .../ViewModels/MainWindowViewModel.cs | 3 +- .../ViewModels/MainWindowViewModel.cs | 231 ++++++++++++++++-- Aucma.Core.SheetMetal/Views/MainWindow.xaml | 21 +- 4 files changed, 219 insertions(+), 38 deletions(-) diff --git a/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs b/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs index c46e4f88..191e4513 100644 --- a/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs @@ -23,7 +23,7 @@ namespace Aucma.Core.BoxFoam.ViewModels private FoamPlanPageView foamPlanPageView = new FoamPlanPageView(); FoamMonitorPageView foamMonitorPageView = new FoamMonitorPageView(); FoamMachinesPageView foamMachinesPageView = new FoamMachinesPageView(); - + public MainWindowViewModel() { UserContent = firstPage; diff --git a/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs b/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs index 64c6c938..fc5dbf13 100644 --- a/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs @@ -195,14 +195,13 @@ namespace Aucma.Core.CodeBinding.ViewModels /// public static void OpenOsk() { - Process proc = new Process(); + Process proc = new Process(); proc.StartInfo.FileName = @"C:\Windows\System32\osk.exe"; proc.StartInfo.UseShellExecute = true; proc.StartInfo.Verb = "runas"; proc.Start(); } #endregion - #region 界面切换 /// /// 界面切换 diff --git a/Aucma.Core.SheetMetal/ViewModels/MainWindowViewModel.cs b/Aucma.Core.SheetMetal/ViewModels/MainWindowViewModel.cs index 5353f367..04719c97 100644 --- a/Aucma.Core.SheetMetal/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.SheetMetal/ViewModels/MainWindowViewModel.cs @@ -10,6 +10,9 @@ using System.Windows.Interop; using System.Collections.ObjectModel; using Admin.Core.Common; using System.IO; +using Aucma.Core.PLc; +using Aucma.Core.Scanner; +using System.Linq; namespace Aucma.Core.SheetMetal.ViewModels { @@ -19,12 +22,91 @@ namespace Aucma.Core.SheetMetal.ViewModels private IndexPageView firstPage = new IndexPageView();//首页 private LogPageView logPage = new LogPageView();//日志 private StatisticsPageView statisticsPage = new StatisticsPageView();//统计 - + public MainWindowViewModel() { UserContent = firstPage; + init(); } + public void init() + { + // 设备状态刷新定时器 + System.Timers.Timer timer = new System.Timers.Timer(1000 * 5); + timer.Elapsed += new System.Timers.ElapsedEventHandler(RefreshStatus); + timer.AutoReset = true; + timer.Enabled = true; + timer.Start(); + } + + #region 设备状态刷新 + /// + /// 设备状态刷新 + /// + /// + /// + public void RefreshStatus(object sender, System.Timers.ElapsedEventArgs e) + { + RefreshMesDb(); + RefreshPlc(); + + + } + /// + /// 数据库状态刷新 + /// + /// + /// + public void RefreshMesDb() + { + MesDbState(true); + } + + + /// + /// plc状态刷新 + /// + /// + /// + public void RefreshPlc() + { + // 后板plc + var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("后板Plc")); + if (obj != null) + { + if (obj.plc.IsConnected) + { + PlcState(true); + } + else + { + PlcState(false); + } + } + else + { + PlcState(false); + } + // u壳plc + var obj2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("U壳PLC")); + if (obj2 != null) + { + if (obj2.plc.IsConnected) + { + Plc2State(true); + } + else + { + Plc2State(false); + } + } + else + { + Plc2State(false); + } + } + + #endregion #region 更换界面 public System.Windows.Controls.UserControl _content; @@ -130,19 +212,69 @@ namespace Aucma.Core.SheetMetal.ViewModels break; } } - #endregion + #endregion + #region MES数据库状态 + /// + /// MES数据库-文字 + /// + public string _mesDbUIStatusWb; + public string MesDbUIStatusWb + { + get => _mesDbUIStatusWb; + set => SetProperty(ref _mesDbUIStatusWb, value); + } + /// + /// MES数据库-颜色 + /// + public string _mesDbUIColor; + public string MesDbUIColor + { + get => _mesDbUIColor; + set => SetProperty(ref _mesDbUIColor, value); + } + /// + /// MES数据库-图标 + /// + public string _mesUIIcon; + public string MesUIIcon + { + get => _mesUIIcon; + set => SetProperty(ref _mesUIIcon, value); + } - #region plc 状态 + /// + /// MES数据库连接状态 + /// + /// + public void MesDbState(bool type) + { + Application.Current.Dispatcher.Invoke(() => + { + if (type) + { + MesDbUIStatusWb = "MES数据库连接成功"; + MesDbUIColor = "Green"; + MesUIIcon = "Assets/Images/Green.png"; + } + else + { + MesDbUIStatusWb = "MES数据库异常"; + MesDbUIColor = "Red"; + MesUIIcon = "Assets/Images/Red.png"; + } + }); + } + #endregion + + #region 后板plc 状态 /// /// UI plc 展示状态-文字 /// - public string _plcUIStatus; + public string _plcUIStatusWb; public string PlcUIStatusWb { - //get { return plcUIStatusWb; } - //set { plcUIStatusWb = value; RaisePropertyChanged("PlcUIStatusWb"); } - get => _plcUIStatus; - set => SetProperty(ref _plcUIStatus, value); + get => _plcUIStatusWb; + set => SetProperty(ref _plcUIStatusWb, value); } /// /// UI plc 展示状态-颜色 @@ -150,8 +282,6 @@ namespace Aucma.Core.SheetMetal.ViewModels public string _plcUIColor; public string PlcUIColor { - //get { return plcUIColor; } - //set { plcUIColor = value; RaisePropertyChanged("PlcUIColor"); } get => _plcUIColor; set => SetProperty(ref _plcUIColor, value); } @@ -161,30 +291,85 @@ namespace Aucma.Core.SheetMetal.ViewModels public string _plcUIIcon; public string PlcUIIcon { - //get { return plcUIIcon; } - //set { plcUIIcon = value; RaisePropertyChanged("plcUIIcon"); } get => _plcUIIcon; set => SetProperty(ref _plcUIIcon, value); } /// - /// PLC连接状态-true:连接成功;false:失败 + /// 后板PLC连接状态-true:连接成功;false:失败 /// /// public void PlcState(bool type) { - if (type) + Application.Current.Dispatcher.Invoke(() => { - PlcUIStatusWb = "PLC连接成功"; - PlcUIColor = "White"; - PlcUIIcon = "Assets/Images/正常.png"; - } - else + if (type) + { + PlcUIStatusWb = "后板PLC连接成功"; + PlcUIColor = "Green"; + PlcUIIcon = "Assets/Images/Green.png"; + } + else + { + PlcUIStatusWb = "后板PLC状态异常"; + PlcUIColor = "Red"; + PlcUIIcon = "Assets/Images/Red.png"; + } + }); + } + #endregion + + + #region U壳PLC状态 + /// + /// UI plc 展示状态-文字 + /// + public string _plc2UIStatusWb; + public string Plc2UIStatusWb + { + get => _plc2UIStatusWb; + set => SetProperty(ref _plc2UIStatusWb, value); + } + /// + /// UI plc 展示状态-颜色 + /// + public string _plc2UIColor; + public string Plc2UIColor + { + get => _plc2UIColor; + set => SetProperty(ref _plc2UIColor, value); + } + /// + /// UI plc 展示状态-图标 + /// + public string _plc2UIIcon; + public string Plc2UIIcon + { + get => _plc2UIIcon; + set => SetProperty(ref _plc2UIIcon, value); + } + + /// + /// PLC连接状态-true:连接成功;false:失败 + /// + /// + public void Plc2State(bool type) + { + Application.Current.Dispatcher.Invoke(() => { - PlcUIStatusWb = "PLC状态异常"; - PlcUIColor = "Red"; - PlcUIIcon = "Assets/Images/失败-01.png"; - } + if (type) + { + Plc2UIStatusWb = "U壳PLC连接成功"; + Plc2UIColor = "Green"; + Plc2UIIcon = "Assets/Images/Green.png"; + } + else + { + Plc2UIStatusWb = "U壳PLC状态异常"; + Plc2UIColor = "Red"; + Plc2UIIcon = "Assets/Images/Red.png"; + } + }); } #endregion } diff --git a/Aucma.Core.SheetMetal/Views/MainWindow.xaml b/Aucma.Core.SheetMetal/Views/MainWindow.xaml index 54875b0e..161341a9 100644 --- a/Aucma.Core.SheetMetal/Views/MainWindow.xaml +++ b/Aucma.Core.SheetMetal/Views/MainWindow.xaml @@ -60,10 +60,7 @@ - - - - +