diff --git a/DOAN.Admin.WebApi/Controllers/PBL/MESInteractionController.cs b/DOAN.Admin.WebApi/Controllers/PBL/MESInteractionController.cs index 46c517f..0e66d5c 100644 --- a/DOAN.Admin.WebApi/Controllers/PBL/MESInteractionController.cs +++ b/DOAN.Admin.WebApi/Controllers/PBL/MESInteractionController.cs @@ -38,6 +38,14 @@ namespace DOAN.Admin.WebApi.Controllers.PBL return SUCCESS(response); } + [HttpGet("test_plc")] + public IActionResult TestPLC(int num) + { + var response = mesInteraction.TestPLC(num); + + return SUCCESS(response); + + } } diff --git a/DOAN.Service/PBL/IService/IMESInteractionServcie.cs b/DOAN.Service/PBL/IService/IMESInteractionServcie.cs index 3e0e1f4..01c056a 100644 --- a/DOAN.Service/PBL/IService/IMESInteractionServcie.cs +++ b/DOAN.Service/PBL/IService/IMESInteractionServcie.cs @@ -10,7 +10,7 @@ namespace DOAN.Service.PBL.IService { public interface IMESInteractionServcie { - + int TestPLC(int num); bool MESLightUp(LightUpDto light); bool MESLightDown(string scan_code); } diff --git a/DOAN.Service/PBL/MESInteractionServcie.cs b/DOAN.Service/PBL/MESInteractionServcie.cs index 1c1bbdc..15ba40f 100644 --- a/DOAN.Service/PBL/MESInteractionServcie.cs +++ b/DOAN.Service/PBL/MESInteractionServcie.cs @@ -8,6 +8,7 @@ using Mapster; using System.Runtime.InteropServices; using SqlSugar; using System.Security.Cryptography.X509Certificates; +using DOAN.Infrastructure.PLC; namespace DOAN.Service.PBL @@ -18,23 +19,32 @@ namespace DOAN.Service.PBL [AppService(ServiceType = typeof(IMESInteractionServcie), ServiceLifetime = LifeTime.Transient)] public class MESInteractionServcie : BaseService, IMESInteractionServcie { + public int TestPLC(int num) + { + PCLTool.ConnectPLC(); + int result = PCLTool.Write("VB100", num); + PCLTool.ConnectClose(); + return result; + + } + public bool MESLightUp(LightUpDto light) { // 1.记录MES交互记录 MES_Interation_Log item = light.Adapt(); item.Id = XUEHUA; - item.CreatedTime= DateTime.Now; + item.CreatedTime = DateTime.Now; Context.Insertable(item).ExecuteCommand(); // 2.根据总成零件号 ,版本 查询对应零件号,使得对应料架亮灯 //镜壳 料架 Storagelocation MirrorshellShelf = Context.Queryable().Where(it => it.Partnumber == - SqlFunc.Subqueryable().Where(It => It.Productcode == light.AssemblyPartNumber&&It.Version==light.Version).Select(it => it.MirrorshellCode)).First(); + SqlFunc.Subqueryable().Where(It => It.Productcode == light.AssemblyPartNumber && It.Version == light.Version).Select(it => it.MirrorshellCode)).First(); //镜体 料架 Storagelocation MirrorshellBody = Context.Queryable().Where(it => it.Partnumber == - SqlFunc.Subqueryable().Where(It => It.Productcode == light.AssemblyPartNumber&&It.Version == light.Version).Select(it => it.MirrorbodyCode)).First(); + SqlFunc.Subqueryable().Where(It => It.Productcode == light.AssemblyPartNumber && It.Version == light.Version).Select(it => it.MirrorbodyCode)).First(); // 3.对应料架亮灯 @@ -56,7 +66,7 @@ namespace DOAN.Service.PBL light_Log.ShelfCode = MirrorshellShelf.RackCode; } - + light_Log.Operationer = "PBL"; light_Log.CreatedTime = DateTime.Now; Light_Log light_Log2 = new Light_Log(); @@ -67,12 +77,12 @@ namespace DOAN.Service.PBL light_Log2.ShelfCode = MirrorshellShelf.RackCode; } - + light_Log2.Operationer = "PBL"; light_Log2.CreatedTime = DateTime.Now; Context.Insertable(light_Log2).ExecuteCommand(); int result = Context.Insertable(light_Log).ExecuteCommand(); - return result > 0; + return result > 0; } @@ -82,33 +92,34 @@ namespace DOAN.Service.PBL // 1.记录MES交互记录 MES_Interation_Log item = new MES_Interation_Log(); item.Id = XUEHUA; - item.ScanCode=scan_code; + item.ScanCode = scan_code; item.CreatedTime = DateTime.Now; Context.Insertable(item).ExecuteCommand(); //2 找到对应的料架 灭灯 - - - - Storagelocation storagelocation= Context.Queryable().Where(it => it.Partnumber == scan_code).First(); - + + + + Storagelocation storagelocation = Context.Queryable().Where(it => it.Partnumber == scan_code).First(); + //TODO PLC 交互 - - + + //亮灯日志 Light_Log light_Log = new Light_Log(); light_Log.Id = XUEHUA; light_Log.LightOperation = 2; - if (storagelocation != null) { - light_Log.ShelfCode = storagelocation.RackCode ; + if (storagelocation != null) + { + light_Log.ShelfCode = storagelocation.RackCode; } - + light_Log.Operationer = "PBL"; light_Log.CreatedTime = DateTime.Now; - int result= Context.Insertable(light_Log).ExecuteCommand(); - + int result = Context.Insertable(light_Log).ExecuteCommand(); + //3 扣减对应的库存 - + return result > 0; } diff --git a/Infrastructure/PLC/PCLTool.cs b/Infrastructure/PLC/PCLTool.cs index 1017293..a2e50b5 100644 --- a/Infrastructure/PLC/PCLTool.cs +++ b/Infrastructure/PLC/PCLTool.cs @@ -1,4 +1,5 @@ using HslCommunication; +using HslCommunication.Profinet.Inovance; using HslCommunication.Profinet.Siemens; using Infrastructure; using System; @@ -16,9 +17,9 @@ namespace DOAN.Infrastructure.PLC // private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); public static SiemensS7Net siemensTcpNet = null; - public bool ConnectPLC() + public static bool ConnectPLC() { - siemensTcpNet= new SiemensS7Net(SiemensPLCS.S1200, "192.168.0.100") + siemensTcpNet= new SiemensS7Net(SiemensPLCS.S1200, "192.168.2.1") { ConnectTimeOut = 5000 }; @@ -39,8 +40,25 @@ namespace DOAN.Infrastructure.PLC } + public static int Write(string addr,int num) + { + + OperateResult write = siemensTcpNet.Write(addr, num); + if (write.IsSuccess) + { + + Console.WriteLine("Write [v100] success"); + return 1; + } + else + { + Console.WriteLine("Write [v100] failed: " + write.Message); + return 0; + } - public void ConnectClose() + } + + public static void ConnectClose() { siemensTcpNet.ConnectClose();