Browse Source

OPC增加门板超声焊设备扫码相关功能

master
dequan.zhang 3 years ago
parent
commit
51e923d9ec
  1. 13
      APPQ5/QMAPP.WinForm/Forms/Operation/OperationForm.cs
  2. 3
      ServicesCenter/WCF/OpcServerHost/App.config
  3. 1
      ServicesCenter/WCF/OpcServerHost/ChatEventHelper.cs
  4. 49
      ServicesCenter/WCF/OpcServerHost/OPCPLCAutomation.cs
  5. 35
      ServicesCenter/WCF/OpcServerHost/OpcDeal/EnumGeter.cs
  6. 606
      ServicesCenter/WCF/OpcServerHost/OpcDeal/ParaInit.cs

13
APPQ5/QMAPP.WinForm/Forms/Operation/OperationForm.cs

@ -2146,7 +2146,7 @@ namespace QMAPP.WinForm.Forms.Operation
{
try
{
if (messageType == "3") //模架号
if (messageType == "3") //模架号 MOULDCARRIER
{
var mould = mouldList.FirstOrDefault(p => string.Equals(p.MODELSTATION, message));
if (mould != null)
@ -2154,7 +2154,7 @@ namespace QMAPP.WinForm.Forms.Operation
SwitchMould(mould.MODELCODE);
}
}
else if (messageType == "4") //模具号
else if (messageType == "4") //模具号 MOULDNUMBER
{
var str_messages = message.Split(':');
if (!(string.Equals(str_messages[str_messages.Length - 1], "0") || string.Equals(str_messages[str_messages.Length - 1].ToUpper(), "FALSE")))
@ -2163,7 +2163,7 @@ namespace QMAPP.WinForm.Forms.Operation
}
return;
}
else if (messageType == "5") //模具号
else if (messageType == "5") //模具号OTHER
{
var str_messages = message.Split(':');
if (AttachInfo.ContainsKey(str_messages[0]))
@ -2180,9 +2180,8 @@ namespace QMAPP.WinForm.Forms.Operation
{
opcheartbeatwaithandel.Set();
}
else
else if(messageType == "0") // PRODUCTCODE
{
if (_AutoMachineCode.Contains(_operationServiceParam.machineInfo.MACHINECODDE))
{
List<ParameterConfig> list = QMFrameWork.Common.Serialization.JsonConvertHelper.GetDeserialize<List<ParameterConfig>>(message);
@ -2200,13 +2199,11 @@ namespace QMAPP.WinForm.Forms.Operation
Operation();
}
}
}
}
else
{
DAInput(message, "PARM");
}
return;
}

3
ServicesCenter/WCF/OpcServerHost/App.config

@ -10,7 +10,8 @@
</appSettings>
<connectionStrings>
<add name="maindb" connectionString="Data Source=10.111.144.98;Initial Catalog=ADIENT_CD_MES;User Id=CDMESADM;Password=CDmes123;" providerName="System.Data.SqlClient"/>
<!--<add name="maindb" connectionString="Data Source=10.111.144.98;Initial Catalog=ADIENT_CD_MES;User Id=CDMESADM;Password=CDmes123;" providerName="System.Data.SqlClient"/>-->
<add name="maindb" connectionString="Data Source=10.111.144.99;Initial Catalog=ADIENT_CD_MES9;User Id=sa;Password=Password2018;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.serviceModel>
<client>

1
ServicesCenter/WCF/OpcServerHost/ChatEventHelper.cs

@ -19,6 +19,7 @@ namespace OpcServerHost
//创建一个静态Dictionary存储设备的最新更新时间
public static Dictionary<string, DateTime> chatterTimes = new Dictionary<string, DateTime>();
public static Dictionary<string, string> machinegroups = new Dictionary<string, string>();
//定义定时器,不断地检索客户端是否连接
public static System.Timers.Timer dutyTimer;

49
ServicesCenter/WCF/OpcServerHost/OPCPLCAutomation.cs

@ -41,6 +41,8 @@ namespace OPCPLC
/// </summary>
public Dictionary<string, int> dirHandleServer = new Dictionary<string, int>();
public Dictionary<string, OPCGroup> GroupLists = new Dictionary<string, OPCGroup>();
/// <summary>
/// 枚举本地OPC服务器
/// </summary>
@ -199,6 +201,12 @@ namespace OPCPLC
return KepItem.ServerHandle;
}
public int AddKepItem2(string itemname, int clientHandleValue)
{
this.KepItem = this.KepGroup.OPCItems.AddItem(itemname, clientHandleValue);
return this.KepItem.ServerHandle;
}
public OPCItem AddKepOPCItem(string itemname, int clientHandleValue)
{
KepItem = KepGroup.OPCItems.AddItem(itemname, clientHandleValue);
@ -206,6 +214,12 @@ namespace OPCPLC
return KepItem;
}
public OPCItem AddKepOPCItem2(string itemname, int clientHandleValue)
{
KepItem = KepGroup.OPCItems.AddItem(itemname, clientHandleValue);
return KepItem;
}
/// <summary>
/// 向OPC中添加连续添加多个地址项
@ -297,6 +311,26 @@ namespace OPCPLC
}
}
public object ReadtagValue2(OPCItem bItem)
{
object result;
try
{
object obj;
object obj2;
object obj3;
bItem.Read(1, out obj, out obj2, out obj3);
result = obj;
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
return result;
}
/// <summary>
/// 释放资源处理的事情
/// </summary>
@ -360,6 +394,21 @@ namespace OPCPLC
}
}
public void WritetagValue1(OPCItem item, object obj)
{
try
{
item.Write(obj);
GC.Collect();
}
catch (Exception ex)
{
}
finally
{
}
}
/// <summary>
/// 向指定的地址项写入指定的值,不触发订阅
/// </summary>

35
ServicesCenter/WCF/OpcServerHost/OpcDeal/EnumGeter.cs

@ -71,7 +71,27 @@ namespace OpcServerHost.Common
/// <summary>
/// 模架号
/// </summary>
MOULDNUMBER = 11
//MOULDNUMBER = 11,
/// <summary>
///模架号
/// </summary>
MOULDCARRIER = 11,
/// <summary>
/// 模架号
/// </summary>
MOULDNUMBER = 12,
/// <summary>
/// 完成模架
/// </summary>
COMPLETEMOULD = 13,
/// <summary>
/// 操作模架号
/// </summary>
OPERATINGMOULD = 14
}
@ -95,7 +115,18 @@ namespace OpcServerHost.Common
/// <summary>
/// 中断信号
/// </summary>
MOULDNUMBER
MOULDCARRIER,
/// <summary>
/// 中断信号
/// </summary>
MOULDNUMBER,
/// <summary>
/// 其他信号
/// </summary>
OTHER
}
public enum SENDORDERTYPE

606
ServicesCenter/WCF/OpcServerHost/OpcDeal/ParaInit.cs

@ -38,6 +38,7 @@ namespace OpcServerHost.Init
public static Dictionary<string, OPCItem> opcItemDict = new Dictionary<string, OPCItem>();
/// <summary>
/// 用来存储客户端句柄与设备参数对应关系
/// key:客户端句柄值
@ -228,7 +229,7 @@ namespace OpcServerHost.Init
clientHandleDict.Add(clientHandleValue, dicKeyStr);
//将字典中的与PLC内存地址向绑定
//parameterValueDict[dicKeyStr] = opcDict[m.MACHINECODDE].AddKepItem(itemName, clientHandleValue);
opcItemDict[dicKeyStr] = opcDict[m.MACHINECODDE].AddKepOPCItem(itemName, clientHandleValue);
opcItemDict[dicKeyStr] = opcDict[m.MACHINECODDE].AddKepOPCItem2(itemName, clientHandleValue);
parameterValueDict[dicKeyStr] = opcItemDict[dicKeyStr].ServerHandle;
}
catch (Exception ex)
@ -250,6 +251,7 @@ namespace OpcServerHost.Init
int i = 1;
}
#endregion
#region 写入组
@ -291,13 +293,13 @@ namespace OpcServerHost.Init
{
clientHandleDict.Add(clientHandleValue, dicKeyStr);
//将字典中的与PLC内存地址向绑定
parameterValueDict[dicKeyStr] = opcplcConnection.AddKepItem(itemName, clientHandleValue);
parameterValueDict[dicKeyStr] = opcplcConnection.AddKepItem2(itemName, clientHandleValue);
}
catch (Exception ex)
{
Console.WriteLine("重复:" + dicKeyStr);
Console.WriteLine("允许加工-重复:" + dicKeyStr);
}
WriteLog.Write(dicKeyStr + " | " + itemName + " | " + clientHandleValue + " | " + parameterValueDict[dicKeyStr]);
}
@ -365,6 +367,20 @@ namespace OpcServerHost.Init
#region 监控组
////获取设备扫描条码完成标记和设备加工完成标记
//List<ParameterConfig> monitorList = paraConfigList
// .Where(o =>
// o.MACHINECODDE == m.MACHINECODDE
// && o.MOLDNUMBER == m.MOLDNUMBER
// && (
// o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString()
// || o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.TEMPCOMPLETE.GetHashCode().ToString()
// || o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.MOULDNUMBER.GetHashCode().ToString()
// || o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.EQUIPSCANFLAG.GetHashCode().ToString()
// )
// )
// .ToList<ParameterConfig>();
//20211222DQZhang补充监控地址点
//获取设备扫描条码完成标记和设备加工完成标记
List<ParameterConfig> monitorList = paraConfigList
.Where(o =>
@ -373,7 +389,10 @@ namespace OpcServerHost.Init
&& (
o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.TEMPCOMPLETE.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.MOULDCARRIER.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.MOULDNUMBER.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEMOULD.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.OPERATINGMOULD.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.EQUIPSCANFLAG.GetHashCode().ToString()
)
)
@ -402,13 +421,13 @@ namespace OpcServerHost.Init
{
clientHandleDict.Add(clientHandleValue, dicKeyStr);
//将字典中的与PLC内存地址向绑定
parameterValueDict[dicKeyStr] = MonitorConnection.AddKepItem(itemName, clientHandleValue);
parameterValueDict[dicKeyStr] = MonitorConnection.AddKepItem2(itemName, clientHandleValue);
}
catch (Exception ex)
{
Console.WriteLine("重复:" + dicKeyStr);
Console.WriteLine("监控-重复:" + dicKeyStr);
}
@ -483,212 +502,275 @@ namespace OpcServerHost.Init
#region 捕获完成标记
if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString())
{
//if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString())
//{
if (itemValue == null)
{
// if (itemValue == null)
// {
continue;
}
//如果完成标记表示更新了加工参数
//获取所有的加工参数
if ((Boolean)itemValue == true)
{
//设置延迟2秒
//因为plc刷新频率
//个别情况获取不到值可以适当的延长等待时间
// continue;
// }
// //如果完成标记表示更新了加工参数
// //获取所有的加工参数
// if ((Boolean)itemValue == true)
// {
// //设置延迟2秒
// //因为plc刷新频率
// //个别情况获取不到值可以适当的延长等待时间
Thread.Sleep(2000);
// Thread.Sleep(2000);
Console.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Catch Finish Flag " + currentPC.MACHINECODDE + ":" + currentPC.MOLDNUMBER + ":" + currentPC.COLUMNCODE);
WriteLog.Write(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Catch Finish Flag " + currentPC.COLUMNCODE, currentPC.MACHINECODDE);
// Console.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Catch Finish Flag " + currentPC.MACHINECODDE + ":" + currentPC.MOLDNUMBER + ":" + currentPC.COLUMNCODE);
// WriteLog.Write(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Catch Finish Flag " + currentPC.COLUMNCODE, currentPC.MACHINECODDE);
List<ParameterConfig> resultList = new List<ParameterConfig>();
// List<ParameterConfig> resultList = new List<ParameterConfig>();
#region 获取该模块下的加工参数
// #region 获取该模块下的加工参数
List<ParameterConfig> getParaList = new List<ParameterConfig>();
// List<ParameterConfig> getParaList = new List<ParameterConfig>();
//获取加工参数和公用参数
List<ParameterConfig> paraList = paraConfigList
.Where(o =>
o.MACHINECODDE == machCode
&& o.MOLDNUMBER == moldNumber
&&
(
o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETER.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.TEMPVALUE.GetHashCode().ToString()
)
)
.ToList<ParameterConfig>();
// //获取加工参数和公用参数
// List<ParameterConfig> paraList = paraConfigList
// .Where(o =>
// o.MACHINECODDE == machCode
// && o.MOLDNUMBER == moldNumber
// &&
// (
// o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETER.GetHashCode().ToString()
// || o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.TEMPVALUE.GetHashCode().ToString()
// )
// )
// .ToList<ParameterConfig>();
//获取所有的加工参数
foreach (var parameter in paraList)
{
//临时存储值不获取值
if (parameter.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.TEMPVALUE.GetHashCode().ToString())
{
ParameterConfig paraConfig = GetResultParameterConfig(parameter);
paraConfig.PARAVALUE = parameter.PARAVALUE;
resultList.Add(paraConfig);
Console.WriteLine(paraConfig.MACHINECODDE + ":" + paraConfig.MOLDNUMBER + ":" + paraConfig.COLUMNCODE + " " + ((paraConfig.PARAVALUE == null) ? " " : paraConfig.PARAVALUE.ToString()));
WriteLog.Write(paraConfig.COLUMNCODE + " " + ((paraConfig.PARAVALUE == null) ? " " : paraConfig.PARAVALUE.ToString()), paraConfig.MACHINECODDE);
// //获取所有的加工参数
// foreach (var parameter in paraList)
// {
// //临时存储值不获取值
// if (parameter.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.TEMPVALUE.GetHashCode().ToString())
// {
// ParameterConfig paraConfig = GetResultParameterConfig(parameter);
// paraConfig.PARAVALUE = parameter.PARAVALUE;
// resultList.Add(paraConfig);
// Console.WriteLine(paraConfig.MACHINECODDE + ":" + paraConfig.MOLDNUMBER + ":" + paraConfig.COLUMNCODE + " " + ((paraConfig.PARAVALUE == null) ? " " : paraConfig.PARAVALUE.ToString()));
// WriteLog.Write(paraConfig.COLUMNCODE + " " + ((paraConfig.PARAVALUE == null) ? " " : paraConfig.PARAVALUE.ToString()), paraConfig.MACHINECODDE);
continue;
}
// continue;
// }
try
{
#region 获取参数
// try
// {
// #region 获取参数
ParameterConfig paraConfig = GetResultParameterConfig(parameter);
// ParameterConfig paraConfig = GetResultParameterConfig(parameter);
var result = new object();
// var result = new object();
try
{
string item = parameter.MACHINECODDE + ":" + parameter.MOLDNUMBER + ":" + parameter.COLUMNCODE;
int indexValue = parameterValueDict[item];
OPCPLCAutomation m = opcDict[currentPC.MACHINECODDE];
result = m.ReadtagValue(opcItemDict[item]);
}
catch (Exception ex)
{
// try
// {
// string item = parameter.MACHINECODDE + ":" + parameter.MOLDNUMBER + ":" + parameter.COLUMNCODE;
// int indexValue = parameterValueDict[item];
// OPCPLCAutomation m = opcDict[currentPC.MACHINECODDE];
// result = m.ReadtagValue(opcItemDict[item]);
// }
// catch (Exception ex)
// {
Console.WriteLine(paraConfig.COLUMNCODE + ":" + ex.Message);
WriteLog.Write(paraConfig.COLUMNCODE + ":" + ex.Message, currentPC.MACHINECODDE);
}
// Console.WriteLine(paraConfig.COLUMNCODE + ":" + ex.Message);
// WriteLog.Write(paraConfig.COLUMNCODE + ":" + ex.Message, currentPC.MACHINECODDE);
// }
if (result != null)
{
paraConfig.PARAVALUE = result;
Console.WriteLine(paraConfig.MACHINECODDE + ":" + paraConfig.MOLDNUMBER + ":" + paraConfig.COLUMNCODE + " " + ((result == null) ? " " : result.ToString()));
WriteLog.Write(paraConfig.COLUMNCODE + " " + ((result == null) ? " " : result.ToString()), paraConfig.MACHINECODDE);
// if (result != null)
// {
// paraConfig.PARAVALUE = result;
// Console.WriteLine(paraConfig.MACHINECODDE + ":" + paraConfig.MOLDNUMBER + ":" + paraConfig.COLUMNCODE + " " + ((result == null) ? " " : result.ToString()));
// WriteLog.Write(paraConfig.COLUMNCODE + " " + ((result == null) ? " " : result.ToString()), paraConfig.MACHINECODDE);
}
// }
// resultList.Add(paraConfig);
// #endregion
// }
// catch (Exception ex)
// {
// continue;
// }
// }
// #endregion
// #region 处理已经读取完加工参数标记
// //目前主要针对浇注设备
// //浇注设备读取完加工参数后要将加工参数读取完成标记位修改为true
// if (paraConfigList.Count(o => o.MACHINECODDE == currentPC.MACHINECODDE
// && o.MOLDNUMBER == currentPC.MOLDNUMBER && o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString()
// ) > 0)
// {
// List<ParameterConfig> collectedList = paraConfigList.Where(o =>
// o.MACHINECODDE == currentPC.MACHINECODDE
// && o.MOLDNUMBER == currentPC.MOLDNUMBER
// && o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString())
// .ToList<ParameterConfig>();
// opcplcConnection.KepGroup = opcplcConnection.KepGroups.GetOPCGroup(collectedList[0].MACHINECODDE + ":" + collectedList[0].MOLDNUMBER.ToString() + ":WriteData");
// opcplcConnection.KepItems = opcplcConnection.KepGroup.OPCItems;
// foreach (var p in collectedList)
// {
// //获取对应的OPC操作对象
// //获取对应的服务端句柄
// //向服务端句柄写入
// opcplcConnection.WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], true);
// Console.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Set Collected true" + p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE);
// WriteLog.Write(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Set Collected true " + p.COLUMNCODE, p.MACHINECODDE);
// }
// }
// #endregion
// #region 将参数信息传递到web服务中
// client.SubmitParameters(JsonConvertHelper.GetSerializes(resultList));
// #endregion
// #region 加工步骤返回工控机信息
// Thread.Sleep(2000);
// //该处需要例外处理一下
// //浇注设备浇注完成后记录先输出浇注机的加工参数
// //模架浇注完成后再输出模架的加工参数
// //浇注的实际参数是浇注加+浇注模架参数的合集
// //Q5的浇注模架和浇注机不是同一个厂家,交互起来麻烦
// //所以先返回浇注机参数,将参数暂存,再获取浇注模架参数进行合并
// //浇注机的浇注完成的参数名称是PouringFinish
// //定义参数信息
// ChatEventArgs e = new ChatEventArgs();
// //设备编号
// e.MachineCode = machCode;
// //传输参数的类别
// e.MessageType = OpcEnumGeter.MESSAGETYPE.PROCESSFINISH.GetHashCode().ToString();
// //传输参数的内容
// e.MessageContent = resultList[0].MOLDNUMBER;
// OpcService opcService = new OpcService();
// opcService.ReturnProductCodeToMachine(e);
// //异步调用服务
// #endregion
// }
// else
// {
// #region 冷刀设备的处理
// if (currentPC.MACHINECODDE == "D3599-132")
// {
resultList.Add(paraConfig);
// //获取对应的OPC操作对象
// opcplcConnection.KepGroup = opcplcConnection.KepGroups.GetOPCGroup(
// currentPC.MACHINECODDE + ":" + currentPC.MOLDNUMBER + ":WriteData"
// );
// opcplcConnection.KepItems = opcplcConnection.KepGroup.OPCItems;
// List<ParameterConfig> paraReadList = paraConfigList
// .Where(o =>
// o.MACHINECODDE == machCode
// && o.MOLDNUMBER == moldNumber
// && (
// o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString()
// || o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.OPERATEFLAG.GetHashCode().ToString()
// )
// )
// .ToList<ParameterConfig>();
// foreach (var p in paraReadList)
// {
// Console.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Get Finish false, set false " + p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE);
// WriteLog.Write(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Get Finish false, set false " + p.COLUMNCODE, p.MACHINECODDE);
// opcplcConnection.WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], false);
// }
// }
// #endregion
// }
//}
#endregion
}
catch (Exception ex)
//20211222DQZhang
#region 捕获完成标记
if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString())
{
if (itemValue == null)
{
continue;
}
}
#endregion
#region 处理已经读取完加工参数标记
//目前主要针对浇注设备
//浇注设备读取完加工参数后要将加工参数读取完成标记位修改为true
if (paraConfigList.Count(o => o.MACHINECODDE == currentPC.MACHINECODDE
&& o.MOLDNUMBER == currentPC.MOLDNUMBER && o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString()
) > 0)
if ((bool)itemValue)
{
List<ParameterConfig> collectedList = paraConfigList.Where(o =>
o.MACHINECODDE == currentPC.MACHINECODDE
&& o.MOLDNUMBER == currentPC.MOLDNUMBER
&& o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString())
.ToList<ParameterConfig>();
opcplcConnection.KepGroup = opcplcConnection.KepGroups.GetOPCGroup(collectedList[0].MACHINECODDE + ":" + collectedList[0].MOLDNUMBER.ToString() + ":WriteData");
opcplcConnection.KepItems = opcplcConnection.KepGroup.OPCItems;
foreach (var p in collectedList)
if (!string.IsNullOrEmpty(currentPC.DBNUMBER))
{
//获取对应的OPC操作对象
//获取对应的服务端句柄
//向服务端句柄写入
opcplcConnection.WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], true);
Console.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Set Collected true" + p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE);
WriteLog.Write(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Set Collected true " + p.COLUMNCODE, p.MACHINECODDE);
if (!ChatEventHelper.machinegroups.ContainsKey(currentPC.DBNUMBER))
{
continue;
}
if (!string.Equals(currentPC.MACHINECODDE, ChatEventHelper.machinegroups[currentPC.DBNUMBER]))
{
continue;
}
#endregion
#region 将参数信息传递到web服务中
client.SubmitParameters(JsonConvertHelper.GetSerializes(resultList));
#endregion
#region 加工步骤返回工控机信息
Thread.Sleep(2000);
//该处需要例外处理一下
//浇注设备浇注完成后记录先输出浇注机的加工参数
//模架浇注完成后再输出模架的加工参数
//浇注的实际参数是浇注加+浇注模架参数的合集
//Q5的浇注模架和浇注机不是同一个厂家,交互起来麻烦
//所以先返回浇注机参数,将参数暂存,再获取浇注模架参数进行合并
//浇注机的浇注完成的参数名称是PouringFinish
//定义参数信息
ChatEventArgs e = new ChatEventArgs();
//设备编号
e.MachineCode = machCode;
//传输参数的类别
e.MessageType = OpcEnumGeter.MESSAGETYPE.PROCESSFINISH.GetHashCode().ToString();
//传输参数的内容
e.MessageContent = resultList[0].MOLDNUMBER;
OpcService opcService = new OpcService();
opcService.ReturnProductCodeToMachine(e);
//异步调用服务
#endregion
}
else
ChatEventArgs chatEventArgs = new ChatEventArgs();
chatEventArgs.MachineCode = machCode;
chatEventArgs.MessageType = OpcEnumGeter.MESSAGETYPE.PROCESSFINISH.GetHashCode().ToString();
chatEventArgs.MessageContent = moldNumber;
if (moldNumber.EndsWith("?"))
{
#region 冷刀设备的处理
if (currentPC.MACHINECODDE == "D3599-132")
IEnumerable<ParameterConfig> enumerable = from p in ParaInit.paraConfigList
where p.MACHINECODDE == machCode && p.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEMOULD.GetHashCode().ToString() && p.MOLDNUMBER.StartsWith(moldNumber.TrimEnd(new char[]
{ '?' }))
select p;
foreach (ParameterConfig parameterConfig in enumerable)
{
//获取对应的OPC操作对象
opcplcConnection.KepGroup = opcplcConnection.KepGroups.GetOPCGroup(
currentPC.MACHINECODDE + ":" + currentPC.MOLDNUMBER + ":WriteData"
);
opcplcConnection.KepItems = opcplcConnection.KepGroup.OPCItems;
List<ParameterConfig> paraReadList = paraConfigList
.Where(o =>
o.MACHINECODDE == machCode
&& o.MOLDNUMBER == moldNumber
&& (
o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.OPERATEFLAG.GetHashCode().ToString()
)
)
.ToList<ParameterConfig>();
foreach (var p in paraReadList)
string key2 = string.Concat(new string[]
{
Console.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Get Finish false, set false " + p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE);
WriteLog.Write(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Get Finish false, set false " + p.COLUMNCODE, p.MACHINECODDE);
parameterConfig.MACHINECODDE,
":",
parameterConfig.MOLDNUMBER,
":",
parameterConfig.COLUMNCODE
});
int num = Convert.ToInt32(MonitorConnection.ReadtagValue(parameterValueDict[key2]));
opcplcConnection.WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], false);
if (num == 1)
{
moldNumber = parameterConfig.MOLDNUMBER;
break;
}
}
#endregion
}
chatEventArgs.MessageContent = moldNumber;
OpcService opcService = new OpcService();
opcService.ReturnProductCodeToMachine(chatEventArgs);
Action action = delegate ()
{
ParaInit.ReadParameters(machCode, moldNumber, currentPC);
};
action.BeginInvoke(null, null);
}
}
#endregion
#endregion
#region 捕获条码扫描完成标记
if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.EQUIPSCANFLAG.GetHashCode().ToString())
@ -746,8 +828,9 @@ namespace OpcServerHost.Init
{
ASCIIEncoding asciiEncoding = new ASCIIEncoding();
var arraysList = (object[])result;
//var arraysList1 = (string[])result;
//var arraysList = (object[])result;
var arraysList = (short[])result;
var count = Convert.ToInt32(arraysList[1]) - 1;
//var count1 = Convert.ToInt32(arraysList1[1]) - 1;
@ -996,31 +1079,82 @@ namespace OpcServerHost.Init
//20171129闫永刚增加对模具号的监控
#region 获取模架号的监控
//if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.MOULDNUMBER.GetHashCode().ToString())
//{
// if (itemValue == null)
// {
// continue;
// }
// Console.WriteLine(itemValue.ToString());
// ChatEventArgs e = new ChatEventArgs();
// //设备编号
// e.MachineCode = machCode;
// //传输参数的类别
// e.MessageType = OpcEnumGeter.MESSAGETYPE.MOULDNUMBER.GetHashCode().ToString();
// //传输参数的内容
// e.MessageContent = itemValue.ToString();
// OpcService opcService = new OpcService();
// opcService.ReturnProductCodeToMachine(e);
// //异步调用服务
//}
#endregion
//20211222DQZhang 补充对模具号的监控
#region 获取模架号的监控
//模架搬运
if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.MOULDCARRIER.GetHashCode().ToString())
{
if (itemValue == null)
{
continue;
}
Console.WriteLine(itemValue.ToString());
ChatEventArgs chatEventArgs = new ChatEventArgs();
chatEventArgs.MachineCode = machCode;
chatEventArgs.MessageType = OpcEnumGeter.MESSAGETYPE.MOULDCARRIER.GetHashCode().ToString();
chatEventArgs.MessageContent = itemValue.ToString();
OpcService opcService = new OpcService();
opcService.ReturnProductCodeToMachine(chatEventArgs);
}
//模架号
if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.MOULDNUMBER.GetHashCode().ToString())
{
if (itemValue == null)
{
continue;
}
Console.WriteLine(itemValue.ToString());
ChatEventArgs e = new ChatEventArgs();
//设备编号
e.MachineCode = machCode;
//传输参数的类别
e.MessageType = OpcEnumGeter.MESSAGETYPE.MOULDNUMBER.GetHashCode().ToString();
//传输参数的内容
e.MessageContent = itemValue.ToString();
ChatEventArgs chatEventArgs = new ChatEventArgs();
chatEventArgs.MachineCode = machCode;
chatEventArgs.MessageType = OpcEnumGeter.MESSAGETYPE.MOULDNUMBER.GetHashCode().ToString();
chatEventArgs.MessageContent = string.Format("{0}:{1}:{2}", currentPC.MOLDNUMBER, currentPC.COLUMNCODE, itemValue.ToString());
OpcService opcService = new OpcService();
opcService.ReturnProductCodeToMachine(e);
//异步调用服务
opcService.ReturnProductCodeToMachine(chatEventArgs);
}
//操作模架
if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.OPERATINGMOULD.GetHashCode().ToString())
{
if (itemValue == null)
{
continue;
}
Console.WriteLine(itemValue.ToString());
ChatEventArgs chatEventArgs = new ChatEventArgs();
chatEventArgs.MachineCode = machCode;
chatEventArgs.MessageType = OpcEnumGeter.MESSAGETYPE.OTHER.GetHashCode().ToString();
chatEventArgs.MessageContent = string.Format("{0}_{1}:{2}", currentPC.MOLDNUMBER, currentPC.COLUMNCODE, itemValue.ToString());
OpcService opcService = new OpcService();
opcService.ReturnProductCodeToMachine(chatEventArgs);
}
#endregion
GC.Collect();
}
@ -1038,6 +1172,104 @@ namespace OpcServerHost.Init
}
private static void ReadParameters(string machCode, string moldNumber, ParameterConfig currentPC)
{
Thread.Sleep(1000);
List<ParameterConfig> list = new List<ParameterConfig>();
List<ParameterConfig> list2 = new List<ParameterConfig>();
List<ParameterConfig> list3 = (from o in ParaInit.paraConfigList
where o.MACHINECODDE == machCode && o.MOLDNUMBER == moldNumber && (o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETER.GetHashCode().ToString() || o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.TEMPVALUE.GetHashCode().ToString())
select o).ToList<ParameterConfig>();
foreach (ParameterConfig parameterConfig in list3)
{
if (parameterConfig.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.TEMPVALUE.GetHashCode().ToString())
{
ParameterConfig resultParameterConfig = ParaInit.GetResultParameterConfig(parameterConfig);
resultParameterConfig.PARAVALUE = parameterConfig.PARAVALUE;
list.Add(resultParameterConfig);
Console.WriteLine(string.Concat(new string[]{
resultParameterConfig.MACHINECODDE,
":",
resultParameterConfig.MOLDNUMBER,
":",
resultParameterConfig.COLUMNCODE,
" ",
(resultParameterConfig.PARAVALUE == null) ? " " : resultParameterConfig.PARAVALUE.ToString()
}));
WriteLog.Write(resultParameterConfig.COLUMNCODE + " " + ((resultParameterConfig.PARAVALUE == null) ? " " : resultParameterConfig.PARAVALUE.ToString()), resultParameterConfig.MACHINECODDE);
}
else
{
try
{
ParameterConfig resultParameterConfig = ParaInit.GetResultParameterConfig(parameterConfig);
object obj = new object();
try
{
string key = string.Concat(new string[]
{
parameterConfig.MACHINECODDE,
":",
parameterConfig.MOLDNUMBER,
":",
parameterConfig.COLUMNCODE
});
OPCPLCAutomation opcplcautomation = ParaInit.opcDict[currentPC.MACHINECODDE];
obj = opcplcautomation.ReadtagValue(ParaInit.opcItemDict[key]);
}
catch (Exception ex)
{
Console.WriteLine(resultParameterConfig.COLUMNCODE + ":" + ex.Message);
WriteLog.Write(resultParameterConfig.COLUMNCODE + ":" + ex.Message, currentPC.MACHINECODDE);
}
if (obj != null)
{
resultParameterConfig.PARAVALUE = obj;
Console.WriteLine(string.Concat(new string[]
{
resultParameterConfig.MACHINECODDE,
":",
resultParameterConfig.MOLDNUMBER,
":",
resultParameterConfig.COLUMNCODE,
" ",
(obj == null) ? " " : obj.ToString()
}));
WriteLog.Write(resultParameterConfig.COLUMNCODE + " " + ((obj == null) ? " " : obj.ToString()), resultParameterConfig.MACHINECODDE);
}
list.Add(resultParameterConfig);
}
catch (Exception ex)
{
}
}
}
if (ParaInit.paraConfigList.Count((ParameterConfig o) => o.MACHINECODDE == currentPC.MACHINECODDE && o.MOLDNUMBER == moldNumber && o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString()) > 0)
{
List<ParameterConfig> list4 = (from o in ParaInit.paraConfigList
where o.MACHINECODDE == currentPC.MACHINECODDE && o.MOLDNUMBER == moldNumber && o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString()
select o).ToList<ParameterConfig>();
ParaInit.opcplcConnection.KepGroup = ParaInit.opcplcConnection.GroupLists[list4[0].MACHINECODDE + ":" + list4[0].MOLDNUMBER.ToString() + ":WriteData"];
ParaInit.opcplcConnection.KepItems = ParaInit.opcplcConnection.KepGroup.OPCItems;
foreach (ParameterConfig parameterConfig2 in list4)
{
ParaInit.opcplcConnection.WritetagValue1(ParaInit.opcItemDict[string.Concat(new string[] { parameterConfig2.MACHINECODDE, ":", parameterConfig2.MOLDNUMBER, ":", parameterConfig2.COLUMNCODE })], true);
Console.WriteLine(string.Concat(new string[]
{
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
" Set Collected true",
parameterConfig2.MACHINECODDE,
":",
parameterConfig2.MOLDNUMBER,
":",
parameterConfig2.COLUMNCODE
}));
WriteLog.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Set Collected true " + parameterConfig2.COLUMNCODE, parameterConfig2.MACHINECODDE);
}
}
ParaInit.client.SubmitParameters(JsonConvertHelper.GetSerializes(list));
}
/// <summary>
/// 向设备发送可以操作的指令信息
/// </summary>

Loading…
Cancel
Save