PLC 交互

This commit is contained in:
qianhao.xu
2024-11-08 08:42:33 +08:00
parent 74c849149e
commit 47855d3f54
7 changed files with 104 additions and 48 deletions

View File

@@ -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);
}

View File

@@ -19,14 +19,7 @@ namespace DOAN.Service.PBL
[AppService(ServiceType = typeof(IMESInteractionServcie), ServiceLifetime = LifeTime.Transient)]
public class MESInteractionServcie : BaseService<Storagelocation>, 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
}
/// <summary>
/// 灭灯
/// </summary>
/// <param name="scan_code"></param>
/// <returns></returns>
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<Storagelocation>().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;