using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro.QuickBuild;
using Cognex.VisionPro.ToolGroup;
using System.IO;
using System.Windows;
using Cognex.VisionPro.PMAlign;
namespace WpfApp2
{
public class ReadVpp
{
public static List mails = new List();//创建一个Mail类型的列表,Mail 是一个类名 并命名为mails
public static List data = new List();
public static CogToolBlock toolBlock_Locate, toolBlock_Result;
public static CogToolGroup toolGroup;
public static CogPMAlignTool cogPMAlignTool;
public static string Result, Result1, Result2, Result3, Result4, Result5, Result6, Result7, Result8, Result9, Result10, Result11, Result12;
public static List list;
public static List list1;
public static List list2;
public static List list3;
public static List list4;
public static List list5;
public static List list6;
public static List list7;
public static List list8;
public static List list9;
public static List list10;
public static List list11;
public static List list12;
public static List listRunStatus = new List();
public static bool RunStatus;
public static void Vpp()
{
int i = 0;
toolGroup = CommonVar.Vpp.jobManager.Job(0).VisionTool as CogToolGroup;
toolBlock_Locate = toolGroup.Tools["Locate"] as CogToolBlock;
toolBlock_Result = toolGroup.Tools["CogToolBlockResult"] as CogToolBlock;
CommonVar.Vpp.PMACount = int.Parse(toolBlock_Locate.Outputs["PMACount"].Value.ToString());
toolBlock_Result.Outputs.LongCount();
CommonVar.num = Convert.ToString(toolBlock_Result.Outputs.ToArray());
//CommonVar.Vpp.Result = toolBlock_Result.Outputs[1].Value.ToString();
#region 数据拉取
CommonVar.lo = toolGroup.Tools.Count;
CommonVar.Vpp.Filename = toolGroup.Tools[14].RunStatus.Result.ToString();
// CommonVar.Vpp.Filename = toolGroup.Tools[14].Name;
//for (int m = 0; m < Convert.ToInt32(toolBlock_Result.Outputs.LongCount()); m++)
//{
// string name = toolBlock_Result.Outputs[m].Name;
// if (name == Result + m.ToString())
// {
// Data data1 = new Data();
// }
//}
while (i < Convert.ToInt32(toolBlock_Result.Outputs.LongCount()))
{
string name;
if (i == 0)
{
name = "Result";
}
else
{
name = toolBlock_Result.Outputs[i].Name;
}
i++;
//if (name == (Result + string.Format("Result{0}", i)))
//{
// Result = toolBlock_Result.Outputs[0].Value.ToString();
// list = new List(Result.Split(','));
//}
if (name=="Result")
{
Result = toolBlock_Result.Outputs[name].Value.ToString();
list = new List(Result.Split(','));
Mail mail10 = new Mail();
mail10.Type = new List(Result.Split(','))[0];
// mail1.Data = new List(Result1.Split(','))[Result1.Split(',').Length - 1];
// mail1.TestResult = new List(Result1.Split(','))[1];
mails.Add(mail10);
}
else if (name == "Result1")
{
Result1 = toolBlock_Result.Outputs[name].Value.ToString();
list1 = new List(Result1.Split(','));
Mail mail1 = new Mail(); //实例化Mail类对象,命名为 mail
mail1.Type = new List(Result1.Split(','))[0]; //给对象mail的Type 属性赋值
mail1.Data = new List(Result1.Split(','))[Result1.Split(',').Length - 1]; //给对象mail的 Data 属性赋值
mail1.TestResult = new List(Result1.Split(','))[1]; //给对象mail的TestResult 属性赋值
mails.Add(mail1); //将对象mail添加到列表
}
else if (name == "Result2")
{
Result2 = toolBlock_Result.Outputs[name].Value.ToString();
list2 = new List(Result2.Split(','));
Mail mail2 = new Mail();
mail2.Type = new List(Result2.Split(','))[0];
mail2.Data = new List(Result2.Split(','))[Result2.Split(',').Length - 1];
mail2.TestResult = new List(Result2.Split(','))[1];
mails.Add(mail2);
}
else if (name == "Result3")
{
Result3 = toolBlock_Result.Outputs[name].Value.ToString();
list3 = new List(Result3.Split(','));
Mail mail3 = new Mail();
mail3.Type = new List(Result3.Split(','))[0];
mail3.Data = new List(Result3.Split(','))[Result3.Split(',').Length - 1];
mail3.TestResult = new List(Result3.Split(','))[1];
mails.Add(mail3);
}
else if (name == "Result4")
{
Result4 = toolBlock_Result.Outputs[name].Value.ToString();
list4 = new List(Result4.Split(','));
Mail mail4 = new Mail();
mail4.Type = new List(Result4.Split(','))[0];
mail4.Data = new List(Result4.Split(','))[Result4.Split(',').Length - 1];
mail4.TestResult = new List(Result4.Split(','))[1];
mails.Add(mail4);
}
else if (name == "Result5")
{
Result5 = toolBlock_Result.Outputs[name].Value.ToString();
list5 = new List(Result5.Split(','));
Mail mail5 = new Mail();
mail5.Type = new List(Result5.Split(','))[0];
mail5.Data = new List(Result5.Split(','))[Result5.Split(',').Length - 1];
mail5.TestResult = new List(Result5.Split(','))[1];
mails.Add(mail5);
}
else if (name == "Result6")
{
Result6 = toolBlock_Result.Outputs[name].Value.ToString();
list6 = new List(Result6.Split(','));
Mail mail6 = new Mail();
mail6.Type = new List(Result6.Split(','))[0];
mail6.Data = new List(Result6.Split(','))[Result6.Split(',').Length - 1];
mail6.TestResult = new List(Result6.Split(','))[1];
mails.Add(mail6);
}
else if (name == "Result7")
{
Result7 = toolBlock_Result.Outputs[name].Value.ToString();
list7 = new List(Result7.Split(','));
Mail mail7 = new Mail();
mail7.Type = new List(Result7.Split(','))[0];
mail7.Data = new List(Result7.Split(','))[Result7.Split(',').Length - 1];
mail7.TestResult = new List(Result7.Split(','))[1];
mails.Add(mail7);
}
else if (name == "Result8")
{
Result8 = toolBlock_Result.Outputs[name].Value.ToString();
list8 = new List(Result8.Split(','));
Mail mail8 = new Mail();
mail8.Type = new List(Result8.Split(','))[0];
mail8.Data = new List(Result8.Split(','))[Result8.Split(',').Length - 1];
mail8.TestResult = new List(Result8.Split(','))[1];
mails.Add(mail8);
}
else if (name == "Result9")
{
Result9 = toolBlock_Result.Outputs[name].Value.ToString();
list9 = new List(Result9.Split(','));
Mail mail9 = new Mail();
mail9.Type = new List(Result9.Split(','))[0];
mail9.Data = new List(Result9.Split(','))[Result9.Split(',').Length - 1];
mail9.TestResult = new List(Result9.Split(','))[1];
mails.Add(mail9);
}
else if (name == "Result10")
{
Result10 = toolBlock_Result.Outputs[name].Value.ToString();
list10 = new List(Result10.Split(','));
Mail mail10 = new Mail();
mail10.Type = new List(Result10.Split(','))[0];
mail10.Data = new List(Result10.Split(','))[Result10.Split(',').Length - 1];
mail10.TestResult = new List(Result10.Split(','))[1];
mails.Add(mail10);
}
else if (name == "Result11")
{
Result11 = toolBlock_Result.Outputs[name].Value.ToString();
list11 = new List(Result11.Split(','));
Mail mail11 = new Mail();
mail11.Type = new List(Result11.Split(','))[0];
mail11.Data = new List(Result11.Split(','))[Result11.Split(',').Length - 1];
mail11.TestResult = new List(Result11.Split(','))[1];
mails.Add(mail11);
}
else if (name == "Result12")
{
Result12 = toolBlock_Result.Outputs[name].Value.ToString();
list12 = new List(Result12.Split(','));
Mail mail12 = new Mail();
mail12.Type = new List(Result12.Split(','))[0];
mail12.Data = new List(Result12.Split(','))[Result12.Split(',').Length - 1];
mail12.TestResult = new List(Result12.Split(','))[1];
mails.Add(mail12);
}
}
#endregion
#region 工具运行状态监测
int j = 0;
while (j < Int32.Parse(toolGroup.Tools.Count.ToString()))
{
listRunStatus.Add(toolGroup.Tools[j].RunStatus.ToString());
j++;
}
for (int m = 0; m < listRunStatus.Count; m++)
{
for (int n = 0; n < listRunStatus.Count; n++)
{
if (listRunStatus[m] == "Accept" && "Accept" == listRunStatus[n])
{
RunStatus = true;
}
else
{
RunStatus = false;
}
}
}
#endregion
}
}
}