|
|
|
@ -12,6 +12,7 @@ using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Security.Cryptography.Xml;
|
|
|
|
|
using System.ServiceModel.Channels;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using TouchSocket.Core;
|
|
|
|
@ -50,6 +51,8 @@ namespace SlnMesnac.Business
|
|
|
|
|
|
|
|
|
|
public delegate void RefreshMessage(string message, bool isWarning = false);
|
|
|
|
|
public static event RefreshMessage? RefreshMessageEvent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -124,14 +127,14 @@ namespace SlnMesnac.Business
|
|
|
|
|
hikFlag = await JudgeIsSuccessAsync();
|
|
|
|
|
if (hikFlag)
|
|
|
|
|
{
|
|
|
|
|
//校验成功下发放行
|
|
|
|
|
Pass();
|
|
|
|
|
//校验成功放行
|
|
|
|
|
|
|
|
|
|
RefreshMessageEvent?.Invoke("Logo识别成功,下发放行");
|
|
|
|
|
logger.LogInformation($"箱体码:{materialCodeStr},Logo识别成功,下发放行");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//校验成功下发放行
|
|
|
|
|
//校验失败禁止放行
|
|
|
|
|
WarningAndStop($"Logo识别失败,禁止放行");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -139,8 +142,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
{
|
|
|
|
|
// 不需要校验
|
|
|
|
|
hikFlag = true;
|
|
|
|
|
|
|
|
|
|
Pass();
|
|
|
|
|
|
|
|
|
|
RefreshMessageEvent?.Invoke("Logo无需识别,下发放行");
|
|
|
|
|
logger.LogInformation($"箱体码:{materialCodeStr},Logo无需识别,下发放行");
|
|
|
|
|
}
|
|
|
|
@ -267,28 +269,93 @@ namespace SlnMesnac.Business
|
|
|
|
|
//M100停止点位
|
|
|
|
|
public void Pass()
|
|
|
|
|
{
|
|
|
|
|
if(plc!=null && plc.IsConnected)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (plc != null && plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
plc.writeInt16ByAddress("M100", 8);
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
// 设置计时器
|
|
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
|
|
stopwatch.Start();
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (plc.readInt16ByAddress("M100") == 0)
|
|
|
|
|
{
|
|
|
|
|
logger.LogInformation("PLC复位成功,启动线体");
|
|
|
|
|
RefreshMessageEvent?.Invoke("PLC复位成功,启动线体", true);
|
|
|
|
|
}
|
|
|
|
|
// 检查是否超过两秒
|
|
|
|
|
if (stopwatch.ElapsedMilliseconds > 3000)
|
|
|
|
|
{
|
|
|
|
|
logger.LogError("PLC复位超时");
|
|
|
|
|
RefreshMessageEvent?.Invoke("PLC复位超时", true);
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.LogError("PLC未连接,请检查连接");
|
|
|
|
|
RefreshMessageEvent?.Invoke("PLC未连接,请检查连接", true);
|
|
|
|
|
}
|
|
|
|
|
// 声光电报警复位
|
|
|
|
|
gunHelper.SendData("OK");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
plc.writeInt16ByAddress("M100",0);
|
|
|
|
|
logger.LogError($"下发PLC复位方法Pass()异常:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
// 声光电报警复位
|
|
|
|
|
gunHelper.SendData("OK");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
|
|
|
|
if (plc != null && plc.IsConnected)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (plc != null && plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
plc.writeInt16ByAddress("M100", 9);
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
// 设置计时器
|
|
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
|
|
stopwatch.Start();
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (plc.readInt16ByAddress("M100") == 1)
|
|
|
|
|
{
|
|
|
|
|
logger.LogInformation("PLC复位成功,启动线体");
|
|
|
|
|
RefreshMessageEvent?.Invoke("PLC复位成功,启动线体", true);
|
|
|
|
|
}
|
|
|
|
|
// 检查是否超过两秒
|
|
|
|
|
if (stopwatch.ElapsedMilliseconds > 3000)
|
|
|
|
|
{
|
|
|
|
|
logger.LogError("PLC复位超时");
|
|
|
|
|
RefreshMessageEvent?.Invoke("PLC复位超时", true);
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// 声光电报警
|
|
|
|
|
gunHelper.SendData("NG");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
plc.writeInt16ByAddress("M100", 1);
|
|
|
|
|
logger.LogError($"下发PLC报警方法Stop()异常:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
// 声光电报警复位
|
|
|
|
|
gunHelper.SendData("NG");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 记录日志,刷新界面及下发PLC报警
|
|
|
|
|
public void WarningAndStop(string message)
|
|
|
|
|
#region 记录日志,刷新界面及下发PLC报警
|
|
|
|
|
public void WarningAndStop(string message)
|
|
|
|
|
{
|
|
|
|
|
logger.LogError(message);
|
|
|
|
|
RefreshMessageEvent?.Invoke(message, true);
|
|
|
|
|