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 ///