diff --git a/DOAN.Admin.WebApi/Controllers/PBL/MESInteractionController.cs b/DOAN.Admin.WebApi/Controllers/PBL/MESInteractionController.cs
index 0e66d5c..948bfba 100644
--- a/DOAN.Admin.WebApi/Controllers/PBL/MESInteractionController.cs
+++ b/DOAN.Admin.WebApi/Controllers/PBL/MESInteractionController.cs
@@ -3,6 +3,7 @@ using DOAN.Model.PBL.Dto;
using DOAN.Model.PBL;
using DOAN.Service.PBL.IService;
using DOAN.Admin.WebApi.Filters;
+using DOAN.ServiceCore.Middleware;
//创建时间:2024-09-23
namespace DOAN.Admin.WebApi.Controllers.PBL
@@ -23,6 +24,7 @@ namespace DOAN.Admin.WebApi.Controllers.PBL
//TODO 接受工单 亮灯
[HttpPost("mes_light_up")]
+ [DoanPlcActionFilter]
public IActionResult MESLightUp([FromBody] LightUpDto light)
{
var response= mesInteraction.MESLightUp(light);
@@ -32,21 +34,16 @@ namespace DOAN.Admin.WebApi.Controllers.PBL
//TODO 扫码灭灯
[HttpGet("mes_light_down")]
+ [DoanPlcActionFilter]
public IActionResult MESLightDown(string scan_code)
{
var response = mesInteraction.MESLightDown(scan_code);
return SUCCESS(response);
}
- [HttpGet("test_plc")]
- public IActionResult TestPLC(int num)
- {
- var response = mesInteraction.TestPLC(num);
- return SUCCESS(response);
-
- }
+
}
diff --git a/DOAN.Model/PBL/Light_Log.cs b/DOAN.Model/PBL/Light_Log.cs
index c0d4572..afafda5 100644
--- a/DOAN.Model/PBL/Light_Log.cs
+++ b/DOAN.Model/PBL/Light_Log.cs
@@ -10,7 +10,7 @@ namespace DOAN.Model.PBL
/// 库存日志
///
[SugarTable("light_log")]
- public class Light_Log
+ public class Light_Log
{
///
/// 雪花
@@ -29,16 +29,19 @@ namespace DOAN.Model.PBL
/// 货架号
///
[SugarColumn(ColumnName = "shelf_code")]
- public string ShelfCode { get; set; }
+ public string ShelfCode { get; set; }
///
/// 操作者
///
[SugarColumn(ColumnName = "operationer")]
- public string Operationer { get; set; }
-
-
+ public string Operationer { get; set; }
+ ///
+ /// 是否plc成功操作
+ ///
+ [SugarColumn(ColumnName = "is_success")]
+ public bool IsSuccess { get; set; }
///
/// 创建时间
///
diff --git a/DOAN.Model/PBL/Storagelocation.cs b/DOAN.Model/PBL/Storagelocation.cs
index 183a018..130c243 100644
--- a/DOAN.Model/PBL/Storagelocation.cs
+++ b/DOAN.Model/PBL/Storagelocation.cs
@@ -47,6 +47,14 @@ namespace DOAN.Model.PBL
[SugarColumn(ColumnName = "is_light")]
public int? IsLight { get; set; }
+
+
+ ///
+ /// plc address
+ ///
+ [SugarColumn(ColumnName = "plc_address")]
+ public string PlcAddress { get; set; }
+
///
/// 创建人
///
diff --git a/DOAN.Service/PBL/IService/IMESInteractionServcie.cs b/DOAN.Service/PBL/IService/IMESInteractionServcie.cs
index 01c056a..7258fb6 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 15ba40f..8b0fdd3 100644
--- a/DOAN.Service/PBL/MESInteractionServcie.cs
+++ b/DOAN.Service/PBL/MESInteractionServcie.cs
@@ -19,14 +19,7 @@ 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)
{
@@ -50,13 +43,17 @@ namespace DOAN.Service.PBL
//TODO PLC 交互
// 对应料架 亮灯字段
- MirrorshellShelf.IsLight = 1;
- MirrorshellBody.IsLight = 1;
- Context.Insertable(MirrorshellShelf).ExecuteCommand();
- Context.Insertable(MirrorshellBody).ExecuteCommand();
// 通知PLC
-
-
+ bool isSucesss = PLCTool.WriteBit(MirrorshellShelf.PlcAddress, true);
+ if (isSucesss)
+ {
+ MirrorshellShelf.IsLight = 1;
+ MirrorshellBody.IsLight = 1;
+ Context.Insertable(MirrorshellShelf).ExecuteCommand();
+ Context.Insertable(MirrorshellBody).ExecuteCommand();
+ }
+
+
//亮灯日志
Light_Log light_Log = new Light_Log();
light_Log.Id = XUEHUA;
@@ -69,6 +66,9 @@ namespace DOAN.Service.PBL
light_Log.Operationer = "PBL";
light_Log.CreatedTime = DateTime.Now;
+ light_Log.IsSuccess = isSucesss;
+
+
Light_Log light_Log2 = new Light_Log();
light_Log2.Id = XUEHUA;
light_Log2.LightOperation = 1;
@@ -80,6 +80,7 @@ namespace DOAN.Service.PBL
light_Log2.Operationer = "PBL";
light_Log2.CreatedTime = DateTime.Now;
+ light_Log2.IsSuccess = isSucesss;
Context.Insertable(light_Log2).ExecuteCommand();
int result = Context.Insertable(light_Log).ExecuteCommand();
return result > 0;
@@ -87,6 +88,11 @@ namespace DOAN.Service.PBL
}
+ ///
+ /// 灭灯
+ ///
+ ///
+ ///
public bool MESLightDown(string scan_code)
{
// 1.记录MES交互记录
@@ -97,15 +103,20 @@ namespace DOAN.Service.PBL
Context.Insertable(item).ExecuteCommand();
//2 找到对应的料架 灭灯
-
-
-
Storagelocation storagelocation = Context.Queryable().Where(it => it.Partnumber == scan_code).First();
//TODO PLC 交互
+ bool isSuccess= PLCTool.WriteBit(storagelocation.PlcAddress, false);
-
- //亮灯日志
+ if (isSuccess)
+ {
+ storagelocation.IsLight = 1;
+ storagelocation.PackageNum =storagelocation.PackageNum - 1;
+ //3 扣减对应的库存
+ Context.Insertable(storagelocation).ExecuteCommand();
+
+ }
+ //灭灯日志
Light_Log light_Log = new Light_Log();
light_Log.Id = XUEHUA;
light_Log.LightOperation = 2;
@@ -113,12 +124,14 @@ namespace DOAN.Service.PBL
{
light_Log.ShelfCode = storagelocation.RackCode;
}
-
+ light_Log.IsSuccess = isSuccess;
light_Log.Operationer = "PBL";
light_Log.CreatedTime = DateTime.Now;
int result = Context.Insertable(light_Log).ExecuteCommand();
- //3 扣减对应的库存
+
+
+
return result > 0;
diff --git a/DOAN.ServiceCore/Filters/DoanPlcActionFilter.cs b/DOAN.ServiceCore/Filters/DoanPlcActionFilter.cs
new file mode 100644
index 0000000..ddf7c38
--- /dev/null
+++ b/DOAN.ServiceCore/Filters/DoanPlcActionFilter.cs
@@ -0,0 +1,39 @@
+using DOAN.Infrastructure.PLC;
+using Microsoft.AspNetCore.Mvc.Filters;
+using System;
+
+namespace DOAN.ServiceCore.Middleware
+{
+ public class DoanPlcActionFilter : ActionFilterAttribute
+ {
+ /////
+ ///// PLC地址
+ /////
+ //private readonly string addr;
+
+ //private readonly bool value;
+
+ //public DoanPlcActionFilter(string addr,string value)
+ //{
+ // addr = addr;
+ // value = value;
+ //}
+ public override void OnActionExecuting(ActionExecutingContext context)
+ {
+ //建立plC 连接
+ PLCTool.ConnectPLC();
+
+
+ base.OnActionExecuting(context);
+ }
+
+ public override void OnActionExecuted(ActionExecutedContext context)
+ {
+ // 关闭pLc连接
+ PLCTool.ConnectClose();
+
+ base.OnActionExecuted(context);
+ }
+ }
+
+}
diff --git a/Infrastructure/PLC/PCLTool.cs b/Infrastructure/PLC/PLCTool.cs
similarity index 72%
rename from Infrastructure/PLC/PCLTool.cs
rename to Infrastructure/PLC/PLCTool.cs
index 47bd0b4..2282ef5 100644
--- a/Infrastructure/PLC/PCLTool.cs
+++ b/Infrastructure/PLC/PLCTool.cs
@@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace DOAN.Infrastructure.PLC
{
- public class PCLTool
+ public class PLCTool
{
@@ -40,22 +40,18 @@ namespace DOAN.Infrastructure.PLC
}
- public static int Write(string addr,int num)
+ ///
+ /// 写入bit
+ ///
+ ///
+ ///
+ ///
+ public static bool WriteBit(string addr,bool value)
{
- OperateResult write = siemensTcpNet.Write(addr, (byte)num);
- if (write.IsSuccess)
- {
-
- Console.WriteLine("Write [v100] success");
- return 1;
- }
- else
- {
- Console.WriteLine("Write [v100] failed: " + write.Message);
- return 0;
- }
-
+ OperateResult write = siemensTcpNet.Write(addr, value);
+ return write.IsSuccess;
+
}
public static void ConnectClose()