From 58d5fa154d95b4d8f1b63672d771f3050d96f60c Mon Sep 17 00:00:00 2001 From: liuwf Date: Tue, 27 Aug 2024 15:37:42 +0800 Subject: [PATCH] =?UTF-8?q?change-=E5=AE=8C=E5=96=84=E6=8A=A5=E8=AD=A6?= =?UTF-8?q?=E5=8F=8A=E8=AE=BE=E5=A4=87=E5=85=B3=E6=9C=BA=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E9=87=87=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Business/ConfigInfoBusiness.cs | 5 + SlnMesnac.Business/ProdMgmtBusiness.cs | 10 +- .../service/IBaseConfigInfoService.cs | 2 + .../service/Impl/BaseConfigInfoServiceImpl.cs | 5 + SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs | 316 +++++++++++++----- SlnMesnac.WPF/appsettings.json | 4 +- 6 files changed, 260 insertions(+), 82 deletions(-) diff --git a/SlnMesnac.Business/ConfigInfoBusiness.cs b/SlnMesnac.Business/ConfigInfoBusiness.cs index 37117c6..fb9472a 100644 --- a/SlnMesnac.Business/ConfigInfoBusiness.cs +++ b/SlnMesnac.Business/ConfigInfoBusiness.cs @@ -63,6 +63,11 @@ namespace SlnMesnac.Business _configInfoService.UpdateConfigInfo(configInfo); } + public void RefreshConfigInfo() + { + _configInfoService.RefreshConfigInfo(); + } + public void DeleteConfigInfo(int configId) { _configInfoService.DeleteConfigInfo(configId); diff --git a/SlnMesnac.Business/ProdMgmtBusiness.cs b/SlnMesnac.Business/ProdMgmtBusiness.cs index 94fce3e..abb946b 100644 --- a/SlnMesnac.Business/ProdMgmtBusiness.cs +++ b/SlnMesnac.Business/ProdMgmtBusiness.cs @@ -391,11 +391,13 @@ namespace SlnMesnac.Business } //2.生成小包条码 GenerateBarcode(40); + + //3.清空投料系统运行时间 - BaseConfigInfo configInfo = _configInfoBusiness.GetConfigInfos().Where(x => x.ConfigKey == "拆包机系统运行时长").FirstOrDefault(); + BaseConfigInfo configInfo = _configInfoBusiness.GetConfigInfos().Where(x => x.ConfigKey == "系统运行时长").FirstOrDefault(); configInfo.ConfigValue = "0"; - _configInfoBusiness.UpdateConfigInfo(configInfo); - + sqlSugarClient.AsTenant().GetConnection("local").Updateable(configInfo).ExecuteCommand(); + _configInfoBusiness.RefreshConfigInfo(); sqlSugarClient.AsTenant().CommitTran(); } @@ -567,7 +569,7 @@ namespace SlnMesnac.Business { int IntervalMin = int.Parse(GetPlcAddressByConfigKey("投料时间间隔")); // 单位分钟 - int systemRunTime = int.Parse(GetPlcAddressByConfigKey("拆包机系统运行时长")); // 单位分钟 + int systemRunTime = int.Parse(GetPlcAddressByConfigKey("系统运行时长")); // 单位分钟 if (systemRunTime > IntervalMin) { diff --git a/SlnMesnac.Repository/service/IBaseConfigInfoService.cs b/SlnMesnac.Repository/service/IBaseConfigInfoService.cs index a8bcc1b..3e568ca 100644 --- a/SlnMesnac.Repository/service/IBaseConfigInfoService.cs +++ b/SlnMesnac.Repository/service/IBaseConfigInfoService.cs @@ -12,6 +12,8 @@ namespace SlnMesnac.Repository.service void UpdateConfigInfo(BaseConfigInfo configInfo); + void RefreshConfigInfo(); + void DeleteConfigInfo(int configId); } } diff --git a/SlnMesnac.Repository/service/Impl/BaseConfigInfoServiceImpl.cs b/SlnMesnac.Repository/service/Impl/BaseConfigInfoServiceImpl.cs index 2401d35..afc5ad9 100644 --- a/SlnMesnac.Repository/service/Impl/BaseConfigInfoServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/BaseConfigInfoServiceImpl.cs @@ -83,5 +83,10 @@ namespace SlnMesnac.Repository.service.Impl var hashValue = info.GetHashCode(); } } + + public void RefreshConfigInfo() + { + RefreshConfigInfos(); + } } } diff --git a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs index f8c8c86..a7a4f5e 100644 --- a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs +++ b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs @@ -23,6 +23,7 @@ using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; +using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; @@ -132,9 +133,9 @@ namespace SlnMesnac.WPF.Page { Task.Run(() => { - + DmsList = dmsRecordShutDownService.GetAllMachineFirst(); - WarningList = dmsRecordAlarmTimeService.GetMachineWarnList(); + WarningList = dmsRecordAlarmTimeService.GetMachineWarnList(); while (true) { try @@ -154,6 +155,7 @@ namespace SlnMesnac.WPF.Page machineStatusDtos.ForEach(x => OeeCollection(x)); //报警采集 machineStatusDtos.ForEach(x => MachineWarnCollection(x)); + } } else @@ -241,10 +243,10 @@ namespace SlnMesnac.WPF.Page if (dmsRecordAlarmTime != null) { sqlClient.AsTenant().BeginTran(); - DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == dmsRecordAlarmTime.AlarmRuleId && x.AlarmStatus=="0"); + DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == dmsRecordAlarmTime.AlarmRuleId && x.AlarmStatus == "0"); if (dmsRecordAlarmInfo != null) { - dmsRecordAlarmInfo.AlarmEndTime = DateTime.Now; + dmsRecordAlarmInfo.AlarmEndTime = DateTime.Now; dmsRecordAlarmInfo.AlarmStatus = "2"; dmsRecordAlarmInfo.UpdateTime = DateTime.Now; sqlClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand(); @@ -294,13 +296,17 @@ namespace SlnMesnac.WPF.Page sqlClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmInfo).ExecuteCommand(); sqlClient.AsTenant().CommitTran(); WarningList = dmsRecordAlarmTimeService.GetMachineWarnList(); + + #region 停止当前设备 + StopAndMessageWarn(machineStatusDto.warnStatus); + #endregion } else { sqlClient.AsTenant().BeginTran(); dmsRecordAlarmTime.UpdateTime = DateTime.Now; dmsRecordAlarmTime.UpdateBy = "SlnMesnac"; - DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlClient.AsTenant().GetConnection("mes").Queryable().First(x=>x.AlarmRuleId==warnRuleId); + DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == warnRuleId); if (dmsRecordAlarmInfo != null) { dmsRecordAlarmInfo.UpdateTime = DateTime.Now; @@ -309,11 +315,12 @@ namespace SlnMesnac.WPF.Page sqlClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmTime).ExecuteCommand(); sqlClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand(); sqlClient.AsTenant().CommitTran(); + WarningList = dmsRecordAlarmTimeService.GetMachineWarnList(); } - + } - - + + } catch (Exception ex) { @@ -322,6 +329,73 @@ namespace SlnMesnac.WPF.Page } } + /// + /// 停止该报警对应的机器及之前的机器,并弹框提醒 + /// + private void StopAndMessageWarn(WarnStatusEnum warnStatusEnum) + { + int status = getStopLevelByWarnStatus(warnStatusEnum); + Application.Current.Dispatcher.Invoke(() => + { + var alarmWindow = new SystemAlarmWindow(); + var viewModel = new SystemAlarmViewModel(); + viewModel.AlarmMsg = warnStatusEnum.ToString(); + viewModel.AlarmConfirmed += (sender, isConfirmed) => + { + alarmWindow.Close(); + }; + + alarmWindow.DataContext = viewModel; + + alarmWindow.ShowDialog(); + }); + if(status >= 0) + { + Task.Run(() => + { + StopMachine(status); + }); + } + + } + + /// + /// 根据报警状态获取停止等级 + /// -1不停止机器,只弹框报警 + /// + /// + /// + private int getStopLevelByWarnStatus(WarnStatusEnum warnStatusEnum) + { + if (warnStatusEnum == WarnStatusEnum.拆包机堵料停螺旋) + { + return 0; + } + else if (warnStatusEnum.ToString().Contains("烘干机")) + { + return 3; + } + else if(warnStatusEnum == WarnStatusEnum.螺旋机螺旋1变频器报警) + { + return 4; + }else if (warnStatusEnum == WarnStatusEnum.螺旋机螺旋2变频器报警) + { + return 6; + }else if (warnStatusEnum.ToString().Contains("磁选机")) + { + return 5; + }else + { + return -1; + } + } + + + + + + + #region 监测缓存区重量,动态调整配方频率 /// @@ -390,7 +464,7 @@ namespace SlnMesnac.WPF.Page }); } - + /// /// 判断缓存区重量是否满足配方要求 @@ -671,30 +745,12 @@ namespace SlnMesnac.WPF.Page #region 依次按序停止 Task.Run(() => { - plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程启动"), false); - SendPulseSignal("拆包机远程停止"); - Thread.Sleep(MachineSleep); - bool unPackStatus1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机系统运行状态")); - if (unPackStatus1) + bool result =StopMachine(99); + if (result) { - MessageBox.Show("一键停止失败,拆包机未停止,请先检查"); - return; + MessageBoxAndLog("一键停止所有机器成功!"); } - - #region 烘干机 - SendPulseSignal("烘干机螺旋停止"); - Thread.Sleep(MachineSleep); - SendPulseSignal("烘干机燃烧停止"); - Thread.Sleep(MachineSleep); - SendPulseSignal("烘干机风机停止"); - #endregion - plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1启动"), false); - Thread.Sleep(MachineSleep); - SendPulseSignal("磁选机一键停止"); - Thread.Sleep(MachineSleep); - plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"), false); - - MessageBoxAndLog("一键停止所有机器成功!"); + }); #endregion //StopButton.IsEnabled = false; @@ -708,6 +764,60 @@ namespace SlnMesnac.WPF.Page } } + /// + /// 停止机器分级,不同级别停不同机器 + /// 0:停止拆包机 + /// 1:停止拆包机,烘干机螺旋 + /// 2:停止拆包机,烘干机螺旋,`烘干机燃烧 + /// 3:停止拆包机,烘干机螺旋,`烘干机燃烧,烘干机风机 + /// 4:停止拆包机,烘干机螺旋,`烘干机燃烧,烘干机风机,螺旋1 + /// 5:停止拆包机,烘干机螺旋,`烘干机燃烧,烘干机风机,螺旋1,磁选机 + /// 6:停止拆包机,烘干机螺旋,`烘干机燃烧,烘干机风机,螺旋1,磁选机,螺旋2 + /// + /// + /// + private bool StopMachine(int stopLevel = 0) + { + bool result = false; + + plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程启动"), false); + SendPulseSignal("拆包机远程停止"); + if (stopLevel < 1) return result; + Thread.Sleep(MachineSleep); + bool unPackStatus1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机系统运行状态")); + if (unPackStatus1) + { + MessageBox.Show("拆包机未成功停止,请先检查"); + return result; + } + + #region 烘干机 + SendPulseSignal("烘干机螺旋停止"); + if(stopLevel < 2) return result; + + Thread.Sleep(MachineSleep); + SendPulseSignal("烘干机燃烧停止"); + if (stopLevel < 3) return result; + + Thread.Sleep(MachineSleep); + SendPulseSignal("烘干机风机停止"); + #endregion + + if (stopLevel < 4) return result; + plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1启动"), false); + if(stopLevel < 5) return result; + Thread.Sleep(MachineSleep); + SendPulseSignal("磁选机一键停止"); + if(stopLevel < 6) return result; + Thread.Sleep(MachineSleep); + plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"), false); + result = true; + // MessageBoxAndLog("一键停止所有机器成功!"); + return result; + } + + + /// /// 急停 /// @@ -1407,7 +1517,7 @@ namespace SlnMesnac.WPF.Page /// /// 拆包机参数监控 /// - private async void RefreshUnPack(List machineStatusDtos) + private void RefreshUnPack(List machineStatusDtos) { try { @@ -1429,7 +1539,7 @@ namespace SlnMesnac.WPF.Page float unPackStatus13 = plc.readFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机废袋机频率反馈")); - await App.Current.Dispatcher.BeginInvoke((Action)(() => + App.Current.Dispatcher.BeginInvoke((Action)(() => { UnpackStatus0.Fill = unPackStatus0 ? Brushes.Green : Brushes.Red; UnpackStatus1.Fill = unPackStatus1 ? Brushes.Green : Brushes.Red; @@ -1448,21 +1558,42 @@ namespace SlnMesnac.WPF.Page UnpackStatus12.Text = unPackStatus12.ToString("F2"); UnpackStatus13.Text = unPackStatus13.ToString("F2"); + })); - MachineStatusDto machineStatusDto = new MachineStatusDto(); - machineStatusDto.deviceId = 1016; - machineStatusDto.status = unPackStatus1; - if (unPackStatus8) - { - machineStatusDto.warnStatus = WarnStatusEnum.拆包机堵料停螺旋; - } - else - { - machineStatusDto.warnStatus = WarnStatusEnum.无报警; - } - machineStatusDtos.Add(machineStatusDto); + MachineStatusDto machineStatusDto = new MachineStatusDto(); + machineStatusDto.deviceId = 1016; + machineStatusDto.status = unPackStatus1; + if (unPackStatus8) + { + machineStatusDto.warnStatus = WarnStatusEnum.拆包机堵料停螺旋; + } + else + { + machineStatusDto.warnStatus = WarnStatusEnum.无报警; + } + machineStatusDtos.Add(machineStatusDto); - })); + //if (unPackStatus8) + //{ + // StopMachine(0); + // string msg = $"拆包机设备故障:{WarnStatusEnum.拆包机堵料停螺旋.ToString()},自动关闭拆包机"; + // _logger.LogError(msg); + + // Application.Current.Dispatcher.Invoke(() => + // { + // var alarmWindow = new SystemAlarmWindow(); + // var viewModel = new SystemAlarmViewModel(); + // viewModel.AlarmMsg = msg; + // viewModel.AlarmConfirmed += (sender, isConfirmed) => + // { + // alarmWindow.Close(); + // }; + + // alarmWindow.DataContext = viewModel; + + // alarmWindow.ShowDialog(); + // }); + //} } catch (Exception ex) { @@ -1476,7 +1607,7 @@ namespace SlnMesnac.WPF.Page /// /// 磁选机参数监控 /// - private async void RefreshMagNet(List machineStatusDtos) + private void RefreshMagNet(List machineStatusDtos) { try { @@ -1485,7 +1616,7 @@ namespace SlnMesnac.WPF.Page bool signal2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机MES允许远程")); bool signal3 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("磁选机设备故障反馈")); - await App.Current.Dispatcher.BeginInvoke((Action)(() => + App.Current.Dispatcher.BeginInvoke((Action)(() => { MagNetStatus1.Fill = signal0 ? Brushes.Green : Brushes.Red; MagNetStatus2.Fill = signal1 ? Brushes.Green : Brushes.Red; @@ -1507,8 +1638,15 @@ namespace SlnMesnac.WPF.Page } machineStatusDtos.Add(machineStatusDto); + //if (signal3) + //{ + // Task.Run(() => + // { + // StopMachine(5); + // _logger.LogError("磁选机设备故障,自动关闭磁选机及以前的设备"); + // }); + //} - } catch (Exception ex) @@ -1521,7 +1659,7 @@ namespace SlnMesnac.WPF.Page /// /// 螺旋机参数监控 /// - private async void RefreshSpiral(List machineStatusDtos) + private void RefreshSpiral(List machineStatusDtos) { try { @@ -1540,7 +1678,7 @@ namespace SlnMesnac.WPF.Page int speed1Set = int.Parse(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度设定值")); int speed2Set = int.Parse(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度设定值")); - await App.Current.Dispatcher.BeginInvoke((Action)(() => + App.Current.Dispatcher.BeginInvoke((Action)(() => { SpiralSignal0.Fill = signal0 ? Brushes.Green : Brushes.Red; SpiralSignal1.Fill = signal1 ? Brushes.Green : Brushes.Red; @@ -1573,6 +1711,22 @@ namespace SlnMesnac.WPF.Page machineStatusDtos.Add(machineStatusDto); + //if (signal5) + //{ + // Task.Run(() => + // { + // StopMachine(6); + // _logger.LogError("螺旋2设备故障,自动关闭螺旋2及以前的设备"); + // }); + //}else if (signal4) + //{ + // Task.Run(() => + // { + // StopMachine(4); + // _logger.LogError("螺旋1设备故障,自动关闭螺旋1及以前的设备"); + // }); + //} + } catch (Exception ex) { @@ -1587,7 +1741,7 @@ namespace SlnMesnac.WPF.Page /// /// 烘干机参数监控 /// - private async void RefreshHot(List machineStatusDtos) + private void RefreshHot(List machineStatusDtos) { try { @@ -1612,7 +1766,7 @@ namespace SlnMesnac.WPF.Page int signal7_2 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机报警")); - await App.Current.Dispatcher.BeginInvoke((Action)(() => + App.Current.Dispatcher.BeginInvoke((Action)(() => { HotSignal1_1.Fill = signal1_1 == 1 ? Brushes.Green : Brushes.Red; HotSignal1_1_Value.Text = ChangeHotStatus(signal1_1); @@ -1638,34 +1792,44 @@ namespace SlnMesnac.WPF.Page HotSignal7_2.Fill = signal7_2 == 0 ? Brushes.Green : Brushes.Red; HotSignal7_2_Value.Text = ChangeHotWarn(signal7_2); + })); - MachineStatusDto machineStatusDto = new MachineStatusDto(); - machineStatusDto.deviceId = 1019; - machineStatusDto.status = signal1_2 && signal2_2; - if (signal7_1) - { - machineStatusDto.warnStatus = WarnStatusEnum.烘干机堵料报警; - } - else if (signal7_2 > 0) - { - switch (signal7_2) - { - case 1: machineStatusDto.warnStatus = WarnStatusEnum.烘干机风机故障; break; - case 2: machineStatusDto.warnStatus = WarnStatusEnum.烘干机燃烧机故障; break; - case 4: machineStatusDto.warnStatus = WarnStatusEnum.烘干机传动故障; break; - case 16: machineStatusDto.warnStatus = WarnStatusEnum.烘干机烘干温度超温; break; - case 32: machineStatusDto.warnStatus = WarnStatusEnum.烘干机温控模块通讯超时; break; - default: break; - } - } - else + + MachineStatusDto machineStatusDto = new MachineStatusDto(); + machineStatusDto.deviceId = 1019; + machineStatusDto.status = signal1_2 && signal2_2; + if (signal7_1) + { + machineStatusDto.warnStatus = WarnStatusEnum.烘干机堵料报警; + } + else if (signal7_2 > 0) + { + switch (signal7_2) { - machineStatusDto.warnStatus = WarnStatusEnum.无报警; + + case 1: machineStatusDto.warnStatus = WarnStatusEnum.烘干机风机故障; break; + case 2: machineStatusDto.warnStatus = WarnStatusEnum.烘干机燃烧机故障; break; + case 4: machineStatusDto.warnStatus = WarnStatusEnum.烘干机传动故障; break; + case 16: machineStatusDto.warnStatus = WarnStatusEnum.烘干机烘干温度超温; break; + case 32: machineStatusDto.warnStatus = WarnStatusEnum.烘干机温控模块通讯超时; break; + default: break; } - machineStatusDtos.Add(machineStatusDto); + } + else + { + machineStatusDto.warnStatus = WarnStatusEnum.无报警; + } + machineStatusDtos.Add(machineStatusDto); - })); + //if (signal7_1 || signal7_2 > 0 && signal7_2 <= 4) + //{ + // Task.Run(() => + // { + // StopMachine(3); + // _logger.LogError($"烘干机设备故障:{machineStatusDto.warnStatus.ToString()},自动关闭烘干机及以前的设备"); + // }); + //} } catch (Exception ex) { diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json index 345fe2f..f852797 100644 --- a/SlnMesnac.WPF/appsettings.json +++ b/SlnMesnac.WPF/appsettings.json @@ -38,8 +38,8 @@ { "configId": 1, "plcType": "SiemensPlc", - // "plcIp": "192.168.2.220", - "plcIp": "127.0.0.1", + // "plcIp": "192.168.2.220", + "plcIp": "127.0.0.1", "plcPort": 103, "plcKey": "plc", "isFlage": true