diff --git a/SlnMesnac.Business/ProdMgmtBusiness.cs b/SlnMesnac.Business/ProdMgmtBusiness.cs index 457c99d..2b0483b 100644 --- a/SlnMesnac.Business/ProdMgmtBusiness.cs +++ b/SlnMesnac.Business/ProdMgmtBusiness.cs @@ -54,7 +54,7 @@ namespace SlnMesnac.Business /// /// 设备生产管理业务类 -3F /// - public class ProdMgmtBusiness: BaseBusiness + public class ProdMgmtBusiness : BaseBusiness { public readonly IMesProductPlanService _mesProductPlanService; @@ -64,24 +64,29 @@ namespace SlnMesnac.Business public readonly IWmsOutStockService _wmsOutStockService; + private readonly ConfigInfoBusiness _configInfoBusiness; + + private List _palletTasks; private ISqlSugarClient sqlSugarClient; private DebugConfig debugConfig = DebugConfig.Instance; - public ProdMgmtBusiness(ISqlSugarClient _sqlSugarClient,IWmsOutStockService wmsOutStockService,ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IBasePalletInfoService basePalletInfoService, IBaseRealTaskService baseRealTaskService, List palletTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) + public ProdMgmtBusiness(ISqlSugarClient _sqlSugarClient, IWmsOutStockService wmsOutStockService, ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IBasePalletInfoService basePalletInfoService, IBaseRealTaskService baseRealTaskService, List palletTasks, IServiceProvider serviceProvider, ConfigInfoBusiness configInfoBusiness) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) { - sqlSugarClient = _sqlSugarClient; - _wmsOutStockService = wmsOutStockService; + + sqlSugarClient = _sqlSugarClient; + _wmsOutStockService = wmsOutStockService; _mesProductPlanService = mesProductPlanService; _basePalletInfoService = basePalletInfoService; _baseRealTaskService = baseRealTaskService; _palletTasks = palletTasks; - // testTran(); + _configInfoBusiness =configInfoBusiness; + // testTran(); } public async void testTran() { - + //TcpClient tcpClient = new TcpClient(); //var waitClient = tcpClient.CreateWaitingClient(new WaitingOptions() @@ -94,12 +99,12 @@ namespace SlnMesnac.Business //tcpClient.Setup(new TouchSocketConfig().SetRemoteIPHost($"192.168.2.51:3000")); //tcpClient.Connect(); // byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, timeout); - string aaa =await ReadEpcStrByRfidKeyAsync("test"); - // ReadEpcStrByRfidKey("test", out string epcStr); - Console.WriteLine(aaa); - //RefreshMessage($"投料校验RFID标签读取成功,标签信息:{epcStr}"); - - + string aaa = await ReadEpcStrByRfidKeyAsync("test"); + // ReadEpcStrByRfidKey("test", out string epcStr); + Console.WriteLine(aaa); + //RefreshMessage($"投料校验RFID标签读取成功,标签信息:{epcStr}"); + + } #region 委托事件 @@ -126,11 +131,11 @@ namespace SlnMesnac.Business public void InitProdPlan() { - + RefreshMesProdList(); Task.Run(() => { ProdPlanExecHandle(); }); Task.Run(() => { MaterialPutInCheck(); }); - + } /// @@ -140,7 +145,7 @@ namespace SlnMesnac.Business { try { - // var aaa = _mesProductPlanService.GetMesProductPlans(); + // var aaa = _mesProductPlanService.GetMesProductPlans(); var info = _mesProductPlanService.GetPlanDtos(); RefreshProdPlanListEvent?.Invoke(info); } @@ -192,27 +197,27 @@ namespace SlnMesnac.Business { RefreshMessage("等待设备叫料信号触发......"); Thread.Sleep(5000); - - - continue; + + + continue; } RefreshMessage("设备要料信号触发成功"); RefreshProdPlanExecEvent?.Invoke(prodPlan); - - // string palletCode = GetPalletInfoByTask(); - RefreshMessage($"执行计划:{prodPlan.PlanCode};计划数量:{Math.Round(prodPlan.PlanAmount,2)};完成数量:{Math.Round(prodPlan.CompleteAmount,2)};发起叫料申请"); + // string palletCode = GetPalletInfoByTask(); + + RefreshMessage($"执行计划:{prodPlan.PlanCode};计划数量:{Math.Round(prodPlan.PlanAmount, 2)};完成数量:{Math.Round(prodPlan.CompleteAmount, 2)};发起叫料申请"); //查询下发agv的主键 - WmsRawOutstock wmsRaw = _wmsOutStockService.GetProdPlanByPlanCode(prodPlan.PlanCode); + WmsRawOutstock wmsRaw = _wmsOutStockService.GetProdPlanByPlanCode(prodPlan.PlanCode); //进行叫料 if (ApplyDeliveryHandle(wmsRaw.rawOutstockId.ToString())) { - + RefreshMessage("根据计划自动申请叫料成功"); #region 本地创建一个叫料任务 BaseRealTask realTask = new BaseRealTask(); @@ -231,7 +236,7 @@ namespace SlnMesnac.Business { RefreshMessage("根据计划自动申请叫料失败"); } - + } catch (Exception e) { @@ -247,7 +252,7 @@ namespace SlnMesnac.Business /// public void MaterialPutInCheck() { - + bool result = false; var plc = base.GetPlcByKey("plc"); while (true) @@ -258,16 +263,16 @@ namespace SlnMesnac.Business BaseRealTask localPlan = null; try { - + localPlan = _baseRealTaskService.GetExeTask(); - - if (localPlan== null) + + if (localPlan == null) { RefreshMessage("本地未获取到叫料任务......"); Thread.Sleep(3000); continue; } - + if (plc == null) { @@ -283,14 +288,14 @@ namespace SlnMesnac.Business continue; } - // TODO 时间校验,修改为计算设备运行20分钟 + // TODO 投料时间校验 bool timeCheck = JudgeProductTime(); if (!timeCheck) { - RefreshMessage($"收到物料到位信号,但是距离上次投料不满20min,禁止投料"); Thread.Sleep(1000 * 15); continue; } + RefreshMessage($"投料时间校验通过"); // 调用调度接口,判断AGV小车是否已经离开到位,否则不允许投料 bool positionCheck = JudgeAgvPosition(); @@ -308,7 +313,7 @@ namespace SlnMesnac.Business if (productPlanDto == null || prodPlan == null) { RefreshMessage($"收到物料到位信号,未获取到正在执行的生产计划,请开始执行计划"); - + Thread.Sleep(5000); continue; } @@ -320,7 +325,7 @@ namespace SlnMesnac.Business //ReadEpcStrByRfidKey("test", out string epcStr); //RefreshMessage($"投料校验RFID标签读取成功,标签信息:{epcStr}"); - + ////获取物料托盘上的物料信息 //BasePalletInfo palletInfo = _basePalletInfoService.GetPalletInfoByPalletCode(epcStr); //if (palletInfo == null) @@ -345,8 +350,6 @@ namespace SlnMesnac.Business //} #endregion - - } catch (Exception e) { @@ -359,16 +362,21 @@ namespace SlnMesnac.Business if (prodPlan != null) { // 下发翻转信号 - plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备投料"),true); + plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备投料"), true); Thread.Sleep(300); plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备投料"), false); - - debugConfig.LastTime = DateTime.Now.ToString(); + + #region 清空投料系统运行时间 + BaseConfigInfo configInfo = _configInfoBusiness.GetConfigInfos().Where(x => x.ConfigKey == "拆包机系统运行时长").FirstOrDefault(); + configInfo.ConfigValue = "0"; + _configInfoBusiness.UpdateConfigInfo(configInfo); + #endregion + //在小包2楼绑定托盘时完成计划 - // PutInResutlHandle(prodPlan, result); + // PutInResutlHandle(prodPlan, result); // 完成本地计划 - if(localPlan!= null) + if (localPlan != null) { localPlan.Status = 2; localPlan.UpdateTime = DateTime.Now; @@ -385,7 +393,7 @@ namespace SlnMesnac.Business /// /// /// - private void PutInResutlHandle(MesProductPlan prodPlan,bool isRes) + private void PutInResutlHandle(MesProductPlan prodPlan, bool isRes) { try { @@ -406,7 +414,8 @@ namespace SlnMesnac.Business { RefreshMessage("投料校验失败,人工确认不许投料"); } - }catch(Exception e) + } + catch (Exception e) { _logger.LogInformation($"投料结果处理异常:{e.Message}"); } @@ -437,11 +446,11 @@ namespace SlnMesnac.Business try { - - var content = new - { - rawOutstockId = taskId, - }; + + var content = new + { + rawOutstockId = taskId, + }; string message = JsonConvert.SerializeObject(content); //询问小车是否离开接口 0已经离开 @@ -454,7 +463,7 @@ namespace SlnMesnac.Business RefreshMessage("Agv叫料成功"); result = true; } - + } catch (Exception ex) { @@ -480,7 +489,7 @@ namespace SlnMesnac.Business var info = _mesProductPlanService.GetProdPlanByPlanCode(planInfo.PlanCode); - if(info == null) + if (info == null) { throw new ArgumentException("更新生产计划异常:根据计划编号获取计划信息为空"); } @@ -508,35 +517,24 @@ namespace SlnMesnac.Business { try { - - int IntervalMin = int.Parse(GetPlcAddressByConfigKey("投料时间间隔")); // 单位分钟 - if (debugConfig.LastTime != "") - { - DateTime lastTime = DateTime.Parse(debugConfig.LastTime); - - TimeSpan timeDifference = DateTime.Now - lastTime; - - if (timeDifference.TotalMinutes > IntervalMin) - { - return true; - } - else - { - return false; - } + int IntervalMin = int.Parse(GetPlcAddressByConfigKey("投料时间间隔")); // 单位分钟 + int systemRunTime = int.Parse(GetPlcAddressByConfigKey("拆包机系统运行时长")); // 单位分钟 + if (systemRunTime > IntervalMin) + { + return true; } else { - return true; + RefreshMessage($"收到物料到位请求投料信号,但是距离上次投料不满20min,禁止投料"); + return false; } } catch (Exception ex) { _logger.LogError($"距离上次投料时间合格判断异常JudgeProductTime:{ex.Message}"); return false; - } } diff --git a/SlnMesnac.Business/base/BaseBusiness.cs b/SlnMesnac.Business/base/BaseBusiness.cs index 0c1bd0f..55919cb 100644 --- a/SlnMesnac.Business/base/BaseBusiness.cs +++ b/SlnMesnac.Business/base/BaseBusiness.cs @@ -284,5 +284,8 @@ namespace SlnMesnac.Business.@base throw new InvalidOperationException($"根据Key获取PLC地址异常{configKey}:{ex.Message}"); } } + + + } } diff --git a/SlnMesnac.WPF/Page/DevMonitorPage.xaml b/SlnMesnac.WPF/Page/DevMonitorPage.xaml index 2a5795c..79c055f 100644 --- a/SlnMesnac.WPF/Page/DevMonitorPage.xaml +++ b/SlnMesnac.WPF/Page/DevMonitorPage.xaml @@ -15,7 +15,7 @@ - + diff --git a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs index b3f386d..8418aa0 100644 --- a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs +++ b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Timers; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -35,14 +36,14 @@ namespace SlnMesnac.WPF.Page PlcAbsractFactory plc = null; int MachineSleep = 1000; private readonly ILogger _logger; - + System.Timers.Timer systemRunTimer = new System.Timers.Timer(1000 * 60); public DevMonitorPage() { _logger = App.ServiceProvider.GetService>(); _configInfoBusiness = App.ServiceProvider.GetService(); - + baseBusiness = App.ServiceProvider.GetService(); MachineSleep = Convert.ToInt32(baseBusiness.GetPlcAddressByConfigKey("设备启动间隔")); plc = baseBusiness.GetPlcByKey("plc"); @@ -56,6 +57,15 @@ namespace SlnMesnac.WPF.Page private void Init() { + + + systemRunTimer.Elapsed += new System.Timers.ElapsedEventHandler(CalculateSystemRunTime); + systemRunTimer.AutoReset = true; + systemRunTimer.Enabled = true; + systemRunTimer.Start(); + + + List configInfos = _configInfoBusiness.GetConfigInfos(); UnpackSet1Txt.Text = configInfos.Where(x => x.ConfigKey == "拆包机翻转机频率设定值").FirstOrDefault().ConfigValue; @@ -66,10 +76,37 @@ namespace SlnMesnac.WPF.Page Speed1Txt.Text = configInfos.Where(x => x.ConfigKey == "螺旋1速度值").FirstOrDefault().ConfigValue; Speed2Txt.Text = configInfos.Where(x => x.ConfigKey == "螺旋2速度值").FirstOrDefault().ConfigValue; - HotSpiralSpeedTxt.Text = configInfos.Where(x => x.ConfigKey == "烘干机螺旋频率设定值").FirstOrDefault().ConfigValue; + HotSpiralSpeedTxt.Text = configInfos.Where(x => x.ConfigKey == "烘干机螺旋频率设定值").FirstOrDefault().ConfigValue; //HotTempTxt.Text = configInfos.Where(x => x.ConfigKey == "烘干机温度设定值").FirstOrDefault().ConfigValue; } + + /// + /// 计算系统投料后运行时长 + /// + /// + /// + private void CalculateSystemRunTime(object? sender, ElapsedEventArgs e) + { + try + { + if (plc != null) + { + bool unPackStatus1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机系统运行状态")); + if (unPackStatus1) + { + + BaseConfigInfo configInfo = _configInfoBusiness.GetConfigInfos().Where(x => x.ConfigKey == "拆包机系统运行时长").FirstOrDefault(); + configInfo.ConfigValue += 1; + _configInfoBusiness.UpdateConfigInfo(configInfo); + } + } + } + catch (Exception ex) + { + _logger.LogError($"计算系统运行时长异常:{ex.Message}"); + } + } /// /// 设备参数监听 /// @@ -95,11 +132,11 @@ namespace SlnMesnac.WPF.Page Thread.Sleep(1000 * 30); } } - catch(Exception ex) + catch (Exception ex) { _logger.LogError($"设备参数监听StartMachineLisening()异常:{ex.Message}"); } - + } }); } @@ -199,7 +236,7 @@ namespace SlnMesnac.WPF.Page _logger.LogError($"一键启动:{ex.Message}"); } } - + } @@ -727,7 +764,7 @@ namespace SlnMesnac.WPF.Page MessageBox.Show($"烘干机螺旋启动失败:前提条件螺旋1未成功启动,请检查后重新启动"); return false; } - if (speed1 < value1 *100 * 0.8) + if (speed1 < value1 * 100 * 0.8) { // plc.writeBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2启动"), false); MessageBox.Show($"烘干机螺旋启动失败:前提条件螺旋1速度{speed1}未达到设定值{value1}的下限阈值80%,请检查后重新启动"); @@ -791,7 +828,7 @@ namespace SlnMesnac.WPF.Page } int value = int.Parse(baseBusiness.GetPlcAddressByConfigKey("烘干机温度设定值")); SendPulseSignal("烘干机燃烧启动"); - // plc.writeFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机温度设定"), value); + // plc.writeFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机温度设定"), value); Thread.Sleep(MachineSleep); return true; } @@ -831,10 +868,10 @@ namespace SlnMesnac.WPF.Page plc.writeFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机螺旋1频率设定"), int.Parse(baseBusiness.GetPlcAddressByConfigKey("拆包机螺旋1频率设定值"))); plc.writeFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机螺旋2频率设定"), int.Parse(baseBusiness.GetPlcAddressByConfigKey("拆包机螺旋2频率设定值"))); plc.writeFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机废袋机频率设定"), int.Parse(baseBusiness.GetPlcAddressByConfigKey("拆包机废袋机频率设定值"))); - + Thread.Sleep(MachineSleep); - // return plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机运行状态系统")); + // return plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机运行状态系统")); return true; } @@ -952,8 +989,8 @@ namespace SlnMesnac.WPF.Page bool signal4 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1变频器状态")); bool signal5 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2变频器状态")); - double speed1 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度反馈"))/100; - double speed2 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度反馈"))/100; + double speed1 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度反馈")) / 100; + double speed2 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度反馈")) / 100; // 螺旋速度预设值 int speed1Set = int.Parse(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度值")); @@ -995,7 +1032,7 @@ namespace SlnMesnac.WPF.Page try { int signal1_1 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机螺旋状态")); - int signal2_1= plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机风机状态")); + int signal2_1 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机风机状态")); int signal3_1 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机燃烧机状态")); @@ -1010,14 +1047,14 @@ namespace SlnMesnac.WPF.Page int signal9 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机加热温度")); int signal10 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机出气温度")); int signal11 = plc.readInt16ByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机输出百分比")); - + bool signal7_1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机堵料报警")); int signal7_2 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机报警")); await App.Current.Dispatcher.BeginInvoke((Action)(() => { - HotSignal1_1.Fill = signal1_1==1 ? Brushes.Green : Brushes.Red; + HotSignal1_1.Fill = signal1_1 == 1 ? Brushes.Green : Brushes.Red; HotSignal1_1_Value.Text = ChangeHotStatus(signal1_1); HotSignal2_1.Fill = signal2_1 == 1 ? Brushes.Green : Brushes.Red; HotSignal2_1_Value.Text = ChangeHotStatus(signal2_1); @@ -1031,7 +1068,7 @@ namespace SlnMesnac.WPF.Page HotSignal4_1.Fill = signal4_1 ? Brushes.Green : Brushes.Red; HotSignal4_2.Fill = signal14_2 ? Brushes.Red : Brushes.Green; - + HotSignal5_1_Value.Text = ((double)signal8 / 10).ToString(); HotSignal5_2_Value.Text = ((double)signal9 / 10).ToString(); HotSignal6_1_Value.Text = ((double)signal10 / 10).ToString(); @@ -1040,7 +1077,7 @@ namespace SlnMesnac.WPF.Page HotSignal7_1.Fill = signal7_1 ? Brushes.Red : Brushes.Green; HotSignal7_2.Fill = signal7_2 == 0 ? Brushes.Green : Brushes.Red; HotSignal7_2_Value.Text = ChangeHotWarn(signal7_2); - + })); } @@ -1055,11 +1092,11 @@ namespace SlnMesnac.WPF.Page { switch (status) { - case 0: return "未知"; - case 1: return "运行"; - case 2: return "停止"; - case 3: return "故障"; - default: return "未知"; + case 0: return "未知"; + case 1: return "运行"; + case 2: return "停止"; + case 3: return "故障"; + default: return "未知"; } } private string ChangeHotWarn(int status) @@ -1127,8 +1164,8 @@ namespace SlnMesnac.WPF.Page BaseConfigInfo configInfo1 = configInfos.Where(x => x.ConfigKey == "螺旋1速度值").FirstOrDefault(); BaseConfigInfo configInfo2 = configInfos.Where(x => x.ConfigKey == "螺旋2速度值").FirstOrDefault(); - plc.writeFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度设置"), speed1 ); - plc.writeFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度设置"), speed2 ); + plc.writeFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1速度设置"), speed1); + plc.writeFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2速度设置"), speed2); configInfo1.ConfigValue = Speed1Txt.Text; configInfo2.ConfigValue = Speed2Txt.Text; @@ -1141,7 +1178,8 @@ namespace SlnMesnac.WPF.Page MessageBox.Show("请输入0到50之间的正整数!"); } - }catch(Exception ex) + } + catch (Exception ex) { _logger.LogError(ex.Message); } @@ -1158,9 +1196,9 @@ namespace SlnMesnac.WPF.Page try { bool isValidSpeed1 = int.TryParse(HotSpiralSpeedTxt.Text, out int speed1); - + // 校验输入的整数是否在0到50之间且大于0 - if (isValidSpeed1&& speed1 > 0 && speed1 <= 50) + if (isValidSpeed1 && speed1 > 0 && speed1 <= 50) { var result = MessageBox.Show("是否确认更改?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Information); if (result == MessageBoxResult.Yes) @@ -1171,9 +1209,9 @@ namespace SlnMesnac.WPF.Page plc.writeFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机螺旋频率设定"), speed1); configInfo.ConfigValue = HotSpiralSpeedTxt.Text; - + _configInfoBusiness.UpdateConfigInfo(configInfo); - + } } else @@ -1198,14 +1236,14 @@ namespace SlnMesnac.WPF.Page bool isValidSpeed4 = int.TryParse(UnpackSet4Txt.Text, out int speed4) && speed4 >= 0 && speed4 <= 50; bool isValidSpeed5 = int.TryParse(UnpackSet5Txt.Text, out int speed5) && speed5 >= 0 && speed5 <= 50; - + if (isValidSpeed1 && isValidSpeed2 && isValidSpeed3 && isValidSpeed4 && isValidSpeed5) { - + var result = MessageBox.Show("是否确认更改?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Information); if (result == MessageBoxResult.Yes) { - + //频率设定 plc.writeFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机翻转机频率设定"), speed1); @@ -1246,7 +1284,7 @@ namespace SlnMesnac.WPF.Page } - + /// /// 烘干机温度设定