From 4d0753eb3211407fbfbe2fee50072648ce662e63 Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Fri, 7 Aug 2026 12:38:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=A8=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FeiYu/App.xaml | 8 +- FeiYu/MainWindow.xaml | 68 ++++--- FeiYu/Styles.xaml | 388 ++++++++++++++++++++++--------------- Model/HSL/HslParent.cs | 2 +- Model/HSL/MitsubishiHsl.cs | 2 +- Model/HSL/OmronHsl.cs | 2 +- Model/HSL/PanasonicHsl.cs | 2 +- ViewModel/MainWindowVM.cs | 159 ++++++++++++--- ViewModel/PLCVM.cs | 4 +- Views/MainInterface.xaml | 161 +++++++++------ Views/StandWindow.xaml | 16 +- 11 files changed, 535 insertions(+), 277 deletions(-) diff --git a/FeiYu/App.xaml b/FeiYu/App.xaml index 4712973..ef0de92 100644 --- a/FeiYu/App.xaml +++ b/FeiYu/App.xaml @@ -10,11 +10,11 @@ - - - + + + - + diff --git a/FeiYu/MainWindow.xaml b/FeiYu/MainWindow.xaml index 437fcca..9e965fe 100644 --- a/FeiYu/MainWindow.xaml +++ b/FeiYu/MainWindow.xaml @@ -1,32 +1,54 @@ - + - + - + - - - - + + + + - - - + + + + @@ -42,11 +64,13 @@ - + + - + + - ../Resources/#方正宋一繁体,Segoe UI,Lucida Sans Unicode,Verdana - ../Resources/#苹果丽黑w36,Segoe UI,Lucida Sans Unicode,Verdana - ../Resources/#微软繁宋体,Segoe UI,Lucida Sans Unicode,Verdana - ../Resources/#宋体-粗体,Segoe UI,Lucida Sans Unicode,Verdana - ../Resources/#行楷体,Segoe UI,Lucida Sans Unicode,Verdana - + + ../Resources/#方正宋一繁体,Segoe UI,Lucida Sans Unicode,Verdana + ../Resources/#苹果丽黑w36,Segoe UI,Lucida Sans Unicode,Verdana + ../Resources/#微软繁宋体,Segoe UI,Lucida Sans Unicode,Verdana + ../Resources/#宋体-粗体,Segoe UI,Lucida Sans Unicode,Verdana + ../Resources/#行楷体,Segoe UI,Lucida Sans Unicode,Verdana + - + - - + + - + - - - + - + - + - + - + - + - + - + - + - + - - - - - - - - - + + + + + + + - - + + @@ -511,14 +581,15 @@ - + - + - - + + \ No newline at end of file diff --git a/Model/HSL/HslParent.cs b/Model/HSL/HslParent.cs index 43b998a..70aa849 100644 --- a/Model/HSL/HslParent.cs +++ b/Model/HSL/HslParent.cs @@ -457,7 +457,7 @@ namespace Model.HSL /// /// /// - public abstract bool Write(string address, params bool[] val); + public abstract bool Write(string address, bool b); #endregion diff --git a/Model/HSL/MitsubishiHsl.cs b/Model/HSL/MitsubishiHsl.cs index 396cb40..c7316c6 100644 --- a/Model/HSL/MitsubishiHsl.cs +++ b/Model/HSL/MitsubishiHsl.cs @@ -652,7 +652,7 @@ namespace Model.HSL /// /// /// - public override bool Write(string address, params bool[] val) + public override bool Write(string address, bool val) { return ConnectionType == 1 ? NetworkConn.Write(address, val).IsSuccess: SerialConn.Write(address, val).IsSuccess; } diff --git a/Model/HSL/OmronHsl.cs b/Model/HSL/OmronHsl.cs index d5fb2b6..f23e7cc 100644 --- a/Model/HSL/OmronHsl.cs +++ b/Model/HSL/OmronHsl.cs @@ -649,7 +649,7 @@ namespace Model.HSL /// /// /// - public override bool Write(string address, params bool[] val) + public override bool Write(string address, bool val) { return ConnectionType == 1 ? NetworkConn.Write(address, val).IsSuccess : SerialConn.Write(address, val).IsSuccess; } diff --git a/Model/HSL/PanasonicHsl.cs b/Model/HSL/PanasonicHsl.cs index 0c8c51c..8757917 100644 --- a/Model/HSL/PanasonicHsl.cs +++ b/Model/HSL/PanasonicHsl.cs @@ -661,7 +661,7 @@ namespace Model.HSL /// /// /// - public override bool Write(string address, params bool[] val) + public override bool Write(string address, bool val) { return ConnectionType == 1 ? NetworkConn.Write(address, val).IsSuccess : SerialConn.Write(address, val).IsSuccess; } diff --git a/ViewModel/MainWindowVM.cs b/ViewModel/MainWindowVM.cs index 422baa8..eb9c9ba 100644 --- a/ViewModel/MainWindowVM.cs +++ b/ViewModel/MainWindowVM.cs @@ -1,48 +1,30 @@ using Community; -using ControlzEx.Theming; using DAL; -using HalconDotNet; -using LiveCharts; using LiveCharts.Defaults; -using LiveCharts.Wpf; -using MahApps.Metro.Controls; using MahApps.Metro.Controls.Dialogs; using Microsoft.Win32; using Model; using Model.HSL; using Model.MotionControl; using Model.Vision; -using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Configuration; using System.Data; using System.IO; -using System.IO.Ports; using System.Linq; -using System.Net; using System.Reflection; -using System.ServiceProcess; using System.Text; -using System.Text.RegularExpressions; using System.Threading; -using System.Threading.Tasks; -using System.Web.Hosting; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; -using System.Windows.Media.Media3D; using System.Windows.Threading; -using System.Xml; -using System.Xml.Linq; -using System.Xml.Serialization; using ViewModel.MotionControl; using ViewModel.Robots; using ViewModel.Vision; using Views; -using Views.Vision; namespace ViewModel { @@ -62,6 +44,40 @@ namespace ViewModel } } + private DelegateCommand _OpenDoor; + public DelegateCommand OpenDoor => + _OpenDoor = _OpenDoor ?? new DelegateCommand() { ExecuteAction = ExecuteOpenDoor }; + + void ExecuteOpenDoor(object obj) + { + if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green) + { + if (Door != "未锁") + { + if (RunStatu == RunStatuEnum.Normal) return; + MyPLC.PLC.Write("Y2", false); + Door = "未锁"; + } + else + { + MyPLC.PLC.Write("Y2", true); + Door = "已锁"; + } + } + + + } + + private string _Door = "未锁"; + public string Door + { + get { return _Door; } + set + { + _Door = value; + this.RaisePropertyChanged("Door"); + } + } #region 通讯服务器对象 private CommunicationServerVM serverComm; /// @@ -582,35 +598,92 @@ namespace ViewModel ShowStatu.StatusBackground = ColorStr.Yellow; ShowStatu.StatusForeground = ColorStr.Black; ShowStatu.StatuInfo = "准备中"; + if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green) + { + //Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器 + MyPLC.PLC.Write("Y12", false); + MyPLC.PLC.Write("Y13", true); + MyPLC.PLC.Write("Y14", false); + MyPLC.PLC.Write("Y15", false); + } break; case RunStatuEnum.Prepareations: ShowStatu.StatusBackground = ColorStr.Green; ShowStatu.StatusForeground = ColorStr.Black; ShowStatu.StatuInfo = "准备就绪"; + if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green) + { + //Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器 + MyPLC.PLC.Write("Y12", false); + MyPLC.PLC.Write("Y13", true); + MyPLC.PLC.Write("Y14", false); + MyPLC.PLC.Write("Y15", false); + } break; case RunStatuEnum.Normal: ShowStatu.StatusBackground = ColorStr.Green; ShowStatu.StatusForeground = ColorStr.Black; ShowStatu.StatuInfo = "运行中"; + if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green) + { + //Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器 + MyPLC.PLC.Write("Y12", false); + MyPLC.PLC.Write("Y13", false); + MyPLC.PLC.Write("Y14", true); + MyPLC.PLC.Write("Y15", false); + } break; case RunStatuEnum.Stop: ShowStatu.StatusBackground = ColorStr.Yellow; ShowStatu.StatusForeground = ColorStr.Black; ShowStatu.StatuInfo = "停止中"; + + if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green) + { + //Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器 + MyPLC.PLC.Write("Y12", false); + MyPLC.PLC.Write("Y13", true); + MyPLC.PLC.Write("Y14", false); + MyPLC.PLC.Write("Y15", false); + } break; case RunStatuEnum.EmgStop: ShowStatu.StatusBackground = ColorStr.Yellow; ShowStatu.StatusForeground = ColorStr.Black; ShowStatu.StatuInfo = "紧急停止中"; + if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green) + { + //Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器 + MyPLC.PLC.Write("Y12", true); + MyPLC.PLC.Write("Y13", false); + MyPLC.PLC.Write("Y14", false); + MyPLC.PLC.Write("Y15", false); + } break; case RunStatuEnum.Exceptional: ShowStatu.StatusBackground = ColorStr.Red; ShowStatu.StatusForeground = ColorStr.White; + if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green) + { + //Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器 + MyPLC.PLC.Write("Y12", false); + MyPLC.PLC.Write("Y13", true); + MyPLC.PLC.Write("Y14", false); + MyPLC.PLC.Write("Y15", true); + } break; case RunStatuEnum.Unknown: ShowStatu.StatusBackground = ColorStr.Yellow; ShowStatu.StatusForeground = ColorStr.Black; ShowStatu.StatuInfo = "状态未知"; + if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green) + { + //Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器 + MyPLC.PLC.Write("Y12", false); + MyPLC.PLC.Write("Y13", false); + MyPLC.PLC.Write("Y14", false); + MyPLC.PLC.Write("Y15", false); + } break; } @@ -1930,7 +2003,7 @@ namespace ViewModel private void Run() { while (true) - { + { if (RunStatu == RunStatuEnum.Normal) { if (!fir) @@ -1941,14 +2014,32 @@ namespace ViewModel if (MyPLC.PLC.PlcStatus.StatusBackground != ColorStr.Green) { + ExcepStop("PLC未连接"); return; } + if (MyPLC.PLC.ReadBool("X0") == false) + { + if (powerTime.AddSeconds(1) < DateTime.Now) + { + ExcepStop("测试电源未开"); + } + + + } + else + { + powerTime = DateTime.Now; + } + LogicDispatch(LogicDispatchFlow); } + } } + + private DateTime powerTime = DateTime.Now; #endregion #region 大总管 @@ -1989,6 +2080,8 @@ namespace ViewModel TimeSpan ts = DateTime.Now.Subtract(RunStartTime).Duration(); TestTimeSpan = (ts + TempTimeSpan); RunTimeShow.StatuInfo = string.Format("{0}:{1}:{2}", TestTimeSpan.Hours, TestTimeSpan.Minutes, TestTimeSpan.Seconds); + + } else { @@ -1996,12 +2089,14 @@ namespace ViewModel } + switch (MyFlow.RunStep) { case GengralProcessEnum.Start: //老化柜温度要到达 if (CurrHeatShow.StatusForeground == ColorStr.Green || CurrentMachine.RunningMode) { + if (!Testing) { RunStartTime = DateTime.Now; @@ -2013,8 +2108,13 @@ namespace ViewModel //老化时间到 测试结束 if (TestTimeSpan.TotalMinutes >= CurrentMachine.MyPar.TestTime || GrayCount >= AllGrouhandList.Count) { - Testing = false; + if (Door != "未锁") + { + MyPLC.PLC.Write("Y2", false);//开门 + Door = "未锁"; + } + Testing = false; RunStatu = RunStatuEnum.Prepareations; ShowStatu.StatuInfo = "测试完成"; @@ -2026,7 +2126,7 @@ namespace ViewModel foreach (var item in AllGrouhandList) { CurrentMachine.Quantitys++; - + //产品测试测次数等于NG次数 直接判定产品NG 变大红色 if (item.State.TestCount > 0 && item.State.TestCount <= item.State.TestCountNG) { @@ -2039,10 +2139,8 @@ namespace ViewModel item.State.StatusBackground = Colors.Green.ToString(); item.TestData += "OK"; CurrentMachine.Produce++; - } + } } - - try { //最后结算 是否为终极不良 记录日志 @@ -2066,16 +2164,20 @@ namespace ViewModel } else { + + + MyHand = AllGrouhandList.Where(w => w.State.StatusBackground == ColorStr.Blue).FirstOrDefault(); if (MyHand != null) { + MyPLC.PLC.Write("Y2", true); //锁门 + Door = "已锁"; MyFlow.RunStep++; MyFlow.RunTime = DateTime.Now; } else { AllGrouhandList.ForEach(w => { w.State.StatusBackground = w.State.StatusBackground != ColorStr.Gray ? ColorStr.Blue : ColorStr.Gray; }); - } } } @@ -2186,7 +2288,7 @@ namespace ViewModel CurrentMachine.Quantitys++; CurrentMachine.Produce++; } - + try { TestResultLog(MyHand, ShowDataList, resStr); @@ -2997,6 +3099,9 @@ namespace ViewModel /// public void ExcepStop(string showMag) { + + + if (RunStatu != RunStatuEnum.Stop && RunStatu != RunStatuEnum.EmgStop && RunStatu != RunStatuEnum.Exceptional) { TempTimeSpan = TestTimeSpan;//记录缓存时间 @@ -3561,7 +3666,7 @@ namespace ViewModel { sb.Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")).Append(",").Append(item.TestData).Append(",\r\n"); } - + //将字符串流数据写入文件 sw.WriteLine(sb); //刷新文件流 diff --git a/ViewModel/PLCVM.cs b/ViewModel/PLCVM.cs index e60ec07..b704406 100644 --- a/ViewModel/PLCVM.cs +++ b/ViewModel/PLCVM.cs @@ -7,8 +7,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO.Ports; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ViewModel { @@ -486,7 +484,7 @@ namespace ViewModel break; case 2: //bool - MessShow = SelestHsl.PLC.Write(WriteAddress, new bool[] { Convert.ToBoolean(WriteValue) }) == true ? "写入成功" : "写入失败"; + MessShow = SelestHsl.PLC.Write(WriteAddress, Convert.ToBoolean(WriteValue)) == true ? "写入成功" : "写入失败"; break; case 3: //short diff --git a/Views/MainInterface.xaml b/Views/MainInterface.xaml index b26bd64..2f7a3d5 100644 --- a/Views/MainInterface.xaml +++ b/Views/MainInterface.xaml @@ -1,48 +1,66 @@  + mc:Ignorable="d" + d:DesignHeight="1080" + d:DesignWidth="1920"> - - + + + + - - - + + + + + + - - + + + + - - + + - - - - - - + + + + + + + + + + + @@ -52,47 +70,76 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - + + + + + + + + + + - - + + + diff --git a/Views/StandWindow.xaml b/Views/StandWindow.xaml index 4ec9cc6..5816131 100644 --- a/Views/StandWindow.xaml +++ b/Views/StandWindow.xaml @@ -24,6 +24,7 @@ + @@ -32,10 +33,17 @@ - - - - + + + + + + +