|
|
@ -12,6 +12,7 @@ using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
using System.Security.Cryptography.Xml;
|
|
|
|
using System.Security.Cryptography.Xml;
|
|
|
|
|
|
|
|
using System.ServiceModel.Channels;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using TouchSocket.Core;
|
|
|
|
using TouchSocket.Core;
|
|
|
@ -50,6 +51,8 @@ namespace SlnMesnac.Business
|
|
|
|
|
|
|
|
|
|
|
|
public delegate void RefreshMessage(string message, bool isWarning = false);
|
|
|
|
public delegate void RefreshMessage(string message, bool isWarning = false);
|
|
|
|
public static event RefreshMessage? RefreshMessageEvent;
|
|
|
|
public static event RefreshMessage? RefreshMessageEvent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -124,14 +127,14 @@ namespace SlnMesnac.Business
|
|
|
|
hikFlag = await JudgeIsSuccessAsync();
|
|
|
|
hikFlag = await JudgeIsSuccessAsync();
|
|
|
|
if (hikFlag)
|
|
|
|
if (hikFlag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//校验成功下发放行
|
|
|
|
//校验成功放行
|
|
|
|
Pass();
|
|
|
|
|
|
|
|
RefreshMessageEvent?.Invoke("Logo识别成功,下发放行");
|
|
|
|
RefreshMessageEvent?.Invoke("Logo识别成功,下发放行");
|
|
|
|
logger.LogInformation($"箱体码:{materialCodeStr},Logo识别成功,下发放行");
|
|
|
|
logger.LogInformation($"箱体码:{materialCodeStr},Logo识别成功,下发放行");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//校验成功下发放行
|
|
|
|
//校验失败禁止放行
|
|
|
|
WarningAndStop($"Logo识别失败,禁止放行");
|
|
|
|
WarningAndStop($"Logo识别失败,禁止放行");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -140,7 +143,6 @@ namespace SlnMesnac.Business
|
|
|
|
// 不需要校验
|
|
|
|
// 不需要校验
|
|
|
|
hikFlag = true;
|
|
|
|
hikFlag = true;
|
|
|
|
|
|
|
|
|
|
|
|
Pass();
|
|
|
|
|
|
|
|
RefreshMessageEvent?.Invoke("Logo无需识别,下发放行");
|
|
|
|
RefreshMessageEvent?.Invoke("Logo无需识别,下发放行");
|
|
|
|
logger.LogInformation($"箱体码:{materialCodeStr},Logo无需识别,下发放行");
|
|
|
|
logger.LogInformation($"箱体码:{materialCodeStr},Logo无需识别,下发放行");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -266,24 +268,89 @@ namespace SlnMesnac.Business
|
|
|
|
#region PLC交互部分
|
|
|
|
#region PLC交互部分
|
|
|
|
//M100停止点位
|
|
|
|
//M100停止点位
|
|
|
|
public void Pass()
|
|
|
|
public void Pass()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (plc != null && plc.IsConnected)
|
|
|
|
if (plc != null && plc.IsConnected)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
plc.writeInt16ByAddress("M100",0);
|
|
|
|
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");
|
|
|
|
gunHelper.SendData("OK");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
logger.LogError($"下发PLC复位方法Pass()异常:{ex.Message}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
public void Stop()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (plc != null && plc.IsConnected)
|
|
|
|
if (plc != null && plc.IsConnected)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
plc.writeInt16ByAddress("M100", 1);
|
|
|
|
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");
|
|
|
|
gunHelper.SendData("NG");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
logger.LogError($"下发PLC报警方法Stop()异常:{ex.Message}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|