@ -38,6 +38,7 @@ namespace OpcServerHost.Init
public static Dictionary < string , OPCItem > opcItemDict = new Dictionary < string , OPCItem > ( ) ;
/// <summary>
/// 用来存储客户端句柄与设备参数对应关系
/// key:客户端句柄值
@ -172,7 +173,7 @@ namespace OpcServerHost.Init
#endregion
#region 加载模块下的加工参数配置信息
//变量所有的模具信息
foreach ( var m in moldList )
{
@ -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 )
@ -236,9 +237,9 @@ namespace OpcServerHost.Init
Console . WriteLine ( "clientHandleDict重复:" + dicKeyStr ) ;
}
}
}
catch ( Exception ex )
{
Console . WriteLine ( ex . Message ) ;
@ -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 ( itemValue = = null )
{
//if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString())
//{
// if (itemValue == null)
// {
// continue;
// }
// //如果完成标记表示更新了加工参数
// //获取所有的加工参数
// if ((Boolean)itemValue == true)
// {
// //设置延迟2秒
// //因为plc刷新频率
// //个别情况获取不到值可以适当的延长等待时间
// Thread.Sleep(2000);
continue ;
}
//如果完成标记表示更新了加工参数
//获取所有的加工参数
if ( ( Boolean ) itemValue = = true )
{
//设置延迟2秒
//因为plc刷新频率
//个别情况获取不到值可以适当的延长等待时间
// 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>();
// #region 获取该模块下的加工参数
// 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 ( 2 0 0 0 ) ;
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 > ( ) ;
//获取加工参数和公用参数
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 > ( ) ;
// opcplcConnection.WritetagValue(parameterValueDict[p.MACHINECODDE + ":" + p.MOLDNUMBER + ":" + p.COLUMNCODE], false);
// }
// }
// #endregion
// }
//}
#endregion
//获取所有的加工参数
foreach ( var parameter in paraList )
//20211222DQZhang
#region 捕获完成标记
if ( currentPC . COLUMNTYPE = = OpcEnumGeter . COLUMNTYPE . COMPLETEFLAG . GetHashCode ( ) . ToString ( ) )
{
if ( itemValue = = null )
{
continue ;
}
if ( ( bool ) itemValue )
{
if ( ! string . IsNullOrEmpty ( currentPC . DBNUMBER ) )
{
//临时存储值不获取值
if ( parameter . COLUMNTYPE = = OpcEnumGeter . COLUMNTYPE . TEMPVALUE . GetHashCode ( ) . ToString ( ) )
if ( ! ChatEventHelper . machinegroups . ContainsKey ( currentPC . DBNUMBER ) )
{
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 )
{
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 )
if ( ! string . Equals ( currentPC . MACHINECODDE , ChatEventHelper . machinegroups [ currentPC . DBNUMBER ] ) )
{
continue ;
}
}
#endregion
#region 处理已经读取完加工参数标记
//目前主要针对浇注设备
//浇注设备读取完加工参数后要将加工参数读取完成标记位修改为true
if ( paraConfigList . Count ( o = > o . MACHINECODDE = = currentPC . MACHINECODDE
& & o . MOLDNUMBER = = currentPC . MOLDNUMBER & & o . COLUMNTYPE = = OpcEnumGeter . COLUMNTYPE . PARAMETERREADED . GetHashCode ( ) . ToString ( )
) > 0 )
ChatEventArgs chatEventArgs = new ChatEventArgs ( ) ;
chatEventArgs . MachineCode = machCode ;
chatEventArgs . MessageType = OpcEnumGeter . MESSAGETYPE . PROCESSFINISH . GetHashCode ( ) . ToString ( ) ;
chatEventArgs . MessageContent = moldNumber ;
if ( moldNumber . EndsWith ( "?" ) )
{
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 )
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 . 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 ) ;
string key2 = string . Concat ( new string [ ]
{
parameterConfig . MACHINECODDE ,
":" ,
parameterConfig . MOLDNUMBER ,
":" ,
parameterConfig . COLUMNCODE
} ) ;
int num = Convert . ToInt32 ( MonitorConnection . ReadtagValue ( parameterValueDict [ key2 ] ) ) ;
if ( num = = 1 )
{
moldNumber = parameterConfig . MOLDNUMBER ;
break ;
}
}
}
#endregion
#region 将参数信息传递到web服务中
client . SubmitParameters ( JsonConvertHelper . GetSerializes ( resultList ) ) ;
#endregion
#region 加工步骤返回工控机信息
Thread . Sleep ( 2 0 0 0 ) ;
//该处需要例外处理一下
//浇注设备浇注完成后记录先输出浇注机的加工参数
//模架浇注完成后再输出模架的加工参数
//浇注的实际参数是浇注加+浇注模架参数的合集
//Q5的浇注模架和浇注机不是同一个厂家,交互起来麻烦
//所以先返回浇注机参数,将参数暂存,再获取浇注模架参数进行合并
//浇注机的浇注完成的参数名称是PouringFinish
//定义参数信息
ChatEventArgs e = new ChatEventArgs ( ) ;
//设备编号
e . MachineCode = machCode ;
//传输参数的类别
e . MessageType = OpcEnumGeter . MESSAGETYPE . PROCESSFINISH . GetHashCode ( ) . ToString ( ) ;
//传输参数的内容
e . MessageContent = resultList [ 0 ] . MOLDNUMBER ;
chatEventArgs . MessageContent = moldNumber ;
OpcService opcService = new OpcService ( ) ;
opcService . ReturnProductCodeToMachine ( e ) ;
//异步调用服务
#endregion
}
else
{
#region 冷刀设备的处理
if ( currentPC . MACHINECODDE = = "D3599-132" )
opcService . ReturnProductCodeToMachine ( chatEventArgs ) ;
Action action = delegate ( )
{
//获取对应的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
ParaInit . ReadParameters ( machCode , moldNumber , currentPC ) ;
} ;
action . BeginInvoke ( null , null ) ;
}
}
#endregion
#endregion
#region 捕获条码扫描完成标记
if ( currentPC . COLUMNTYPE = = OpcEnumGeter . COLUMNTYPE . EQUIPSCANFLAG . GetHashCode ( ) . ToString ( ) )
@ -745,9 +827,10 @@ namespace OpcServerHost.Init
if ( result ! = null )
{
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 ( 1 0 0 0 ) ;
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>