From aa1b64d33b23221a9d6253520ac6fb2765c5cafe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=AF=E9=BE=99=20=E6=9B=B9?= <1805857645@QQ.com> Date: Thu, 26 Dec 2024 10:41:57 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=E6=B7=BB=E5=8A=A0=E5=8E=8B=E5=8A=9BPLC?= =?UTF-8?q?=E6=96=AD=E7=BA=BF=E9=87=8D=E8=BF=9E=EF=BC=8CPLC=E6=96=AD?= =?UTF-8?q?=E7=BA=BF=E9=87=8D=E8=BF=9E=E6=8A=BD=E7=A6=BB=E6=88=90=E7=8B=AC?= =?UTF-8?q?=E7=AB=8B=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModel/MainWindowViewModel.cs | 61 ++++++++++++------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs index 1a3d20d..3cf2eb8 100644 --- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs @@ -41,6 +41,7 @@ namespace SlnMesnac.WPF.ViewModel private readonly AgvAndTaskMonitorPage agvAndTaskMonitorPage = new AgvAndTaskMonitorPage(); private System.Timers.Timer timer = new System.Timers.Timer(1000 * 60); PlcAbsractFactory? plc = null; + private PlcAbsractFactory? pressurePlc = null; private BaseBusiness? baseBusiness = null; #region 参数定义 @@ -79,8 +80,6 @@ namespace SlnMesnac.WPF.ViewModel } } - - /// /// PLC设备状态 /// @@ -90,6 +89,17 @@ namespace SlnMesnac.WPF.ViewModel get { return _PlcStatus; } set { _PlcStatus = value; RaisePropertyChanged(nameof(PlcStatus)); } } + + /// + /// 压力PLC设备状态 + /// + private int _PressurePlcStatus = 0; + public int PressurePlcStatus + { + get { return _PressurePlcStatus; } + set { _PressurePlcStatus = value; RaisePropertyChanged(nameof(PressurePlcStatus)); } + } + /// /// 喷码机状态 /// @@ -154,6 +164,7 @@ namespace SlnMesnac.WPF.ViewModel FormControlCommand = new RelayCommand(x => FormControl(x)); baseBusiness = App.ServiceProvider.GetService(); plc = baseBusiness.GetPlcByKey("plc"); + pressurePlc = baseBusiness.GetPlcByKey("pressurePlc"); StartLiseningStatus(); checkStatus(); RefreshTime(); @@ -232,32 +243,16 @@ namespace SlnMesnac.WPF.ViewModel timer.Start(); } - /// - /// 检查设备状态 - /// private void checkStatus() { - try { #region PLC状态 - if (plc != null && plc.IsConnected) - { - plc.IsConnected = plc.readHeartByAddress("M100"); - PlcStatus = 1; - } - else - { - PlcStatus = 2; - - PlcConfig? plcConfig = App.ServiceProvider.GetService().plcConfig.FirstOrDefault(x => x.plcKey == "plc"); - if (plcConfig != null) - { - bool result = plc.Connect(plcConfig.plcIp, plcConfig.plcPort); - plc.IsConnected = result; - } + CheckPlcStatus(plc, "plc", status => PlcStatus = status); + #endregion - } + #region 压力PLC状态断线重连 + CheckPlcStatus(pressurePlc, "pressurePlc", status => PressurePlcStatus = status); #endregion #region 喷码机状态 @@ -295,6 +290,28 @@ namespace SlnMesnac.WPF.ViewModel } + /// + /// 检查设备状态 + /// + private void CheckPlcStatus(PlcAbsractFactory plc, string plcKey, Action setStatus) + { + if (plc != null && plc.IsConnected) + { + plc.IsConnected = plc.readHeartByAddress("M100"); + setStatus(1); + } + else + { + setStatus(2); + PlcConfig? plcConfig = App.ServiceProvider.GetService().plcConfig.FirstOrDefault(x => x.plcKey == plcKey); + if (plcConfig != null) + { + bool result = plc.Connect(plcConfig.plcIp, plcConfig.plcPort); + plc.IsConnected = result; + } + } + } + #endregion ///