|
|
using MaterialTraceability.Common;
|
|
|
using MaterialTraceability.Entity.DTO;
|
|
|
using MaterialTraceability.Plc;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace MaterialTraceability.Business
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// PLC业务类
|
|
|
/// </summary>
|
|
|
public class PlcBusiness
|
|
|
{
|
|
|
private static IPlc plcInstance = null;
|
|
|
|
|
|
private static AppConfigDto appConfig = AppConfigDto.Instance;
|
|
|
|
|
|
#region 定义间隔判断时间
|
|
|
private static DateTime lastReadTime_A_Begin;
|
|
|
private static DateTime lastReadTime_A_End;
|
|
|
|
|
|
private static DateTime lastReadTime_B_Begin;
|
|
|
private static DateTime lastReadTime_B_End;
|
|
|
|
|
|
private static DateTime lastReadTime_Force;
|
|
|
|
|
|
private static DateTime lastReadTime_ForceSecond; //模切暂用
|
|
|
|
|
|
private static DateTime AB_lastReadTime_SJForceSinal; //凹版收卷结束信号
|
|
|
|
|
|
private static DateTime AB_lastReadTime_SJEndSinal; //凹版收卷结束信号
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 信号刷新事件
|
|
|
/// </summary>
|
|
|
/// <param name="status"></param>
|
|
|
public delegate void SignalReadRefresh(int status, int position);
|
|
|
public event SignalReadRefresh SignalRefreshEvent;
|
|
|
|
|
|
private static System.Timers.Timer timer = new System.Timers.Timer(appConfig.plcSingalReadTime);
|
|
|
|
|
|
public void EndSignalInit(int status, int position)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(status, position);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 初始化PLC
|
|
|
/// </summary>
|
|
|
/// <param name="PLCType"></param>
|
|
|
/// <returns></returns>
|
|
|
public IPlc InitPlc(string PLCType)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
string str = System.Environment.CurrentDirectory;
|
|
|
str = str + "\\MaterialTraceability.Plc.dll";
|
|
|
Assembly assembly = Assembly.LoadFile(str); // 加载程序集(EXE 或 DLL)
|
|
|
string AssemName = "MaterialTraceability.Plc.Impl." + PLCType;
|
|
|
var obj = assembly.CreateInstance(AssemName, true);
|
|
|
plcInstance = obj as IPlc;
|
|
|
if (plcInstance == null)
|
|
|
{
|
|
|
LogHelper.Info("PLC初始化失败!!!");
|
|
|
return null;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
LogHelper.Info("PLC初始化成功");
|
|
|
#region 读取时间初始化
|
|
|
var initTime = DateTime.Now.AddMinutes(-1);
|
|
|
lastReadTime_A_Begin = initTime;
|
|
|
lastReadTime_A_End = initTime;
|
|
|
lastReadTime_B_Begin = initTime;
|
|
|
lastReadTime_B_End = initTime;
|
|
|
lastReadTime_Force = initTime;
|
|
|
lastReadTime_ForceSecond = initTime;
|
|
|
AB_lastReadTime_SJForceSinal = initTime;
|
|
|
AB_lastReadTime_SJEndSinal = initTime;
|
|
|
#endregion
|
|
|
|
|
|
return plcInstance;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.Error("PLC初始化异常", ex);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public bool Connect()
|
|
|
{
|
|
|
if (!plcInstance.IsConnected)
|
|
|
{
|
|
|
bool connectResult = plcInstance.Connect(appConfig.plcAddress, appConfig.plcPort);
|
|
|
return connectResult;
|
|
|
}
|
|
|
return plcInstance.IsConnected;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取PLC连接状态
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public bool IsConnected()
|
|
|
{
|
|
|
return plcInstance.IsConnected;
|
|
|
}
|
|
|
|
|
|
public bool ReConnect()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (plcInstance.IsConnected)
|
|
|
{
|
|
|
if (plcInstance.DisConnect())
|
|
|
{
|
|
|
LogHelper.PlcLog("PLC断开成功");
|
|
|
}
|
|
|
}
|
|
|
//断开后关闭定时器
|
|
|
if (timer.Enabled)
|
|
|
{
|
|
|
timer.Stop();
|
|
|
timer.Close();
|
|
|
timer.Dispose();
|
|
|
timer = new System.Timers.Timer(appConfig.plcSingalReadTime);
|
|
|
}
|
|
|
LogHelper.PlcLog("定时器关闭,等待2S后进行重连");
|
|
|
Thread.Sleep(1000 * 2);
|
|
|
|
|
|
if (Connect())
|
|
|
{
|
|
|
LogHelper.PlcLog("PLC连接成功,开启定时器");
|
|
|
LoopRead("");
|
|
|
}
|
|
|
}
|
|
|
catch(Exception ex)
|
|
|
{
|
|
|
LogHelper.Error("PLC重连异常",ex);
|
|
|
}
|
|
|
var result = plcInstance.IsConnected;
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 开启线程循环读取PLC地址
|
|
|
/// </summary>
|
|
|
/// <param name="address"></param>
|
|
|
public void LoopRead(string address)
|
|
|
{
|
|
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(readPlc);
|
|
|
timer.AutoReset = true;
|
|
|
timer.Enabled = true;
|
|
|
timer.Start();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 读取PLC信号 object source, System.Timers.ElapsedEventArgs e
|
|
|
/// </summary>
|
|
|
/// <param name="source"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void readPlc(object source, System.Timers.ElapsedEventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//获取工序编号 TB-涂布、LY冷压预分切、MQ-模切、JR-卷绕
|
|
|
string processCode = appConfig.processId;
|
|
|
#region 凹版
|
|
|
//凹版工序
|
|
|
if (processCode.Equals("AB"))
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.AbAddress.心跳, 1);
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.AbAddress.放卷开始) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.AbAddress.放卷开始, 0);
|
|
|
SignalRefreshEvent?.Invoke(6, 0);
|
|
|
}
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.AbAddress.收卷开始) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.AbAddress.收卷开始, 0);
|
|
|
SignalRefreshEvent?.Invoke(7, 1);
|
|
|
}
|
|
|
//放卷 涨紧信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.AbAddress.放卷涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.AbAddress.放卷涨紧, 0);
|
|
|
SignalRefreshEvent?.Invoke(1, 0);
|
|
|
}
|
|
|
|
|
|
//放卷结束信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.AbAddress.放卷结束) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.AbAddress.放卷结束, 0);
|
|
|
SignalRefreshEvent?.Invoke(2, 0);
|
|
|
}
|
|
|
|
|
|
//收卷涨紧信号-1A气胀轴
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.AbAddress.收卷涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.AbAddress.收卷涨紧, 0);
|
|
|
SignalRefreshEvent?.Invoke(3, 1);
|
|
|
}
|
|
|
|
|
|
|
|
|
//收卷结束信号-1A气胀轴
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.AbAddress.收卷结束) == 1)
|
|
|
{
|
|
|
if (isReadFlag(ref AB_lastReadTime_SJEndSinal))
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.AbAddress.收卷结束, 0);
|
|
|
SignalRefreshEvent?.Invoke(4, 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//异常下料-1A
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.AbAddress.放卷异常下料) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.AbAddress.放卷异常下料, 0);
|
|
|
SignalRefreshEvent?.Invoke(5, 0);
|
|
|
|
|
|
}
|
|
|
//异常下料-1B
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.AbAddress.收卷异常下料) == 1)
|
|
|
{
|
|
|
if (isReadFlag(ref AB_lastReadTime_SJForceSinal))
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.AbAddress.收卷异常下料, 0);
|
|
|
SignalRefreshEvent?.Invoke(5, 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
#region 涂布
|
|
|
if (processCode.Equals("TB"))
|
|
|
{
|
|
|
lock (string.Empty)
|
|
|
{
|
|
|
//写入心跳
|
|
|
plcInstance.writeInt32ByAddress("D9828", 1);
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.心跳, 1);
|
|
|
LogHelper.PlcLog("RFID系统写入心跳D9628");
|
|
|
Thread.Sleep(200);
|
|
|
|
|
|
// A放卷涨紧 A轴position设为3
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.A放卷涨紧) == 1)
|
|
|
{
|
|
|
LogHelper.PlcLog("B放卷涨紧");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.涨紧信号清除, 1);
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.A放卷涨紧, 0);
|
|
|
SignalRefreshEvent?.Invoke(1, 3);
|
|
|
}
|
|
|
|
|
|
// B放卷涨紧 B轴position设为4
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.B放卷涨紧) == 1)
|
|
|
{
|
|
|
LogHelper.PlcLog("B放卷涨紧");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.B放卷涨紧, 0);
|
|
|
SignalRefreshEvent?.Invoke(1, 4);
|
|
|
}
|
|
|
|
|
|
// A放卷开始 A轴position设为3
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.放卷开始) == 1)
|
|
|
{
|
|
|
LogHelper.PlcLog("A放卷开始");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.放卷开始, 0);
|
|
|
SignalRefreshEvent?.Invoke(6, 3);
|
|
|
}
|
|
|
|
|
|
// B放卷开始 B轴position设为4
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.放卷开始) == 2)
|
|
|
{
|
|
|
LogHelper.PlcLog("B放卷开始");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.放卷开始, 0);
|
|
|
SignalRefreshEvent?.Invoke(6, 4);
|
|
|
}
|
|
|
|
|
|
// A放卷结束 A轴position设为3
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.A放卷结束) == 1)
|
|
|
{
|
|
|
LogHelper.PlcLog("A放卷结束");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.A放卷结束, 0);
|
|
|
SignalRefreshEvent?.Invoke(2, 3);
|
|
|
}
|
|
|
|
|
|
// B放卷结束 B轴position设为4` ` ````
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.B放卷结束) == 1)
|
|
|
{
|
|
|
LogHelper.PlcLog("B放卷结束");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.B放卷结束, 0);
|
|
|
SignalRefreshEvent?.Invoke(2, 4);
|
|
|
}
|
|
|
|
|
|
//A轴放卷强制下料
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.放卷强制下料) == 1)
|
|
|
{
|
|
|
LogHelper.PlcLog("A轴放卷强制下料");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.放卷强制下料, 0);
|
|
|
SignalRefreshEvent?.Invoke(5, 3);
|
|
|
}
|
|
|
|
|
|
//B轴放卷强制下料
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.放卷强制下料) == 2)
|
|
|
{
|
|
|
LogHelper.PlcLog("B轴放卷强制下料");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.放卷强制下料, 0);
|
|
|
SignalRefreshEvent?.Invoke(5, 4);
|
|
|
}
|
|
|
|
|
|
// A轴收卷涨紧 A轴position设为1
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.A收卷轴涨紧) == 1)
|
|
|
{
|
|
|
LogHelper.PlcLog("A轴收卷涨紧");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.涨紧信号清除, 1);
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.A收卷轴涨紧, 0);
|
|
|
if (isReadFlag(ref lastReadTime_A_Begin))
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(3, 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// B轴收卷涨紧 B轴position设为2
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.B收卷轴涨紧) == 1)
|
|
|
{
|
|
|
LogHelper.PlcLog("B轴收卷涨紧");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.涨紧信号清除, 1);
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.B收卷轴涨紧, 0);
|
|
|
if (isReadFlag(ref lastReadTime_B_Begin))
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(3, 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#region 收卷开始信号 Add By wenjy 2022-11-29
|
|
|
// A轴收卷开始信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.收卷轴开始) == 1)
|
|
|
{
|
|
|
LogHelper.PlcLog("A轴收卷开始信号 D9720==1 -> 0");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.收卷轴开始, 0);
|
|
|
if (isReadFlag(ref lastReadTime_A_End))
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(7, 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// B轴收卷开始信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.收卷轴开始) == 2)
|
|
|
{
|
|
|
LogHelper.PlcLog("B轴收卷开始信号 D9720==2 -> 0");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.收卷轴开始, 0);
|
|
|
|
|
|
if (isReadFlag(ref lastReadTime_B_End))
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(7, 2);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
// A轴收卷完工信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.A收卷轴完工) == 1)
|
|
|
{
|
|
|
|
|
|
LogHelper.PlcLog("A轴收卷完工信号");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.控制下料, 1);
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.A收卷轴完工, 0);
|
|
|
if (isReadFlag(ref lastReadTime_A_End))
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(4, 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// B轴收卷完工信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.B收卷轴完工) == 1)
|
|
|
{
|
|
|
LogHelper.PlcLog("B轴收卷完工信号");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.控制下料, 1);
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.B收卷轴完工, 0);
|
|
|
|
|
|
if (isReadFlag(ref lastReadTime_B_End))
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(4, 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//A轴强制下料
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.强制下料) == 1)
|
|
|
{
|
|
|
LogHelper.PlcLog("A轴强制下料");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.强制下料, 0);
|
|
|
|
|
|
if (isReadFlag(ref lastReadTime_Force))
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(5, 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//B轴强制下料
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.TbAddress.强制下料) == 2)
|
|
|
{
|
|
|
LogHelper.PlcLog("B轴强制下料");
|
|
|
plcInstance.writeInt32ByAddress(appConfig.TbAddress.强制下料, 0);
|
|
|
if (isReadFlag(ref lastReadTime_Force))
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(5, 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 冷压
|
|
|
//冷压工序、赢合厂家
|
|
|
if (processCode.Equals("LY_A"))
|
|
|
{
|
|
|
//放卷 涨紧信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.放卷涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.放卷涨紧, 0);
|
|
|
SignalRefreshEvent?.Invoke(1, 0);
|
|
|
}
|
|
|
|
|
|
//放卷结束信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.放卷结束) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.放卷结束, 0);
|
|
|
SignalRefreshEvent?.Invoke(2, 0);
|
|
|
}
|
|
|
|
|
|
//收卷涨紧信号-1A气胀轴
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷1A涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷1A涨紧, 0);
|
|
|
SignalRefreshEvent?.Invoke(3, 1);
|
|
|
}
|
|
|
//收卷涨紧信号-1B气胀轴
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷1B涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷1B涨紧, 0);
|
|
|
SignalRefreshEvent?.Invoke(3, 2);
|
|
|
}
|
|
|
//收卷涨紧信号-2A气胀轴
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷2A涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷2A涨紧, 0);
|
|
|
SignalRefreshEvent?.Invoke(3, 3);
|
|
|
|
|
|
}
|
|
|
//收卷涨紧信号-2B气胀轴
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷2B涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷2B涨紧, 0);
|
|
|
SignalRefreshEvent?.Invoke(3, 4);
|
|
|
}
|
|
|
|
|
|
//收卷结束信号-1A气胀轴
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷1A结束) == 1)
|
|
|
{
|
|
|
lock (string.Empty)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷1A结束, 0);
|
|
|
SignalRefreshEvent?.Invoke(4, 1);
|
|
|
}
|
|
|
}
|
|
|
//收卷结束信号-1B气胀轴
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷1B结束) == 1)
|
|
|
{
|
|
|
lock (string.Empty)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷1B结束, 0);
|
|
|
SignalRefreshEvent?.Invoke(4, 2);
|
|
|
}
|
|
|
}
|
|
|
//收卷结束信号-2A气胀轴
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷2A结束) == 1)
|
|
|
{
|
|
|
lock (string.Empty)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷2A结束, 0);
|
|
|
SignalRefreshEvent?.Invoke(4, 3);
|
|
|
}
|
|
|
}
|
|
|
//收卷结束信号-2B气胀轴
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷2B结束) == 1)
|
|
|
{
|
|
|
lock (string.Empty)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷2B结束, 0);
|
|
|
SignalRefreshEvent?.Invoke(4, 4);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//异常下料-1A
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷1A异常下料) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷1A异常下料, 0);
|
|
|
SignalRefreshEvent?.Invoke(5, 1);
|
|
|
}
|
|
|
//异常下料-1B
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷1B异常下料) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷1B异常下料, 0);
|
|
|
SignalRefreshEvent?.Invoke(5, 2);
|
|
|
}
|
|
|
//异常下料-2A
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷2A异常下料) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷2A异常下料, 0);
|
|
|
SignalRefreshEvent?.Invoke(5, 3);
|
|
|
}
|
|
|
//异常下料-2B
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.LyAddress.收卷2B异常下料) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.LyAddress.收卷2B异常下料, 0);
|
|
|
SignalRefreshEvent?.Invoke(5, 4);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 模切
|
|
|
if (processCode.Equals("MQ_A"))
|
|
|
{
|
|
|
|
|
|
//开机启动信号 Add By WenJy 2022-10-12
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.开机启动) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.mqAddress.开机启动, 0);
|
|
|
SignalRefreshEvent?.Invoke(8, 0);
|
|
|
}
|
|
|
|
|
|
//左放卷 涨紧信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.左放卷涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.mqAddress.左放卷涨紧, 0);
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(1, 6);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(1, 5);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//右放卷 涨紧信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.右放卷涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.mqAddress.右放卷涨紧, 0);
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(1, 5);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(1, 6);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//左放卷 开始信号
|
|
|
if (plcInstance.readBoolByAddress(appConfig.mqAddress.左放卷开始))
|
|
|
{
|
|
|
if (isReadFlag(ref lastReadTime_A_Begin))
|
|
|
{
|
|
|
LogHelper.PlcLog("读到左放卷开始信号");
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(6, 6);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(6, 5);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//右放卷 开始信号
|
|
|
if (plcInstance.readBoolByAddress(appConfig.mqAddress.右放卷开始))
|
|
|
{
|
|
|
if (isReadFlag(ref lastReadTime_A_End))
|
|
|
{
|
|
|
LogHelper.PlcLog("读到右放卷开始信号");
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(6, 5);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(6, 6);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//左放卷 结束信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.左放卷结束) == 1)
|
|
|
{
|
|
|
writePlc(appConfig.mqAddress.左放卷结束, 0);
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(2, 6);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(2, 5);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//右放卷 结束信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.右放卷结束) == 1)
|
|
|
{
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(2, 5);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(2, 6);
|
|
|
}
|
|
|
writePlc(appConfig.mqAddress.右放卷结束, 0);
|
|
|
}
|
|
|
|
|
|
//上收卷左侧涨紧 信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.上左收卷涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.mqAddress.上左收卷涨紧, 0);
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(3, 3);
|
|
|
}
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(3, 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//上收卷右侧涨紧 信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.上右收卷涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.mqAddress.上右收卷涨紧, 0);
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(3, 1);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(3, 3);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//下收卷左侧涨紧 信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.下左收卷涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.mqAddress.下左收卷涨紧, 0);
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(3, 4);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(3, 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//下收卷右侧涨紧 信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.下右收卷涨紧) == 1)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(appConfig.mqAddress.下右收卷涨紧, 0);
|
|
|
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(3, 2);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(3, 4);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//上收卷左侧开始信号
|
|
|
if (plcInstance.readBoolByAddress(appConfig.mqAddress.上左收卷开始))
|
|
|
{
|
|
|
if (isReadFlag(ref lastReadTime_B_Begin))
|
|
|
{
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(7, 3);
|
|
|
}
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(7, 1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//上收卷右侧开始信号
|
|
|
if (plcInstance.readBoolByAddress(appConfig.mqAddress.上右收卷开始))
|
|
|
{
|
|
|
if (isReadFlag(ref lastReadTime_B_End))
|
|
|
{
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(7, 1);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(7, 3);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//下收卷左侧开始信号
|
|
|
if (plcInstance.readBoolByAddress(appConfig.mqAddress.下左收卷开始))
|
|
|
{
|
|
|
if (isReadFlag(ref lastReadTime_Force))
|
|
|
{
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(7, 4);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(7, 2);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//下收卷右侧开始信号
|
|
|
if (plcInstance.readBoolByAddress(appConfig.mqAddress.下右收卷开始))
|
|
|
{
|
|
|
if (isReadFlag(ref lastReadTime_ForceSecond))
|
|
|
{
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(7, 2);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(7, 4);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//上左收卷结束信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.上左收卷结束) == 1)
|
|
|
{
|
|
|
writePlc(appConfig.mqAddress.上左收卷结束, 0);
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(4, 3);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(4, 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//上右收卷结束信号
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.上右收卷结束) == 1)
|
|
|
{
|
|
|
writePlc(appConfig.mqAddress.上右收卷结束, 0);
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(4, 1);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(4, 3);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//下左收卷结束
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.下左收卷结束) == 1)
|
|
|
{
|
|
|
writePlc(appConfig.mqAddress.下左收卷结束, 0);
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(4, 4);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(4, 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//下右收卷结束
|
|
|
if (plcInstance.readInt32ByAddress(appConfig.mqAddress.下右收卷结束) == 1)
|
|
|
{
|
|
|
writePlc(appConfig.mqAddress.下右收卷结束, 0);
|
|
|
if (appConfig.machineId == 3)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(4, 2);
|
|
|
}
|
|
|
|
|
|
if (appConfig.machineId == 4)
|
|
|
{
|
|
|
SignalRefreshEvent?.Invoke(4, 4);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.Error("读取PLC信号异常",ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据时间差判断信号是否处理
|
|
|
/// </summary>
|
|
|
/// <param name="lastReadTime"></param>
|
|
|
/// <returns></returns>
|
|
|
public static bool isReadFlag(ref DateTime lastReadTime)
|
|
|
{
|
|
|
DateTime nowReadTime = DateTime.Now;
|
|
|
TimeSpan info = nowReadTime - lastReadTime;
|
|
|
int elapsedTime = Convert.ToInt32(info.TotalSeconds);
|
|
|
LogHelper.PlcLog("开始时间:" + lastReadTime.ToString("G") + ";结束时间:" + nowReadTime.ToString("G") + ";时间差:" + elapsedTime);
|
|
|
if (elapsedTime < 30)
|
|
|
{
|
|
|
LogHelper.PlcLog("距离上次读取时间小于30S,不触发逻辑处理");
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//上次读取时间
|
|
|
lastReadTime = nowReadTime;
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// PLC地址写入
|
|
|
/// </summary>
|
|
|
/// <param name="address"></param>
|
|
|
/// <param name="value"></param>
|
|
|
public void writePlc(string address,int value)
|
|
|
{
|
|
|
plcInstance.writeInt32ByAddress(address, value);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 写入String类型数据
|
|
|
/// </summary>
|
|
|
/// <param name="address"></param>
|
|
|
/// <param name="value"></param>
|
|
|
public static void writeStrPlc(string address, string value)
|
|
|
{
|
|
|
plcInstance.writeStringByAddress(address, value);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 写入double类型
|
|
|
/// </summary>
|
|
|
/// <param name="address"></param>
|
|
|
/// <param name="value"></param>
|
|
|
public void writeDoublePlc(string address, int value)
|
|
|
{
|
|
|
plcInstance.writeDoubleByAddress(address, value);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 读取String类型数据
|
|
|
/// </summary>
|
|
|
/// <param name="address"></param>
|
|
|
/// <param name="length"></param>
|
|
|
public static string readStrPlc(string address,ushort length)
|
|
|
{
|
|
|
return plcInstance.readStringByAddress(address, length);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// PLC地址读取
|
|
|
/// </summary>
|
|
|
/// <param name="address"></param>
|
|
|
/// <returns></returns>
|
|
|
public static int readPlc(string address)
|
|
|
{
|
|
|
var info = plcInstance.readInt32ByAddress(address);
|
|
|
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// PLC地址读取-bool
|
|
|
/// </summary>
|
|
|
/// <param name="address"></param>
|
|
|
/// <returns></returns>
|
|
|
public static bool readBoolPlc(string address)
|
|
|
{
|
|
|
var info = plcInstance.readBoolByAddress(address);
|
|
|
|
|
|
return info;
|
|
|
}
|
|
|
}
|
|
|
}
|