You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
990 lines
46 KiB
990 lines
46 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using OPCPLC;
|
|
using QMAPP.FJC.Entity.Basic;
|
|
using System.Configuration;
|
|
using QMAPP.FJC.DAL.Basic;
|
|
using QMAPP.FJC.Entity;
|
|
using System.Threading;
|
|
using OPCAutomation;
|
|
using QMAPP.FJC.BLL.Process;
|
|
|
|
namespace EQUIPINTERFACETEST
|
|
{
|
|
public class SkinScoreTest
|
|
{
|
|
//用来存储生产设备信息
|
|
public List<MachineInfo> machineList;
|
|
|
|
//用来存储设备加工参数信息
|
|
//key值样式为:设备号+模具号+读写状态+操作类别+数据库字段
|
|
public Dictionary<string, int> parameterValueDict;
|
|
|
|
private Dictionary<int, string> clientHandleDict = new Dictionary<int, string>();
|
|
|
|
private Dictionary<string, string> colunmConDict = new Dictionary<string, string>();
|
|
|
|
private int clientHandleValue = 0;
|
|
|
|
//加工参数列表静态变量
|
|
public List<ParameterConfig> paraConfigList;
|
|
|
|
//设备参数信息
|
|
public List<ParameterConfig> moldList;
|
|
|
|
//OPC零件信息列表静态变量
|
|
public Dictionary<string, OPCPLCAutomation> opcplcConnectionList;
|
|
|
|
public void InitParameter()
|
|
{
|
|
parameterValueDict = new Dictionary<string, int>();
|
|
|
|
moldList = new List<ParameterConfig>();
|
|
|
|
paraConfigList = new List<ParameterConfig>();
|
|
|
|
machineList = new List<MachineInfo>();
|
|
//获取数据库中所有的生产设备信息
|
|
|
|
opcplcConnectionList = new Dictionary<string, OPCPLCAutomation>();
|
|
|
|
try
|
|
{
|
|
#region 获取数据库中所有的生产设备信息
|
|
|
|
MachineInfoDAL machineDal = new MachineInfoDAL();
|
|
|
|
machineList = machineDal.GetList(new MachineInfo() { PROCESSTYPE = EnumGeter.ProcessType.lengdaoruohua.GetHashCode().ToString() });
|
|
|
|
#endregion
|
|
|
|
#region 获取所有的配置信息
|
|
|
|
ParameterConfigDAL paraConDal = new QMAPP.FJC.DAL.Basic.ParameterConfigDAL();
|
|
paraConfigList = paraConDal.GetList(new ParameterConfig() { MACHINECODDE = machineList[0].MACHINECODDE });
|
|
|
|
#endregion
|
|
|
|
#region 获取设备模块信息
|
|
|
|
//对加工参数配置信息按照设备及模具信息进行分组
|
|
var objlist = from pc in paraConfigList
|
|
group pc by new { pc.MACHINECODDE, pc.MOLDNUMBER } into g
|
|
select new ParameterConfig { MACHINECODDE = g.Key.MACHINECODDE, MOLDNUMBER = g.Key.MOLDNUMBER };
|
|
|
|
//添加到静态变量中
|
|
foreach (var ob in objlist)
|
|
{
|
|
moldList.Add(new ParameterConfig() { MACHINECODDE = ob.MACHINECODDE, MOLDNUMBER = ob.MOLDNUMBER });
|
|
}
|
|
|
|
//按照设备进行排序
|
|
moldList = moldList.OrderBy(o => o.MACHINECODDE).OrderBy(o => o.MOLDNUMBER).ToList<ParameterConfig>();
|
|
|
|
#endregion
|
|
|
|
#region 加载模块下的加工参数配置信息
|
|
|
|
//变量所有的模具信息
|
|
foreach (var m in moldList)
|
|
{
|
|
MachineInfo machineEntity = machineList.First(o => o.MACHINECODDE == m.MACHINECODDE);
|
|
|
|
#region 获取加工参数组
|
|
|
|
List<ParameterConfig> paraList = paraConfigList
|
|
.Where(o => o.MACHINECODDE == m.MACHINECODDE && o.MOLDNUMBER == m.MOLDNUMBER && o.COLUMNTYPE == "0")
|
|
.ToList<ParameterConfig>();
|
|
|
|
if (paraList.Count > 0)
|
|
{
|
|
OPCPLCAutomation gtxConnection = new OPCPLC.OPCPLCAutomation();
|
|
|
|
//opcServer服务器IP
|
|
string opcServerIP = ConfigurationManager.AppSettings.Get("OPCServerIP");
|
|
|
|
//opcServer服务名称
|
|
string opcServerName = ConfigurationManager.AppSettings.Get("OPCServerName");
|
|
|
|
gtxConnection.GetListOPCServers(opcServerIP);
|
|
//连接Opc服务
|
|
gtxConnection.ConnectRemoteServer(opcServerName, opcServerIP);
|
|
|
|
gtxConnection.CreateGroup(m.MACHINECODDE + ":" + m.MOLDNUMBER + ":GetData");
|
|
|
|
//变该模块下的所有参数信息
|
|
foreach (var pc in paraList)
|
|
{
|
|
|
|
try
|
|
{
|
|
//初始化字典名称: 设备名称+模块编号+字段名称
|
|
string dicKeyStr = machineEntity.MACHINECODDE + ":" + m.MOLDNUMBER + ":" + pc.COLUMNCODE;
|
|
|
|
//初始化字段信息值为0
|
|
parameterValueDict.Add(dicKeyStr, 0);
|
|
|
|
//获取opc中tagName
|
|
string itemName = pc.CONNECTIONSTRING;
|
|
|
|
clientHandleValue++;
|
|
|
|
clientHandleDict.Add(clientHandleValue, dicKeyStr);
|
|
|
|
//将字典中的与PLC内存地址向绑定
|
|
parameterValueDict[dicKeyStr] = gtxConnection.AddKepItem(itemName, clientHandleValue);
|
|
|
|
colunmConDict.Add(dicKeyStr, m.MACHINECODDE + ":" + m.MOLDNUMBER + ":GetData");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
//添加PLC连接信息
|
|
opcplcConnectionList.Add(m.MACHINECODDE + ":" + m.MOLDNUMBER + ":GetData", gtxConnection);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 写入组
|
|
|
|
List<ParameterConfig> writeList = paraConfigList
|
|
.Where(
|
|
o => o.MACHINECODDE == m.MACHINECODDE && o.MOLDNUMBER == m.MOLDNUMBER
|
|
&& (o.COLUMNTYPE == EQUIPINTERFACETESTCommon.COLUMNTYPE.OPERATEFLAG.GetHashCode().ToString()
|
|
|| o.COLUMNTYPE == EQUIPINTERFACETESTCommon.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString()
|
|
)
|
|
)
|
|
.ToList<ParameterConfig>();
|
|
|
|
|
|
if (writeList.Count > 0)
|
|
{
|
|
OPCPLCAutomation gtxConnection = new OPCPLC.OPCPLCAutomation();
|
|
|
|
//opcServer服务器IP
|
|
string opcServerIP = ConfigurationManager.AppSettings.Get("OPCServerIP");
|
|
|
|
//opcServer服务名称
|
|
string opcServerName = ConfigurationManager.AppSettings.Get("OPCServerName");
|
|
|
|
gtxConnection.GetListOPCServers(opcServerIP);
|
|
//连接Opc服务
|
|
gtxConnection.ConnectRemoteServer(opcServerName, opcServerIP);
|
|
|
|
gtxConnection.CreateGroup(m.MACHINECODDE + ":" + m.MOLDNUMBER + ":WriteData");
|
|
|
|
//变该模块下的所有参数信息
|
|
foreach (var pc in writeList)
|
|
{
|
|
//初始化字典名称: 设备名称+模块编号+字段名称
|
|
string dicKeyStr = machineEntity.MACHINECODDE + ":" + m.MOLDNUMBER + ":" + pc.COLUMNCODE;
|
|
|
|
//初始化字段信息值为0
|
|
parameterValueDict.Add(dicKeyStr, 0);
|
|
|
|
//获取opc中tagName
|
|
string itemName = pc.CONNECTIONSTRING;
|
|
|
|
clientHandleValue++;
|
|
|
|
clientHandleDict.Add(clientHandleValue, dicKeyStr);
|
|
|
|
//将字典中的与PLC内存地址向绑定
|
|
parameterValueDict[dicKeyStr] = gtxConnection.AddKepItem(itemName, clientHandleValue);
|
|
|
|
colunmConDict.Add(dicKeyStr, m.MACHINECODDE + ":" + m.MOLDNUMBER + ":WriteData");
|
|
}
|
|
|
|
//添加PLC连接信息
|
|
opcplcConnectionList.Add(m.MACHINECODDE + ":" + m.MOLDNUMBER + ":WriteData", gtxConnection);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 条码信息
|
|
|
|
List<ParameterConfig> barcodePara = paraConfigList
|
|
.Where(o => o.MACHINECODDE == m.MACHINECODDE
|
|
&& o.MOLDNUMBER == m.MOLDNUMBER
|
|
&& o.COLUMNTYPE == EQUIPINTERFACETESTCommon.COLUMNTYPE.BARCODE.GetHashCode().ToString())
|
|
.ToList<ParameterConfig>();
|
|
|
|
if (barcodePara.Count > 0)
|
|
{
|
|
OPCPLCAutomation gtxConnection = new OPCPLC.OPCPLCAutomation();
|
|
|
|
//opcServer服务器IP
|
|
string opcServerIP = ConfigurationManager.AppSettings.Get("OPCServerIP");
|
|
|
|
//opcServer服务名称
|
|
string opcServerName = ConfigurationManager.AppSettings.Get("OPCServerName");
|
|
|
|
gtxConnection.GetListOPCServers(opcServerIP);
|
|
//连接Opc服务
|
|
gtxConnection.ConnectRemoteServer(opcServerName, opcServerIP);
|
|
|
|
gtxConnection.CreateGroup(m.MACHINECODDE + ":" + m.MOLDNUMBER + ":BarCodePara");
|
|
|
|
//变该模块下的所有参数信息
|
|
foreach (var pc in barcodePara)
|
|
{
|
|
|
|
try
|
|
{
|
|
//初始化字典名称: 设备名称+模块编号+字段名称
|
|
string dicKeyStr = machineEntity.MACHINECODDE + ":" + m.MOLDNUMBER + ":" + pc.COLUMNCODE;
|
|
|
|
//初始化字段信息值为0
|
|
parameterValueDict.Add(dicKeyStr, 0);
|
|
|
|
//获取opc中tagName
|
|
string itemName = pc.CONNECTIONSTRING;
|
|
|
|
clientHandleValue++;
|
|
|
|
clientHandleDict.Add(clientHandleValue, dicKeyStr);
|
|
|
|
//将字典中的与PLC内存地址向绑定
|
|
parameterValueDict[dicKeyStr] = gtxConnection.AddKepItem(itemName, clientHandleValue);
|
|
|
|
colunmConDict.Add(dicKeyStr, m.MACHINECODDE + ":" + m.MOLDNUMBER + ":BarCodePara");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
throw;
|
|
}
|
|
|
|
}
|
|
|
|
//添加PLC连接信息
|
|
opcplcConnectionList.Add(m.MACHINECODDE + ":" + m.MOLDNUMBER + ":BarCodePara", gtxConnection);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 公共参数组
|
|
|
|
List<ParameterConfig> commonPara = paraConfigList
|
|
.Where(o => o.MACHINECODDE == m.MACHINECODDE
|
|
&& o.MOLDNUMBER == m.MOLDNUMBER
|
|
&& o.COLUMNTYPE == EQUIPINTERFACETESTCommon.COLUMNTYPE.PUBLICDATA.GetHashCode().ToString())
|
|
.ToList<ParameterConfig>();
|
|
|
|
if (commonPara.Count > 0)
|
|
{
|
|
OPCPLCAutomation gtxConnection = new OPCPLC.OPCPLCAutomation();
|
|
|
|
//opcServer服务器IP
|
|
string opcServerIP = ConfigurationManager.AppSettings.Get("OPCServerIP");
|
|
|
|
//opcServer服务名称
|
|
string opcServerName = ConfigurationManager.AppSettings.Get("OPCServerName");
|
|
|
|
gtxConnection.GetListOPCServers(opcServerIP);
|
|
//连接Opc服务
|
|
gtxConnection.ConnectRemoteServer(opcServerName, opcServerIP);
|
|
|
|
gtxConnection.CreateGroup(m.MACHINECODDE + ":" + m.MOLDNUMBER + ":CommonPara");
|
|
|
|
//变该模块下的所有参数信息
|
|
foreach (var pc in commonPara)
|
|
{
|
|
|
|
try
|
|
{
|
|
//初始化字典名称: 设备名称+模块编号+字段名称
|
|
string dicKeyStr = machineEntity.MACHINECODDE + ":" + m.MOLDNUMBER + ":" + pc.COLUMNCODE;
|
|
|
|
//初始化字段信息值为0
|
|
parameterValueDict.Add(dicKeyStr, 0);
|
|
|
|
//获取opc中tagName
|
|
string itemName = pc.CONNECTIONSTRING;
|
|
|
|
clientHandleValue++;
|
|
|
|
clientHandleDict.Add(clientHandleValue, dicKeyStr);
|
|
|
|
//将字典中的与PLC内存地址向绑定
|
|
parameterValueDict[dicKeyStr] = gtxConnection.AddKepItem(itemName, clientHandleValue);
|
|
|
|
colunmConDict.Add(dicKeyStr, m.MACHINECODDE + ":" + m.MOLDNUMBER + ":CommonPara");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
throw;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//添加PLC连接信息
|
|
opcplcConnectionList.Add(m.MACHINECODDE + ":" + m.MOLDNUMBER + ":CommonPara", gtxConnection);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 监控组
|
|
|
|
|
|
//获取设备扫描条码完成标记和设备加工完成标记
|
|
List<ParameterConfig> monitorList = paraConfigList
|
|
.Where(o => o.MACHINECODDE == m.MACHINECODDE && o.MOLDNUMBER == m.MOLDNUMBER
|
|
&& (
|
|
o.COLUMNTYPE == EQUIPINTERFACETESTCommon.COLUMNTYPE.EQUIPSCANFLAG.GetHashCode().ToString()
|
|
|| o.COLUMNTYPE == EQUIPINTERFACETESTCommon.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString()
|
|
|| o.COLUMNTYPE == EQUIPINTERFACETESTCommon.COLUMNTYPE.INTERRUPT.GetHashCode().ToString()))
|
|
.ToList<ParameterConfig>();
|
|
|
|
if (monitorList.Count > 0)
|
|
{
|
|
OPCPLCAutomation gtxConnection = new OPCPLC.OPCPLCAutomation();
|
|
|
|
//opcServer服务器IP
|
|
string opcServerIP = ConfigurationManager.AppSettings.Get("OPCServerIP");
|
|
|
|
//opcServer服务名称
|
|
string opcServerName = ConfigurationManager.AppSettings.Get("OPCServerName");
|
|
|
|
gtxConnection.GetListOPCServers(opcServerIP);
|
|
//连接Opc服务
|
|
gtxConnection.ConnectRemoteServer(opcServerName, opcServerIP);
|
|
|
|
gtxConnection.CreateGroup(m.MACHINECODDE + ":" + m.MOLDNUMBER + ":Monitor");
|
|
|
|
//变该模块下的所有参数信息
|
|
foreach (var pc in monitorList)
|
|
{
|
|
//初始化字典名称: 设备名称+模块编号+字段名称
|
|
string dicKeyStr = machineEntity.MACHINECODDE + ":" + m.MOLDNUMBER + ":" + pc.COLUMNCODE;
|
|
|
|
//初始化字段信息值为0
|
|
parameterValueDict.Add(dicKeyStr, 0);
|
|
|
|
//获取opc中tagName
|
|
string itemName = pc.CONNECTIONSTRING;
|
|
|
|
clientHandleValue++;
|
|
|
|
clientHandleDict.Add(clientHandleValue, dicKeyStr);
|
|
|
|
//将字典中的与PLC内存地址向绑定
|
|
parameterValueDict[dicKeyStr] = gtxConnection.AddKepItem(itemName, clientHandleValue);
|
|
|
|
colunmConDict.Add(dicKeyStr, m.MACHINECODDE + ":" + m.MOLDNUMBER + ":Monitor");
|
|
}
|
|
|
|
gtxConnection.KepGroups.DefaultGroupIsActive = true;//激活组。
|
|
gtxConnection.KepGroups.DefaultGroupDeadband = 0;// 死区值,设为0时,服务器端该组内任何数据变化都通知组。
|
|
gtxConnection.KepGroups.DefaultGroupUpdateRate = 200;//默认组群的刷新频率为200ms
|
|
gtxConnection.KepGroup.UpdateRate = 200;//刷新频率为1秒。
|
|
gtxConnection.KepGroup.IsSubscribed = true;//使用订阅功能,即可以异步,默认false
|
|
|
|
gtxConnection.KepGroup.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(KepGroup_DataChange);
|
|
|
|
//添加PLC连接信息
|
|
opcplcConnectionList.Add(m.MACHINECODDE + ":" + m.MOLDNUMBER + ":Monitor", gtxConnection);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
Console.WriteLine("Finish loading basedata!");
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
private void KepGroup_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps)
|
|
{
|
|
|
|
try
|
|
{
|
|
//延迟一秒
|
|
Thread.Sleep(1000);
|
|
|
|
//为了测试,所以加了控制台的输出,来查看事物ID号
|
|
//Console.WriteLine("********"+TransactionID.ToString()+"*********");
|
|
for (int i = 1; i <= NumItems; i++)
|
|
{
|
|
//获取写入的值
|
|
var itemValue = ItemValues.GetValue(i);
|
|
|
|
//获取客户端句柄
|
|
int chvalue = Convert.ToInt32(ClientHandles.GetValue(i));
|
|
|
|
//获取服务端字典key值
|
|
string dicKeyStr = clientHandleDict[chvalue];
|
|
|
|
//获取设备信息
|
|
string machCode = dicKeyStr.Substring(0, dicKeyStr.IndexOf(':'));
|
|
|
|
string moldAndColumn = dicKeyStr.Substring(dicKeyStr.IndexOf(':') + 1);
|
|
|
|
//获取模块信息
|
|
string moldNumber = moldAndColumn.Substring(0, moldAndColumn.IndexOf(':'));
|
|
|
|
//获取字段名称
|
|
string columnCode = dicKeyStr.Substring(dicKeyStr.LastIndexOf(':') + 1);
|
|
|
|
ParameterConfig currentPC = paraConfigList.First(o => o.MACHINECODDE == machCode && o.MOLDNUMBER == moldNumber && o.COLUMNCODE == columnCode);
|
|
|
|
//完成标记
|
|
if (currentPC.COLUMNTYPE == EQUIPINTERFACETESTCommon.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString())
|
|
{
|
|
List<ParameterConfig> resultList = new List<ParameterConfig>();
|
|
#region 操作完成
|
|
try
|
|
{
|
|
if (itemValue == null)
|
|
{
|
|
Console.WriteLine(currentPC.COLUMNCODE.ToString() + " value is null");
|
|
WriteLog.Write(currentPC.COLUMNCODE.ToString() + " value is null");
|
|
continue;
|
|
}
|
|
//如果完成标记表示更新了加工参数
|
|
//获取所有的加工参数
|
|
if ((Boolean)itemValue == true)
|
|
{
|
|
|
|
Console.WriteLine(System.DateTime.Now.ToLongTimeString() + " catch FINISH,the value is true");
|
|
WriteLog.Write(System.DateTime.Now.ToLongTimeString() + " catch FINISH,the value is true");
|
|
|
|
#region 获取参数
|
|
|
|
|
|
|
|
List<ParameterConfig> paraList = paraConfigList
|
|
.Where(o =>
|
|
o.MACHINECODDE == machCode
|
|
&& o.MOLDNUMBER == moldNumber
|
|
&& (
|
|
o.COLUMNTYPE == OpcHostEnumGeter.COLUMNTYPE.PARAMETER.GetHashCode().ToString()
|
|
)
|
|
)
|
|
.OrderBy(o => o.COLUMNCODE)
|
|
.ToList<ParameterConfig>();
|
|
|
|
foreach (var parameter in paraList)
|
|
{
|
|
|
|
try
|
|
{
|
|
string item = parameter.MACHINECODDE + ":" + parameter.MOLDNUMBER + ":" + parameter.COLUMNCODE;
|
|
|
|
string conListKey = colunmConDict[item];
|
|
|
|
OPCPLCAutomation con = opcplcConnectionList[conListKey];
|
|
|
|
var result = con.ReadtagValue(parameterValueDict[item]);
|
|
|
|
if (parameter.COLUMNCODE != "RELEASE" && (parameter.COLUMNCODE.Contains("WORKTIME") || parameter.COLUMNCODE.ToUpper().Contains("RELEASE")))
|
|
{
|
|
Console.WriteLine(parameter.COLUMNCODE + ":" + (char)Convert.ToInt32(result));
|
|
WriteLog.Write(parameter.COLUMNCODE + ":" + (char)Convert.ToInt32(result));
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine(parameter.COLUMNCODE + ":" + result.ToString());
|
|
WriteLog.Write(parameter.COLUMNCODE + ":" + result.ToString());
|
|
}
|
|
|
|
ParameterConfig paraConfig = GetResultParameterConfig(parameter);
|
|
|
|
if (result != null)
|
|
{
|
|
paraConfig.PARAVALUE = result;
|
|
}
|
|
|
|
resultList.Add(paraConfig);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Console.WriteLine("获取" + parameter.COLUMNCODE + "值异常");
|
|
WriteLog.Write("获取" + parameter.COLUMNCODE + "值异常");
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
List<ParameterConfig> paraReadList = paraConfigList
|
|
.Where(o =>
|
|
o.MACHINECODDE == machCode
|
|
&& o.MOLDNUMBER == moldNumber
|
|
&& (
|
|
o.COLUMNTYPE == OpcHostEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString()
|
|
)
|
|
)
|
|
.ToList<ParameterConfig>();
|
|
|
|
foreach (var p in paraReadList)
|
|
{
|
|
Console.WriteLine(System.DateTime.Now.ToLongTimeString() + " set Data_Colleted,the value is true");
|
|
WriteLog.Write(System.DateTime.Now.ToLongTimeString() + " set Data_Colleted,the value is true");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], true);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 插入数据库
|
|
|
|
OperateProcess operateProcess = new OperateProcess();
|
|
operateProcess.Process(machineList[0], resultList);
|
|
|
|
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
|
|
List<ParameterConfig> paraReadList = paraConfigList
|
|
.Where(o =>
|
|
o.MACHINECODDE == machCode
|
|
&& o.MOLDNUMBER == moldNumber
|
|
&& (
|
|
o.COLUMNTYPE == OpcHostEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString()
|
|
||o.COLUMNTYPE==OpcHostEnumGeter.COLUMNTYPE.OPERATEFLAG.GetHashCode().ToString()
|
|
)
|
|
)
|
|
.ToList<ParameterConfig>();
|
|
|
|
foreach (var p in paraReadList)
|
|
{
|
|
Console.WriteLine(System.DateTime.Now.ToLongTimeString() + " set Data_Colleted,the value is false");
|
|
WriteLog.Write(System.DateTime.Now.ToLongTimeString() + " set Data_Colleted,the value is false");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], false);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
WriteLog.Write(ex.Message
|
|
);
|
|
continue;
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
else if (currentPC.COLUMNTYPE == EQUIPINTERFACETESTCommon.COLUMNTYPE.EQUIPSCANFLAG.GetHashCode().ToString())
|
|
{
|
|
#region 提示扫描条码完成
|
|
|
|
if (itemValue == null)
|
|
{
|
|
Console.WriteLine(currentPC.COLUMNCODE.ToString() + "值为null");
|
|
WriteLog.Write(currentPC.COLUMNCODE.ToString() + "值为null");
|
|
continue;
|
|
}
|
|
|
|
//如果完成标记表示更新了加工参数
|
|
//获取所有的加工参数
|
|
if ((Boolean)itemValue == true)
|
|
{
|
|
bool ishaveBarcode = true;
|
|
|
|
Console.WriteLine("--------------Start to SkinScore--------------");
|
|
WriteLog.Write("--------------Start to SkinScore--------------");
|
|
|
|
Console.WriteLine(System.DateTime.Now.ToLongTimeString() + " Barcode scaned!");
|
|
WriteLog.Write(System.DateTime.Now.ToLongTimeString() + " Barcode scaned!");
|
|
|
|
List<ParameterConfig> paraList = paraConfigList
|
|
.Where(o =>
|
|
o.MACHINECODDE == machCode
|
|
&& o.MOLDNUMBER == moldNumber
|
|
&& (
|
|
o.COLUMNTYPE == EQUIPINTERFACETESTCommon.COLUMNTYPE.BARCODE.GetHashCode().ToString()
|
|
)
|
|
)
|
|
.OrderBy(o => o.COLUMNCODE)
|
|
.ToList<ParameterConfig>();
|
|
|
|
foreach (var parameter in paraList)
|
|
{
|
|
|
|
try
|
|
{
|
|
string item = parameter.MACHINECODDE + ":" + parameter.MOLDNUMBER + ":" + parameter.COLUMNCODE;
|
|
|
|
string conListKey = colunmConDict[item];
|
|
|
|
OPCPLCAutomation con = opcplcConnectionList[conListKey];
|
|
|
|
var result = con.ReadtagValue(parameterValueDict[item]);
|
|
|
|
Console.WriteLine(parameter.COLUMNCODE + ":" + result.ToString());
|
|
|
|
|
|
|
|
WriteLog.Write(parameter.COLUMNCODE + ":" + result.ToString());
|
|
|
|
if (string.IsNullOrEmpty(result.ToString().Trim()))
|
|
{
|
|
ishaveBarcode = false;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("获取" + parameter.COLUMNCODE + "值异常");
|
|
WriteLog.Write("获取" + parameter.COLUMNCODE + "值异常");
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if (ishaveBarcode == false)
|
|
{
|
|
Console.WriteLine("Fail to get barcode!");
|
|
WriteLog.Write("Fail to get barcode!");
|
|
continue;
|
|
}
|
|
|
|
|
|
List<ParameterConfig> paraWriteList = paraConfigList
|
|
.Where(o =>
|
|
o.MACHINECODDE == machCode
|
|
&& o.MOLDNUMBER == moldNumber
|
|
&& (
|
|
o.COLUMNTYPE == OpcHostEnumGeter.COLUMNTYPE.OPERATEFLAG.GetHashCode().ToString()
|
|
)
|
|
)
|
|
.ToList<ParameterConfig>();
|
|
|
|
string resultOk = ConfigurationManager.AppSettings["ResultValue"];
|
|
|
|
//resultOk = "NOK";
|
|
|
|
if (resultOk == "OK")
|
|
{
|
|
ParameterConfig p = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODEOK");
|
|
Console.WriteLine("set BARCODEOK value true");
|
|
WriteLog.Write("set BARCODEOK value true");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], true);
|
|
|
|
ParameterConfig p2 = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODENOK");
|
|
Console.WriteLine("set BARCODENOK value false");
|
|
WriteLog.Write("set BARCODEOK value false");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p2.MACHINECODDE + ":" + p2.MOLDNUMBER + ":" + p2.COLUMNCODE], false);
|
|
|
|
}
|
|
else
|
|
{
|
|
//Console.WriteLine("milling interupted last time");
|
|
//WriteLog.Write("milling interupted last time");
|
|
|
|
ParameterConfig p = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODEOK");
|
|
Console.WriteLine("set BARCODEOK value false");
|
|
WriteLog.Write("set BARCODEOK value false");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], false);
|
|
|
|
ParameterConfig p2 = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODENOK");
|
|
Console.WriteLine("set BARCODENOK value true");
|
|
WriteLog.Write("set BARCODEOK value true");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p2.MACHINECODDE + ":" + p2.MOLDNUMBER + ":" + p2.COLUMNCODE], true);
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
List<ParameterConfig> paraWriteList = paraConfigList
|
|
.Where(o =>
|
|
o.MACHINECODDE == machCode
|
|
&& o.MOLDNUMBER == moldNumber
|
|
&& (
|
|
o.COLUMNTYPE == OpcHostEnumGeter.COLUMNTYPE.OPERATEFLAG.GetHashCode().ToString()
|
|
)
|
|
)
|
|
.ToList<ParameterConfig>();
|
|
|
|
ParameterConfig p = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODEOK");
|
|
Console.WriteLine("set BARCODEOK value false");
|
|
WriteLog.Write("set BARCODEOK value false");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], false);
|
|
|
|
ParameterConfig p2 = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODENOK");
|
|
Console.WriteLine("set BARCODENOK value false");
|
|
WriteLog.Write("set BARCODEOK value false");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p2.MACHINECODDE + ":" + p2.MOLDNUMBER + ":" + p2.COLUMNCODE], false);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
else if (currentPC.COLUMNTYPE == EQUIPINTERFACETESTCommon.COLUMNTYPE.INTERRUPT.GetHashCode().ToString())
|
|
{
|
|
//捕获停止事件
|
|
if (itemValue == null)
|
|
{
|
|
Console.WriteLine(currentPC.COLUMNCODE.ToString() + "值为null");
|
|
WriteLog.Write(currentPC.COLUMNCODE.ToString() + "值为null");
|
|
continue;
|
|
}
|
|
|
|
if ((Boolean)itemValue == true)
|
|
{
|
|
Console.WriteLine("catch INTERUPT,the value is true");
|
|
WriteLog.Write("catch INTERUPT,the value is true");
|
|
|
|
//var reuslt = opcplcConnectionList["1A-CC0002:1:GetData"].ReadtagValue(parameterValueDict["1A-CC0002:1:RESULT"]);
|
|
|
|
List<ParameterConfig> resultList = paraConfigList
|
|
.Where(o => o.COLUMNCODE.Contains("RESULT"))
|
|
.OrderBy(o => o.COLUMNCODE)
|
|
.ToList<ParameterConfig>();
|
|
|
|
List<ParameterConfig> paraWriteList = paraConfigList
|
|
.Where(o =>
|
|
o.MACHINECODDE == machCode
|
|
&& o.MOLDNUMBER == moldNumber
|
|
&& (
|
|
o.COLUMNTYPE == OpcHostEnumGeter.COLUMNTYPE.OPERATEFLAG.GetHashCode().ToString()
|
|
)
|
|
)
|
|
.ToList<ParameterConfig>();
|
|
|
|
|
|
var reuslt = opcplcConnectionList["1A-CC0002:1:GetData"].ReadtagValue(parameterValueDict[resultList[0].MACHINECODDE + ":" + resultList[0].MOLDNUMBER + ":" + resultList[0].COLUMNCODE]);
|
|
|
|
if (reuslt.ToString() == "NOK")
|
|
{
|
|
Console.WriteLine("RESULT" + ":" + "NOK, BARCODE IS SCARPED!");
|
|
WriteLog.Write("RESULT" + ":" + "NOK, BARCODE IS SCARPED!");
|
|
|
|
ParameterConfig p = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODEOK");
|
|
Console.WriteLine("set BARCODEOK value false");
|
|
WriteLog.Write("set BARCODEOK value false");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], false);
|
|
|
|
ParameterConfig p2 = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODENOK");
|
|
Console.WriteLine("set BARCODENOK value true");
|
|
WriteLog.Write("set BARCODEOK value true");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p2.MACHINECODDE + ":" + p2.MOLDNUMBER + ":" + p2.COLUMNCODE], true);
|
|
|
|
|
|
ConfigurationManager.AppSettings.Set("ResultValue", "NOK");
|
|
}
|
|
else
|
|
{
|
|
|
|
Console.WriteLine("RESULT" + ":" + "OK, BARCODE IS OK!");
|
|
WriteLog.Write("RESULT" + ":" + "OK, BARCODE IS OK!");
|
|
|
|
ParameterConfig p = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODEOK");
|
|
Console.WriteLine("set BARCODEOK value true");
|
|
WriteLog.Write("set BARCODEOK value true");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], true);
|
|
|
|
ParameterConfig p2 = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODENOK");
|
|
Console.WriteLine("set BARCODENOK value false");
|
|
WriteLog.Write("set BARCODEOK value false");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p2.MACHINECODDE + ":" + p2.MOLDNUMBER + ":" + p2.COLUMNCODE], false);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
Console.WriteLine("系统出现异常:" + ex.Message);
|
|
}
|
|
|
|
}
|
|
public void WriteTest()
|
|
{
|
|
|
|
List<ParameterConfig> paraWriteList = paraConfigList
|
|
.Where(o =>
|
|
o.MACHINECODDE == "1A-CC0002"
|
|
&& o.MOLDNUMBER == "1"
|
|
&& (
|
|
o.COLUMNTYPE == OpcHostEnumGeter.COLUMNTYPE.OPERATEFLAG.GetHashCode().ToString()
|
|
)
|
|
)
|
|
.ToList<ParameterConfig>();
|
|
|
|
//ParameterConfig p = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODEOK");
|
|
//Console.WriteLine("set BARCODEOK value true");
|
|
//WriteLog.Write("set BARCODEOK value true");
|
|
//opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], true);
|
|
|
|
//ParameterConfig p2 = paraWriteList.First(o => o.COLUMNCODE.ToUpper() == "BARCODENOK");
|
|
//Console.WriteLine("set BARCODENOK value false");
|
|
//WriteLog.Write("set BARCODEOK value false");
|
|
//opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p2.MACHINECODDE + ":" + p2.MOLDNUMBER + ":" + p2.COLUMNCODE], false);
|
|
//opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict["1A-CC0002" + ":" + "1" + ":" + "INTERRUPT"], false);
|
|
|
|
|
|
}
|
|
|
|
public void Test()
|
|
{
|
|
//hour = ConvertClass.DecToHex(result.ToString());
|
|
//延迟一秒
|
|
|
|
while (true)
|
|
{
|
|
Thread.Sleep(5000);
|
|
WriteLog.Write("--------------" + System.DateTime.Now.ToString("yyyy:MM:dd HH:mm:ss") + "--------------");
|
|
List<ParameterConfig> list = paraConfigList
|
|
//.Where(o => o.COLUMNTYPE == "8")
|
|
.OrderBy(o => o.COLUMNCODE).ToList<ParameterConfig>();
|
|
foreach (var parameter in list)
|
|
{
|
|
|
|
try
|
|
{
|
|
string item = parameter.MACHINECODDE + ":" + parameter.MOLDNUMBER + ":" + parameter.COLUMNCODE;
|
|
|
|
//string conListKey = colunmConDict[item];
|
|
|
|
OPCPLCAutomation con = new OPCPLCAutomation();
|
|
|
|
//加工参数
|
|
if (parameter.COLUMNTYPE == "0")
|
|
{
|
|
con = opcplcConnectionList["1A-CC0002:1:GetData"];
|
|
}
|
|
else if (parameter.COLUMNTYPE == "8")
|
|
{
|
|
//获取条码信息
|
|
con = opcplcConnectionList["1A-CC0002:1:BarCodePara"];
|
|
}
|
|
else if (parameter.COLUMNTYPE == "6" || parameter.COLUMNTYPE == "2")
|
|
{
|
|
//获取条码信息
|
|
con = opcplcConnectionList["1A-CC0002:1:WriteData"];
|
|
}
|
|
else if (parameter.COLUMNTYPE == "4" || parameter.COLUMNTYPE == "1" || parameter.COLUMNTYPE == "7")
|
|
{
|
|
//获取条码信息
|
|
con = opcplcConnectionList["1A-CC0002:1:Monitor"];
|
|
}
|
|
|
|
var result = con.ReadtagValue(parameterValueDict[item]);
|
|
|
|
if (result != null)
|
|
{
|
|
|
|
if (parameter.COLUMNCODE != "RESULT" && (parameter.COLUMNCODE.Contains("WORKTIME") || parameter.COLUMNCODE.ToUpper().Contains("RESULT")))
|
|
{
|
|
//Console.WriteLine(parameter.COLUMNCODE + ":" + (char)Convert.ToInt32(result));
|
|
WriteLog.Write(parameter.COLUMNCODE + ":" + (char)Convert.ToInt32(result));
|
|
}
|
|
else
|
|
{
|
|
//Console.WriteLine(item.ToString() + "值为" + result.ToString().Trim());
|
|
WriteLog.Write(item.ToString() + "值为" + result.ToString().Trim());
|
|
|
|
//if (parameter.COLUMNCODE == "BARCODE")
|
|
//{
|
|
// Console.WriteLine(item.ToString() + "值为" + result.ToString().Trim());
|
|
//}
|
|
}
|
|
|
|
if (parameter.COLUMNCODE == "RESULT")
|
|
{
|
|
int i = result.ToString().Length;
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
//Console.WriteLine(item.ToString() + ":");
|
|
WriteLog.Write(item.ToString() + ":");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Exception:" + parameter.COLUMNCODE);
|
|
Console.WriteLine(ex.Message);
|
|
continue;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void GetResult()
|
|
{
|
|
OPCPLCAutomation con = new OPCPLCAutomation();
|
|
con = opcplcConnectionList["1A-CC0002:1:GetData"];
|
|
|
|
List<ParameterConfig> list = paraConfigList
|
|
.Where(o => o.COLUMNCODE.Contains("RESULT")||o.COLUMNCODE=="RELEASE")
|
|
.OrderBy(o => o.COLUMNTYPE).ToList<ParameterConfig>();
|
|
|
|
foreach (var p in list)
|
|
{
|
|
string flag = p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE;
|
|
var obj = opcplcConnectionList["1A-CC0002:1:GetData"].ReadtagValue(parameterValueDict[flag]);
|
|
|
|
Console.WriteLine(obj.ToString());
|
|
}
|
|
}
|
|
|
|
internal void WriteBarcodeOk()
|
|
{
|
|
Thread.Sleep(3000);
|
|
|
|
|
|
ParameterConfig p = paraConfigList.First(o => o.COLUMNCODE.ToUpper() == "BARCODEOK");
|
|
Console.WriteLine("set BARCODEOK value true");
|
|
WriteLog.Write("set BARCODEOK value true");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], true);
|
|
|
|
ParameterConfig p2 = paraConfigList.First(o => o.COLUMNCODE.ToUpper() == "BARCODENOK");
|
|
Console.WriteLine("set BARCODENOK value false");
|
|
WriteLog.Write("set BARCODEOK value false");
|
|
opcplcConnectionList["1A-CC0002:1:WriteData"].WritetagValue(parameterValueDict[p2.MACHINECODDE + ":" + p2.MOLDNUMBER + ":" + p2.COLUMNCODE], false);
|
|
}
|
|
|
|
private ParameterConfig GetResultParameterConfig(ParameterConfig parameter)
|
|
{
|
|
ParameterConfig paraConfig = new ParameterConfig();
|
|
|
|
#region 属性复制
|
|
|
|
paraConfig.COLUMNCODE = parameter.COLUMNCODE;
|
|
paraConfig.COLUMNTYPE = parameter.COLUMNTYPE;
|
|
paraConfig.DATATYPE = parameter.DATATYPE;
|
|
paraConfig.DBNUMBER = parameter.DBNUMBER;
|
|
paraConfig.DEALTYPE = parameter.DEALTYPE;
|
|
paraConfig.MACHINECODDE = parameter.MACHINECODDE;
|
|
paraConfig.MOLDNUMBER = parameter.MOLDNUMBER;
|
|
paraConfig.OPERATETYPE = parameter.OPERATETYPE;
|
|
paraConfig.PROCESSTYPE = parameter.PROCESSTYPE;
|
|
|
|
#endregion
|
|
|
|
return paraConfig;
|
|
}
|
|
|
|
}
|
|
}
|
|
|