Browse Source

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

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

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

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

3
ServicesCenter/WCF/OpcServerHost/App.config

@ -10,7 +10,8 @@
</appSettings> </appSettings>
<connectionStrings> <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> </connectionStrings>
<system.serviceModel> <system.serviceModel>
<client> <client>

1
ServicesCenter/WCF/OpcServerHost/ChatEventHelper.cs

@ -19,6 +19,7 @@ namespace OpcServerHost
//创建一个静态Dictionary存储设备的最新更新时间 //创建一个静态Dictionary存储设备的最新更新时间
public static Dictionary<string, DateTime> chatterTimes = new Dictionary<string, DateTime>(); 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; public static System.Timers.Timer dutyTimer;

51
ServicesCenter/WCF/OpcServerHost/OPCPLCAutomation.cs

@ -41,6 +41,8 @@ namespace OPCPLC
/// </summary> /// </summary>
public Dictionary<string, int> dirHandleServer = new Dictionary<string, int>(); public Dictionary<string, int> dirHandleServer = new Dictionary<string, int>();
public Dictionary<string, OPCGroup> GroupLists = new Dictionary<string, OPCGroup>();
/// <summary> /// <summary>
/// 枚举本地OPC服务器 /// 枚举本地OPC服务器
/// </summary> /// </summary>
@ -199,13 +201,25 @@ namespace OPCPLC
return KepItem.ServerHandle; 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) public OPCItem AddKepOPCItem(string itemname, int clientHandleValue)
{ {
KepItem = KepGroup.OPCItems.AddItem(itemname, clientHandleValue); KepItem = KepGroup.OPCItems.AddItem(itemname, clientHandleValue);
dirHandleServer.Add(itemname, KepItem.ServerHandle); dirHandleServer.Add(itemname, KepItem.ServerHandle);
return KepItem; return KepItem;
} }
public OPCItem AddKepOPCItem2(string itemname, int clientHandleValue)
{
KepItem = KepGroup.OPCItems.AddItem(itemname, clientHandleValue);
return KepItem;
}
/// <summary> /// <summary>
/// 向OPC中添加连续添加多个地址项 /// 向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>
/// 释放资源处理的事情 /// 释放资源处理的事情
/// </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>
/// 向指定的地址项写入指定的值,不触发订阅 /// 向指定的地址项写入指定的值,不触发订阅
/// </summary> /// </summary>

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

@ -71,7 +71,27 @@ namespace OpcServerHost.Common
/// <summary> /// <summary>
/// 模架号 /// 模架号
/// </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>
/// 中断信号 /// 中断信号
/// </summary> /// </summary>
MOULDNUMBER MOULDCARRIER,
/// <summary>
/// 中断信号
/// </summary>
MOULDNUMBER,
/// <summary>
/// 其他信号
/// </summary>
OTHER
} }
public enum SENDORDERTYPE public enum SENDORDERTYPE

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

@ -38,6 +38,7 @@ namespace OpcServerHost.Init
public static Dictionary<string, OPCItem> opcItemDict = new Dictionary<string, OPCItem>(); public static Dictionary<string, OPCItem> opcItemDict = new Dictionary<string, OPCItem>();
/// <summary> /// <summary>
/// 用来存储客户端句柄与设备参数对应关系 /// 用来存储客户端句柄与设备参数对应关系
/// key:客户端句柄值 /// key:客户端句柄值
@ -172,7 +173,7 @@ namespace OpcServerHost.Init
#endregion #endregion
#region 加载模块下的加工参数配置信息 #region 加载模块下的加工参数配置信息
//变量所有的模具信息 //变量所有的模具信息
foreach (var m in moldList) foreach (var m in moldList)
{ {
@ -228,7 +229,7 @@ namespace OpcServerHost.Init
clientHandleDict.Add(clientHandleValue, dicKeyStr); clientHandleDict.Add(clientHandleValue, dicKeyStr);
//将字典中的与PLC内存地址向绑定 //将字典中的与PLC内存地址向绑定
//parameterValueDict[dicKeyStr] = opcDict[m.MACHINECODDE].AddKepItem(itemName, clientHandleValue); //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; parameterValueDict[dicKeyStr] = opcItemDict[dicKeyStr].ServerHandle;
} }
catch (Exception ex) catch (Exception ex)
@ -236,9 +237,9 @@ namespace OpcServerHost.Init
Console.WriteLine("clientHandleDict重复:" + dicKeyStr); Console.WriteLine("clientHandleDict重复:" + dicKeyStr);
} }
}
}
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
@ -250,6 +251,7 @@ namespace OpcServerHost.Init
int i = 1; int i = 1;
} }
#endregion #endregion
#region 写入组 #region 写入组
@ -291,13 +293,13 @@ namespace OpcServerHost.Init
{ {
clientHandleDict.Add(clientHandleValue, dicKeyStr); clientHandleDict.Add(clientHandleValue, dicKeyStr);
//将字典中的与PLC内存地址向绑定 //将字典中的与PLC内存地址向绑定
parameterValueDict[dicKeyStr] = opcplcConnection.AddKepItem(itemName, clientHandleValue); parameterValueDict[dicKeyStr] = opcplcConnection.AddKepItem2(itemName, clientHandleValue);
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine("重复:" + dicKeyStr); Console.WriteLine("允许加工-重复:" + dicKeyStr);
} }
WriteLog.Write(dicKeyStr + " | " + itemName + " | " + clientHandleValue + " | " + parameterValueDict[dicKeyStr]); WriteLog.Write(dicKeyStr + " | " + itemName + " | " + clientHandleValue + " | " + parameterValueDict[dicKeyStr]);
} }
@ -365,6 +367,20 @@ namespace OpcServerHost.Init
#region 监控组 #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 List<ParameterConfig> monitorList = paraConfigList
.Where(o => .Where(o =>
@ -373,7 +389,10 @@ namespace OpcServerHost.Init
&& ( && (
o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString() o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.TEMPCOMPLETE.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.MOULDNUMBER.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEMOULD.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.OPERATINGMOULD.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.EQUIPSCANFLAG.GetHashCode().ToString() || o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.EQUIPSCANFLAG.GetHashCode().ToString()
) )
) )
@ -402,13 +421,13 @@ namespace OpcServerHost.Init
{ {
clientHandleDict.Add(clientHandleValue, dicKeyStr); clientHandleDict.Add(clientHandleValue, dicKeyStr);
//将字典中的与PLC内存地址向绑定 //将字典中的与PLC内存地址向绑定
parameterValueDict[dicKeyStr] = MonitorConnection.AddKepItem(itemName, clientHandleValue); parameterValueDict[dicKeyStr] = MonitorConnection.AddKepItem2(itemName, clientHandleValue);
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine("重复:" + dicKeyStr); Console.WriteLine("监控-重复:" + dicKeyStr);
} }
@ -483,212 +502,275 @@ namespace OpcServerHost.Init
#region 捕获完成标记 #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刷新频率
// //个别情况获取不到值可以适当的延长等待时间
// Thread.Sleep(2000);
continue; // 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);
//如果完成标记表示更新了加工参数
//获取所有的加工参数
if ((Boolean)itemValue == true) // List<ParameterConfig> resultList = new List<ParameterConfig>();
{
//设置延迟2秒 // #region 获取该模块下的加工参数
//因为plc刷新频率
//个别情况获取不到值可以适当的延长等待时间 // 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>();
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); // 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;
// }
// try
// {
// #region 获取参数
// ParameterConfig paraConfig = GetResultParameterConfig(parameter);
// 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)
// {
List<ParameterConfig> resultList = new List<ParameterConfig>(); // 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);
// }
// 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")
// {
#region 获取该模块下的加工参数 // //获取对应的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);
List<ParameterConfig> getParaList = new List<ParameterConfig>(); // opcplcConnection.WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], false);
// }
//获取加工参数和公用参数 // }
List<ParameterConfig> paraList = paraConfigList
.Where(o => // #endregion
o.MACHINECODDE == machCode // }
&& o.MOLDNUMBER == moldNumber //}
&&
(
o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETER.GetHashCode().ToString()
|| o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.TEMPVALUE.GetHashCode().ToString()
)
)
.ToList<ParameterConfig>();
#endregion
//获取所有的加工参数 //20211222DQZhang
foreach (var parameter in paraList) #region 捕获完成标记
if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString())
{
if (itemValue == null)
{
continue;
}
if ((bool)itemValue)
{
if (!string.IsNullOrEmpty(currentPC.DBNUMBER))
{ {
//临时存储值不获取值 if (!ChatEventHelper.machinegroups.ContainsKey(currentPC.DBNUMBER))
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;
} }
if (!string.Equals(currentPC.MACHINECODDE, ChatEventHelper.machinegroups[currentPC.DBNUMBER]))
try
{
#region 获取参数
ParameterConfig paraConfig = GetResultParameterConfig(parameter);
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)
{
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);
}
resultList.Add(paraConfig);
#endregion
}
catch (Exception ex)
{ {
continue; continue;
} }
} }
ChatEventArgs chatEventArgs = new ChatEventArgs();
#endregion chatEventArgs.MachineCode = machCode;
chatEventArgs.MessageType = OpcEnumGeter.MESSAGETYPE.PROCESSFINISH.GetHashCode().ToString();
#region 处理已经读取完加工参数标记 chatEventArgs.MessageContent = moldNumber;
if (moldNumber.EndsWith("?"))
//目前主要针对浇注设备
//浇注设备读取完加工参数后要将加工参数读取完成标记位修改为true
if (paraConfigList.Count(o => o.MACHINECODDE == currentPC.MACHINECODDE
&& o.MOLDNUMBER == currentPC.MOLDNUMBER && o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString()
) > 0)
{ {
IEnumerable<ParameterConfig> enumerable = from p in ParaInit.paraConfigList
List<ParameterConfig> collectedList = paraConfigList.Where(o => where p.MACHINECODDE == machCode && p.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEMOULD.GetHashCode().ToString() && p.MOLDNUMBER.StartsWith(moldNumber.TrimEnd(new char[]
o.MACHINECODDE == currentPC.MACHINECODDE { '?' }))
&& o.MOLDNUMBER == currentPC.MOLDNUMBER select p;
&& o.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.PARAMETERREADED.GetHashCode().ToString()) foreach (ParameterConfig parameterConfig in enumerable)
.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操作对象 string key2 = string.Concat(new string[]
//获取对应的服务端句柄 {
//向服务端句柄写入 parameterConfig.MACHINECODDE,
opcplcConnection.WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], true); ":",
parameterConfig.MOLDNUMBER,
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); parameterConfig.COLUMNCODE
});
int num = Convert.ToInt32(MonitorConnection.ReadtagValue(parameterValueDict[key2]));
if (num == 1)
{
moldNumber = parameterConfig.MOLDNUMBER;
break;
}
} }
} }
chatEventArgs.MessageContent = moldNumber;
#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 opcService = new OpcService();
opcService.ReturnProductCodeToMachine(e); opcService.ReturnProductCodeToMachine(chatEventArgs);
//异步调用服务 Action action = delegate ()
#endregion
}
else
{
#region 冷刀设备的处理
if (currentPC.MACHINECODDE == "D3599-132")
{ {
ParaInit.ReadParameters(machCode, moldNumber, currentPC);
//获取对应的OPC操作对象 };
opcplcConnection.KepGroup = opcplcConnection.KepGroups.GetOPCGroup( action.BeginInvoke(null, null);
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
#endregion
#region 捕获条码扫描完成标记 #region 捕获条码扫描完成标记
if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.EQUIPSCANFLAG.GetHashCode().ToString()) if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.EQUIPSCANFLAG.GetHashCode().ToString())
@ -745,9 +827,10 @@ namespace OpcServerHost.Init
if (result != null) if (result != null)
{ {
ASCIIEncoding asciiEncoding = new ASCIIEncoding(); ASCIIEncoding asciiEncoding = new ASCIIEncoding();
var arraysList = (object[])result; //var arraysList = (object[])result;
//var arraysList1 = (string[])result;
var arraysList = (short[])result;
var count = Convert.ToInt32(arraysList[1]) - 1; var count = Convert.ToInt32(arraysList[1]) - 1;
//var count1 = Convert.ToInt32(arraysList1[1]) - 1; //var count1 = Convert.ToInt32(arraysList1[1]) - 1;
@ -996,31 +1079,82 @@ namespace OpcServerHost.Init
//20171129闫永刚增加对模具号的监控 //20171129闫永刚增加对模具号的监控
#region 获取模架号的监控 #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 (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.MOULDNUMBER.GetHashCode().ToString())
{ {
if (itemValue == null) if (itemValue == null)
{ {
continue; continue;
} }
Console.WriteLine(itemValue.ToString()); Console.WriteLine(itemValue.ToString());
ChatEventArgs chatEventArgs = new ChatEventArgs();
ChatEventArgs e = new ChatEventArgs(); chatEventArgs.MachineCode = machCode;
//设备编号 chatEventArgs.MessageType = OpcEnumGeter.MESSAGETYPE.MOULDNUMBER.GetHashCode().ToString();
e.MachineCode = machCode; chatEventArgs.MessageContent = string.Format("{0}:{1}:{2}", currentPC.MOLDNUMBER, currentPC.COLUMNCODE, itemValue.ToString());
//传输参数的类别
e.MessageType = OpcEnumGeter.MESSAGETYPE.MOULDNUMBER.GetHashCode().ToString();
//传输参数的内容
e.MessageContent = itemValue.ToString();
OpcService opcService = new OpcService(); 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 #endregion
GC.Collect(); 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>
/// 向设备发送可以操作的指令信息 /// 向设备发送可以操作的指令信息
/// </summary> /// </summary>

Loading…
Cancel
Save