@ -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:客户端句柄值
@ -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 )
@ -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,213 +502,276 @@ namespace OpcServerHost.Init
#region 捕获完成标记
#region 捕获完成标记
if ( currentPC . COLUMNTYPE = = OpcEnumGeter . COLUMNTYPE . COMPLETEFLAG . GetHashCode ( ) . ToString ( ) )
//if (currentPC.COLUMNTYPE == OpcEnumGeter.COLUMNTYPE.COMPLETEFLAG.GetHashCode().ToString())
{
//{
// if (itemValue == null)
// {
// continue;
// }
// //如果完成标记表示更新了加工参数
// //获取所有的加工参数
// if ((Boolean)itemValue == true)
// {
// //设置延迟2秒
// //因为plc刷新频率
// //个别情况获取不到值可以适当的延长等待时间
// Thread.Sleep(2000);
if ( itemValue = = null )
// 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>();
continue ;
}
//如果完成标记表示更新了加工参数
//获取所有的加工参数
if ( ( Boolean ) itemValue = = true )
{
//设置延迟2秒
//因为plc刷新频率
//个别情况获取不到值可以适当的延长等待时间
Thread . Sleep ( 2 0 0 0 ) ;
// //获取所有的加工参数
// 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);
Console . WriteLine ( System . DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) + " Catch Finish Flag " + currentPC . MACHINECODDE + ":" + currentPC . MOLDNUMBER + ":" + currentPC . COLUMNCODE ) ;
// continue;
WriteLog . Write ( System . DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) + " Catch Finish Flag " + currentPC . COLUMNCODE , currentPC . MACHINECODDE ) ;
// }
// 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;
// }
// }
// #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")
// {
List < ParameterConfig > resultList = new List < ParameterConfig > ( ) ;
// //获取对应的OPC操作对象
// opcplcConnection.KepGroup = opcplcConnection.KepGroups.GetOPCGroup(
#region 获取该模块下的加工参数
// 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 )
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 ( ( bool ) itemValue )
try
{
{
#region 获取参数
if ( ! string . IsNullOrEmpty ( currentPC . DBNUMBER ) )
ParameterConfig paraConfig = GetResultParameterConfig ( parameter ) ;
var result = new object ( ) ;
try
{
{
string item = parameter . MACHINECODDE + ":" + parameter . MOLDNUMBER + ":" + parameter . COLUMNCODE ;
if ( ! ChatEventHelper . machinegroups . ContainsKey ( currentPC . DBNUMBER ) )
int indexValue = parameterValueDict [ item ] ;
OPCPLCAutomation m = opcDict [ currentPC . MACHINECODDE ] ;
result = m . ReadtagValue ( opcItemDict [ item ] ) ;
}
catch ( Exception ex )
{
{
continue ;
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 ;
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 ,
":" ,
parameterConfig . COLUMNCODE
} ) ;
int num = Convert . ToInt32 ( MonitorConnection . ReadtagValue ( parameterValueDict [ key2 ] ) ) ;
Console . WriteLine ( System . DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) + " Set Collected true" + p . MACHINECODDE + ":" + p . MOLDNUMBER + ":" + p . COLUMNCODE ) ;
if ( num = = 1 )
WriteLog . Write ( System . DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) + " Set Collected true " + p . COLUMNCODE , p . MACHINECODDE ) ;
{
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 ;
OpcService opcService = new OpcService ( ) ;
opcService . ReturnProductCodeToMachine ( e ) ;
//异步调用服务
#endregion
}
}
else
chatEventArgs . MessageContent = moldNumber ;
{
OpcService opcService = new OpcService ( ) ;
opcService . ReturnProductCodeToMachine ( chatEventArgs ) ;
#region 冷刀设备的处理
Action action = delegate ( )
if ( currentPC . MACHINECODDE = = "D3599-132" )
{
//获取对应的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 ) ;
ParaInit . ReadParameters ( machCode , moldNumber , currentPC ) ;
WriteLog . Write ( System . DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) + " Get Finish false, set false " + p . COLUMNCODE , p . MACHINECODDE ) ;
} ;
action . BeginInvoke ( null , null ) ;
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 ( ) )
{
{
@ -746,8 +828,9 @@ namespace OpcServerHost.Init
{
{
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 ( 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>
/// 向设备发送可以操作的指令信息
/// 向设备发送可以操作的指令信息
/// </summary>
/// </summary>