From 926ff42b5b7963df7e21931780cc581d5c7b1238 Mon Sep 17 00:00:00 2001 From: liuwf Date: Sat, 3 Aug 2024 10:18:12 +0800 Subject: [PATCH] =?UTF-8?q?change-=E4=BF=AE=E6=94=B9=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs | 184 +++++++++++++++++----- 1 file changed, 147 insertions(+), 37 deletions(-) diff --git a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs index 2be2bf9..7f4cda5 100644 --- a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs +++ b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Newtonsoft.Json.Linq; using SlnMesnac.Business; using SlnMesnac.Business.@base; using SlnMesnac.Plc; @@ -110,26 +111,25 @@ namespace SlnMesnac.WPF.Page bool Spiral1Status = StartSpiral1(); if (!MagNetStatus) return; - #endregion + //4.烘干机:烘干螺旋、烘干风机、烘干燃烧 - #region 烘干机 - SendPulseSignal("烘干机螺旋启动"); - Thread.Sleep(MachineSleep); - SendPulseSignal("烘干机风机启动"); - Thread.Sleep(MachineSleep); - SendPulseSignal("烘干机燃烧启动"); - #endregion + bool DryerStatus1 = StartDryerMagNet(); + if (!DryerStatus1) return; + bool DryerStatus2 = StartDryerFan(); + if (!DryerStatus2) return; + bool DryerStatus3 = StartDryerHot(); + if (!DryerStatus3) return; - #region 拆包机 - plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程急停"), false); - plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程停止"), false); - SendPulseSignal("拆包机远程启动"); + //5.拆包机 + bool unpackStatus = StartUnPack(); #endregion - Thread.Sleep(MachineSleep); - - }); + if (unpackStatus) + { + MessageBoxAndLog("一键启动所有机器成功!"); + } - + }); + }catch(Exception ex) { _logger.LogError($"一键启动:{ex.Message}"); @@ -186,7 +186,7 @@ namespace SlnMesnac.WPF.Page Thread.Sleep(MachineSleep); plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"), false); #endregion - + MessageBoxAndLog("一键停止所有机器成功!"); }); #endregion //StopButton.IsEnabled = false; @@ -411,10 +411,7 @@ namespace SlnMesnac.WPF.Page { try { - Task.Run(() => - { - SendPulseSignal("烘干机螺旋启动"); - }); + StartDryerMagNet(); } catch (Exception ex) { @@ -451,20 +448,7 @@ namespace SlnMesnac.WPF.Page /// private void StartDryerHotButton_Click(object sender, RoutedEventArgs e) { - try - { - Task.Run(() => - { - - SendPulseSignal("烘干机燃烧启动"); - }); - - - } - catch (Exception ex) - { - _logger.LogError($"烘干机燃烧启动:{ex.Message}"); - } + StartDryerHot(); } /// @@ -581,7 +565,7 @@ namespace SlnMesnac.WPF.Page int value2 = int.Parse(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度值")) * 100; bool startFlag = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动")); int speed2 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度反馈")); - if (startFlag) + if (!startFlag) { MessageBox.Show($"前提条件螺旋2未成功启动,请检查后重新启动"); return false; @@ -640,7 +624,7 @@ namespace SlnMesnac.WPF.Page plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1启动"), true); plc.writeInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度设置"), value1 * 100); Thread.Sleep(MachineSleep); - result = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动")); + result = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1启动")); } catch (Exception ex) @@ -652,6 +636,132 @@ namespace SlnMesnac.WPF.Page } + #region 烘干机 + /// + /// 烘干机螺旋启动/前提:check:螺旋1启动且速度达到值 + /// + private bool StartDryerMagNet() + { + bool result = false; + try + { + int value1 = int.Parse(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度值")) * 100; + bool startFlag = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1启动")); + int speed1 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度反馈")); + if (!startFlag) + { + MessageBox.Show($"烘干机螺旋启动失败:前提条件螺旋1未成功启动,请检查后重新启动"); + return false; + } + if (speed1 < value1 * 0.8) + { + // plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"), false); + MessageBox.Show($"烘干机螺旋启动失败:前提条件螺旋1速度{speed1}未达到设定值{value1}的下限阈值80%,请检查后重新启动"); + return false; + } + int value = int.Parse(baseBusiness.GetPlcAddressByConfigKey("烘干机螺旋频率设定值")); + SendPulseSignal("烘干机螺旋启动"); + plc.writeInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机螺旋频率设定"), value1 * 100); + Thread.Sleep(MachineSleep/2); + return true; + } + catch (Exception ex) + { + MessageBoxAndLog($"烘干机螺旋启动异常:{ex.Message}", true); + result = false; + } + return result; + } + + /// + /// 烘干机风机启动/前提:check:烘干机螺旋启动 + /// + private bool StartDryerFan() + { + bool result = false; + try + { + + bool startFlag = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机反馈传动启动")); + if (!startFlag) + { + MessageBox.Show($"烘干机风机启动失败:前提条件烘干机螺旋未成功启动,请检查后重新启动"); + return false; + } + SendPulseSignal("烘干机风机启动"); + Thread.Sleep(MachineSleep); + return true; + } + catch (Exception ex) + { + MessageBoxAndLog($"烘干机风机启动异常:{ex.Message}", true); + result = false; + } + return result; + } + + + /// + /// 烘干机燃烧启动/前提:check:烘干机风机启动 + /// + private bool StartDryerHot() + { + bool result = false; + try + { + bool startFlag = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机反馈风机启动")); + if (!startFlag) + { + MessageBox.Show($"烘干机燃烧启动失败:前提条件烘干机风机未成功启动,请检查后重新启动"); + return false; + } + int value = int.Parse(baseBusiness.GetPlcAddressByConfigKey("烘干机温度设定值")); + SendPulseSignal("烘干机燃烧启动"); + plc.writeInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机温度设定"), value *100); + Thread.Sleep(MachineSleep); + return true; + } + catch (Exception ex) + { + MessageBoxAndLog($"烘干机燃烧启动异常:{ex.Message}", true); + result = false; + } + return result; + } + + #endregion + + + /// + /// 拆包机启动/前提:check:燃烧机启动 + /// + private bool StartUnPack() + { + bool result = false; + try + { + bool startFlag = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机反馈燃烧启动")); + if (!startFlag) + { + MessageBox.Show($"拆包机启动失败:前提条件烘干机燃烧未成功启动,请检查后重新启动"); + return false; + } + + plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程急停"), false); + plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机远程停止"), false); + SendPulseSignal("拆包机远程启动"); + Thread.Sleep(MachineSleep); + return plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机运行状态系统")); + + } + catch (Exception ex) + { + MessageBoxAndLog($"拆包机启动异常:{ex.Message}", true); + result = false; + } + return result; + } + private void MessageBoxAndLog(string message,bool isError = false) {