1 using Cognex.VisionPro; 2 using Cognex.VisionPro.FGGigE; 3 using Cognex.VisionPro.FGGigE.Implementation.Internal; 4 using Cognex.VisionPro.ToolBlock; 5 using System; 6 using System.Collections.Generic; 7 using System.ComponentModel; 8 using System.Data; 9 using System.Drawing; 10 using System.Linq; 11 using System.Text; 12 using System.Windows.Forms; 13 14 namespace 康耐视硬件触发测试 15 { 16 public partial class Form1 : Form 17 { 18 CogToolBlock tb = null; 19 CogAcqFifoTool acq = null; 20 CogAcqFifoTool tacq = null; 21 22 private string path = Application.StartupPath + "\\Tool\\" + "tb.vpp"; 23 private string pathAcq = AppDomain.CurrentDomain.BaseDirectory + "\\Tool\\" + "acq.vpp"; 24 public Form1() 25 { 26 InitializeComponent(); 27 try 28 { 29 tb = CogSerializer.LoadObjectFromFile(path) as CogToolBlock; 30 cogToolBlockEditV21.Subject = tb; 31 acq = CogSerializer.LoadObjectFromFile(pathAcq) as CogAcqFifoTool; 32 cogAcqFifoEditV21.Subject = acq; 33 } 34 catch (Exception ex) 35 { 36 37 MessageBox.Show(ex.Message); 38 } 39 40 41 } 42 43 private void Form1_FormClosing(object sender, FormClosingEventArgs e) 44 { 45 CogFrameGrabberGigEs cameras = new CogFrameGrabberGigEs(); 46 47 try 48 { 49 foreach (CogFrameGrabberGigE item in cameras) 50 { 51 item.Disconnect(false); 52 } 53 54 } 55 catch (Exception ex) 56 { 57 58 } 59 } 60 //方法参数,添加相机触发事件 61 private void AcqRun(object sender, CogCompleteEventArgs e) 62 { 63 acq.Run(); 64 cogRecordDisplay1.Image = acq.OutputImage; 65 cogRecordDisplay1.Fit(); 66 67 } 68 69 private void ToolAcq(object sender, CogCompleteEventArgs e) 70 { 71 tacq = tb.Tools["CogAcqFifoTool1"] as CogAcqFifoTool; 72 tacq.Run(); 73 cogRecordDisplay2.Image = tacq.OutputImage; 74 cogRecordDisplay2.Fit(); 75 76 } 77 78 79 private void Form1_Load(object sender, EventArgs e) 80 { 81 //acq.Operator.Complete += new CogCompleteEventHandler(ToolAcq); 82 //acq.Operator.Complete += new CogCompleteEventHandler(AcqRun); 83 tacq = tb.Tools["CogAcqFifoTool1"] as CogAcqFifoTool; 84 85 tacq.Operator.Complete += new CogCompleteEventHandler(ToolAcq); 86 87 } 88 89 90 } 91 }