From 75b44df7e95d4a488050cfe659e310591be16ddf Mon Sep 17 00:00:00 2001 From: liuwf Date: Thu, 10 Oct 2024 18:36:22 +0800 Subject: [PATCH] =?UTF-8?q?add-=E6=B7=BB=E5=8A=A0=E9=A6=96=E9=A1=B5RFID?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E3=80=81=E5=96=B7=E7=A0=81=E6=9C=BA=E3=80=81?= =?UTF-8?q?PLC=E7=9B=91=E6=8E=A7=E5=B1=95=E7=A4=BA=E5=8F=8A=E6=96=AD?= =?UTF-8?q?=E7=BA=BF=E9=87=8D=E8=BF=9E=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Business/ProdCompletionBusiness.cs | 4 +- SlnMesnac.Extensions/PlcFactorySetup.cs | 21 ++-- SlnMesnac.Plc/Factory/InovanceFactory.cs | 5 + SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs | 5 + SlnMesnac.Plc/Factory/OmronNJFactory.cs | 5 + SlnMesnac.Plc/Factory/SiemensFactory.cs | 27 ++++- SlnMesnac.Plc/PlcAbsractFactory.cs | 10 +- SlnMesnac.WPF/MainWindow.xaml | 67 ++++++++++- .../ViewModel/MainWindowViewModel.cs | 113 ++++++++++++++++-- SlnMesnac.WPF/appsettings.json | 2 +- 10 files changed, 231 insertions(+), 28 deletions(-) diff --git a/SlnMesnac.Business/ProdCompletionBusiness.cs b/SlnMesnac.Business/ProdCompletionBusiness.cs index d7f07f0..2d54e03 100644 --- a/SlnMesnac.Business/ProdCompletionBusiness.cs +++ b/SlnMesnac.Business/ProdCompletionBusiness.cs @@ -52,8 +52,8 @@ namespace SlnMesnac.Business public class ProdCompletionBusiness : BaseBusiness { private FJ500Comm.FJ500SP fj500s = new FJ500Comm.FJ500SP(); - //喷码机喷码失败或者设备状态检查重试次数 - private int PmTryAmount = 0; + //喷码机喷码失败或者设备状态检查重试次数,0代表状态正常 + public static int PmTryAmount = 0; //喷码机心跳,每次收到回复刷新时间,如果超过1分钟,则认为喷码机断开连接,添加一条报警 private DateTime PmHeartTime = DateTime.Now; private readonly IMesProductPlanService _mesProductPlanService; diff --git a/SlnMesnac.Extensions/PlcFactorySetup.cs b/SlnMesnac.Extensions/PlcFactorySetup.cs index 220c06c..f8f6b36 100644 --- a/SlnMesnac.Extensions/PlcFactorySetup.cs +++ b/SlnMesnac.Extensions/PlcFactorySetup.cs @@ -58,20 +58,23 @@ namespace SlnMesnac.Extensions var connectResult = _plc.Connect(item.plcIp, item.plcPort); if (connectResult) { - Log.Information($"PLC锛歿item.plcIp}:{item.plcPort};杩炴帴鎴愬姛锛屾椂闂达細{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); - _plc.ConfigKey = item.plcKey; - if (absractFactories.Contains(_plc)) - { - absractFactories.Remove(_plc); - } + Log.Information($"PLC锛歿item.plcIp}:{item.plcPort};杩炴帴鎴愬姛锛屾椂闂达細{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + - absractFactories.Add(_plc); + } else { - Log.Information($"PLC锛歿item.plcIp}:{item.plcPort};杩炴帴澶辫触锛屾椂闂达細{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + Log.Information($"PLC锛歿item.plcIp}:{item.plcPort};杩炴帴澶辫触锛屾椂闂达細{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); } + _plc.ConfigKey = item.plcKey; + if (absractFactories.Contains(_plc)) + { + absractFactories.Remove(_plc); + } + + absractFactories.Add(_plc); } } } @@ -85,7 +88,7 @@ namespace SlnMesnac.Extensions }); } - private static PlcAbsractFactory InitPlc(IServiceProvider serviceProvider, string plcType) + public static PlcAbsractFactory InitPlc(IServiceProvider serviceProvider, string plcType) { PlcAbsractFactory _plc = null; var _inovance = serviceProvider.GetRequiredService(); diff --git a/SlnMesnac.Plc/Factory/InovanceFactory.cs b/SlnMesnac.Plc/Factory/InovanceFactory.cs index 7dc52d2..de2292c 100644 --- a/SlnMesnac.Plc/Factory/InovanceFactory.cs +++ b/SlnMesnac.Plc/Factory/InovanceFactory.cs @@ -367,5 +367,10 @@ namespace SlnMesnac.Plc.Factory { throw new NotImplementedException(); } + + public override bool readHeartByAddress(string address) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs b/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs index f6f86e7..a7cc9d7 100644 --- a/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs +++ b/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs @@ -308,5 +308,10 @@ namespace SlnMesnac.Plc.Factory { throw new NotImplementedException(); } + + public override bool readHeartByAddress(string address) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/SlnMesnac.Plc/Factory/OmronNJFactory.cs b/SlnMesnac.Plc/Factory/OmronNJFactory.cs index 1223b06..0fa2f47 100644 --- a/SlnMesnac.Plc/Factory/OmronNJFactory.cs +++ b/SlnMesnac.Plc/Factory/OmronNJFactory.cs @@ -311,5 +311,10 @@ namespace SlnMesnac.Plc.Factory { throw new NotImplementedException(); } + + public override bool readHeartByAddress(string address) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/SlnMesnac.Plc/Factory/SiemensFactory.cs b/SlnMesnac.Plc/Factory/SiemensFactory.cs index 6571c75..d166afd 100644 --- a/SlnMesnac.Plc/Factory/SiemensFactory.cs +++ b/SlnMesnac.Plc/Factory/SiemensFactory.cs @@ -67,10 +67,33 @@ namespace SlnMesnac.Plc.Factory } catch (Exception ex) { - throw new InvalidOperationException($"瑗块棬瀛怱绯诲垪PLC杩炴帴寮傚父锛歿ex.Message}"); + // throw new InvalidOperationException($"瑗块棬瀛怱绯诲垪PLC杩炴帴寮傚父锛歿ex.Message}"); + return false; } } - + + /// + /// 閫氳繃PLC鍦板潃璇诲彇蹇冭烦缁撴灉 + /// + /// + /// + public override bool readHeartByAddress(string address) + { + try + { + OperateResult read = s7.ReadBool(address); + if (!read.IsSuccess) + { + return false; + } + return true; + } + catch (Exception ex) + { + return false; + } + } + /// /// 鏂紑杩炴帴 /// diff --git a/SlnMesnac.Plc/PlcAbsractFactory.cs b/SlnMesnac.Plc/PlcAbsractFactory.cs index 65925ce..c3a6a98 100644 --- a/SlnMesnac.Plc/PlcAbsractFactory.cs +++ b/SlnMesnac.Plc/PlcAbsractFactory.cs @@ -39,7 +39,15 @@ namespace SlnMesnac.Plc /// /// public abstract bool Connect(string ip, int port); - + + /// + /// 閫氳繃PLC鍦板潃璇诲彇蹇冭烦缁撴灉 + /// + /// + /// + public abstract bool readHeartByAddress(string address); + + /// /// 鏂紑杩炴帴 /// diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml index 8333b75..87adc8c 100644 --- a/SlnMesnac.WPF/MainWindow.xaml +++ b/SlnMesnac.WPF/MainWindow.xaml @@ -88,7 +88,7 @@ - + @@ -118,6 +118,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs index 3d6268e..dca08c9 100644 --- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs @@ -3,13 +3,20 @@ using GalaSoft.MvvmLight.Command; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using OracleInternal.Sharding; +using ServiceStack; +using SlnMesnac.Business; using SlnMesnac.Business.@base; +using SlnMesnac.Config; +using SlnMesnac.Plc; using SlnMesnac.TouchSocket; using SlnMesnac.WPF.Page; using SlnMesnac.WPF.Page.Generate; using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; +using System.Timers; using System.Windows; namespace SlnMesnac.WPF.ViewModel @@ -26,7 +33,9 @@ namespace SlnMesnac.WPF.ViewModel private readonly BaseConfigInfoPage configInfoPage = new BaseConfigInfoPage(); private readonly RecipeManagePage recipeManagePage = new RecipeManagePage(); private readonly AgvAndTaskMonitorPage agvAndTaskMonitorPage = new AgvAndTaskMonitorPage(); - + private System.Timers.Timer timer = new System.Timers.Timer(1000*5); + PlcAbsractFactory? plc = null; + private BaseBusiness? baseBusiness = null; #region 鍙傛暟瀹氫箟 /// /// PLC璁惧鐘舵 @@ -38,25 +47,26 @@ namespace SlnMesnac.WPF.ViewModel set { _PlcStatus = value; RaisePropertyChanged(nameof(PlcStatus)); } } /// - /// 绠卞3鎵爜鍣ㄧ姸鎬 + /// 鍠风爜鏈虹姸鎬 /// - private int _ShellScannerStatus = 0; - public int ShellScannerStatus + private int _PmStatus = 0; + public int PmStatus { - get { return _ShellScannerStatus; } - set { _ShellScannerStatus = value; RaisePropertyChanged(nameof(ShellScannerStatus)); } + get { return _PmStatus; } + set { _PmStatus = value; RaisePropertyChanged(nameof(PmStatus)); } } /// - /// 鍐呰儐鎵爜鍣ㄧ姸鎬 + /// RFID1鐘舵 /// - private int _BoldScannerStatus = 0; - public int BoldScannerStatus + private int _Out2FRfidStatus = 0; + public int Out2FRfidStatus { - get { return _BoldScannerStatus; } - set { _BoldScannerStatus = value; RaisePropertyChanged(nameof(BoldScannerStatus)); } + get { return _Out2FRfidStatus; } + set { _Out2FRfidStatus = value; RaisePropertyChanged(nameof(Out2FRfidStatus)); } } + public System.Windows.Controls.UserControl _content; public System.Windows.Controls.UserControl UserContent @@ -91,17 +101,96 @@ namespace SlnMesnac.WPF.ViewModel public MainWindowViewModel() { - _logger = App.ServiceProvider.GetService>(); UserContent = prodMgmtPage; ControlOnClickCommand = new RelayCommand(obj => ControlOnClick(obj)); FormControlCommand = new RelayCommand(x => FormControl(x)); + baseBusiness = App.ServiceProvider.GetService(); + plc = baseBusiness.GetPlcByKey("plc"); + StartLiseningStatus(); + checkStatus(); + } + + + /// + /// 鐩戝惉澶栭儴璁惧鐘舵:PLC銆佸柗鐮佹満銆丷FID + /// + private void StartLiseningStatus() + { + timer.Elapsed += new System.Timers.ElapsedEventHandler(LiseningStatus); + timer.AutoReset = true; + timer.Enabled = true; + timer.Start(); } + private void LiseningStatus(object?sender, ElapsedEventArgs e) + { + timer.Stop(); + checkStatus(); + 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; + } + } + #endregion + + #region 鍠风爜鏈虹姸鎬 + if (ProdCompletionBusiness.PmTryAmount == 0) + { + PmStatus = 1; + } + else + { + PmStatus = 2; + } + #endregion + + #region RFID鐘舵 + var rfidEquip = baseBusiness.GetRfidByKey("secondFloorOut"); + if(rfidEquip != null) + { + Out2FRfidStatus = 1; + } + else + { + Out2FRfidStatus = 2; + + + + } + #endregion + + } + catch (Exception ex) + { + _logger.LogError($"鐩戝惉璁惧鐘舵佸紓甯:{ex.Message}"); + } + + } /// /// 绐椾綋鎺у埗 diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json index 51816c0..a03f043 100644 --- a/SlnMesnac.WPF/appsettings.json +++ b/SlnMesnac.WPF/appsettings.json @@ -39,7 +39,7 @@ "configId": 1, "plcType": "SiemensPlc", "plcIp": "192.168.2.220", - // "plcIp": "127.0.0.1", + // "plcIp": "127.0.0.1", "plcPort": 102, "plcKey": "plc", "isFlage": true