From 65161955ec603b517be52a1d7dfa622db8403feb Mon Sep 17 00:00:00 2001 From: wenjy Date: Mon, 29 Jan 2024 15:25:03 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E5=BC=80=E4=BB=93=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E4=B8=8B=E5=8F=91=E4=B9=8B=E5=89=8D=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E7=8E=B0=E5=9C=BA=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E6=9C=AA?= =?UTF-8?q?=E5=85=B3=E9=94=81=E5=88=B0=E4=BD=8D=E7=9A=84=E4=BB=93=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Config/AppConfig.cs | 10 +++++ SlnMesnac/Controllers/IngCheckController.cs | 46 ++++++++++++++++++++- SlnMesnac/appsettings.Development.json | 2 + SlnMesnac/appsettings.json | 2 + 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/SlnMesnac.Config/AppConfig.cs b/SlnMesnac.Config/AppConfig.cs index 47e949a..99277bb 100644 --- a/SlnMesnac.Config/AppConfig.cs +++ b/SlnMesnac.Config/AppConfig.cs @@ -19,11 +19,21 @@ namespace SlnMesnac.Config /// public string mcsOpenAddr { get; set; } + /// + /// MCS料仓状态起始地址 + /// + public string mcsBinStatusAddr { get; set; } + /// /// CWSS 开仓地址 /// public string cwssOpenAddr { get; set; } + /// + /// CWSS料仓状态起始地址 + /// + public string cwssBinStatusAddr { get; set; } + /// /// Sql连接配置 /// diff --git a/SlnMesnac/Controllers/IngCheckController.cs b/SlnMesnac/Controllers/IngCheckController.cs index d350189..701a877 100644 --- a/SlnMesnac/Controllers/IngCheckController.cs +++ b/SlnMesnac/Controllers/IngCheckController.cs @@ -1,3 +1,4 @@ +using System.Text; using System.Text.Json; using Microsoft.AspNetCore.Mvc; using SlnMesnac.Config; @@ -135,7 +136,8 @@ public class IngCheckController if (ingredientInfo.IsOpen == 1) { - var openFlag = _plcPool.GetPlcByKey("mcs").writeValueByAddress(mcsInfo.BinNo,_appConfig.mcsOpenAddr); + + var openFlag = SendMcsOpenInstruct(mcsInfo.BinNo); if (openFlag) { _logger.LogInformation($"上辅机开仓指令下发成功"); @@ -214,4 +216,46 @@ public class IngCheckController } return result; } + + /// + /// 下发MCS开仓指令 + /// + /// + /// + /// + private bool SendMcsOpenInstruct(int binNo) + { + bool result = false; + var plcInfo = _plcPool.GetPlcByKey("mcs"); + string[] binStatusArray = _appConfig.mcsBinStatusAddr.Split(","); + List binStatusResult = new List(); + foreach (var item in binStatusArray) + { + bool res = plcInfo.readBoolByAddress(item); + if (res) + { + binStatusResult.Add(1); + } + else + { + binStatusResult.Add(0); + } + } + + var allOtherNumbersList = binStatusResult.Where((num, index) => index != binNo - 1).ToList(); + bool allOtherNumbersAreZero = allOtherNumbersList.Contains(0); + if (allOtherNumbersAreZero) + { + throw new ArgumentException($"开仓指令下发异常,存在门锁未关到位的料仓,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + } + + result = plcInfo.writeValueByAddress(binNo, _appConfig.mcsOpenAddr); + + if (!result) + { + throw new ArgumentException($"开仓指令下发失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + } + + return result; + } } \ No newline at end of file diff --git a/SlnMesnac/appsettings.Development.json b/SlnMesnac/appsettings.Development.json index 839e60d..36a9fc4 100644 --- a/SlnMesnac/appsettings.Development.json +++ b/SlnMesnac/appsettings.Development.json @@ -10,7 +10,9 @@ "AppConfig": { "logPath": "E:/桌面/杜肯密炼MES项目/程序设计/Durk.SlnMesnac/SlnMesnac/bin/Debug/net6.0", "mcsOpenAddr": "D100", + "mcsBinStatusAddr": "M10811,M10813,M10815,M10817,M10819,M10821,M10823,M10825", "cwssOpenAddr": "DB122", + "cwssBinStatusAddr": "M10810", "SqlConfig": [ { "configId": "mcs", diff --git a/SlnMesnac/appsettings.json b/SlnMesnac/appsettings.json index a3992a8..35eaf84 100644 --- a/SlnMesnac/appsettings.json +++ b/SlnMesnac/appsettings.json @@ -10,7 +10,9 @@ "AppConfig": { "logPath": "E:/桌面/杜肯密炼MES项目/程序设计/Durk.SlnMesnac/SlnMesnac/bin/Debug/net6.0", "mcsOpenAddr": "D75367", + "mcsBinStatusAddr": "M10811,M10813,M10815,M10817,M10819,M10821,M10823,M10825", "cwssOpenAddr": "DB122", + "cwssBinStatusAddr": "M10810", "SqlConfig": [ { "configId": "mcs",