使用VisionPro连接GIGE相机
using Cognex.VisionPro; using Cognex.VisionPro.Comm; using Cognex.VisionPro.FGGigE; using Cognex.VisionPro.QuickBuild; using Cognex.VisionPro.ResultsAnalysis; using Cognex.VisionPro.ToolGroup; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace VPPDemo { public partial class Form1 : Form { private const int INFO_OK = 0; private const int INFO_ERR = -1; ICogAcqFifo mAcqFifo2;//定义一个相机对象 private ICogFrameGrabber mFrameGrabber = null;// List<String> videoFormat = new List<String>();//相机信息列表 private CogFrameGrabberGigEs mfr2;//取得相机列表 private ICogFrameGrabber gbm2;//取第一个相机,第二个相机依次增加 public Form1() { InitializeComponent(); } /// <summary> /// 打开相机 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { mfr2 = new CogFrameGrabberGigEs ();//取得相机列表 gbm2 = mfr2[0];//取第一个相机,第二个相机依次增加 mAcqFifo2 = gbm2.CreateAcqFifo ( gbm2.AvailableVideoFormats[0], CogAcqFifoPixelFormatConstants.Format8Grey, 0, true );//初始化相机 cogRecordDisplay1.StartLiveDisplay ( mAcqFifo2, false );//控件绑定相机并显示画面 } private void Form1_Load(object sender, EventArgs e) { FindeCam(); } /// <summary> /// 遍历相机 /// </summary> /// <returns></returns> public int FindeCam() { try { CogFrameGrabberGigEs mframe = new CogFrameGrabberGigEs(); if (mframe.Count < 1) { MessageBox.Show("没有找到相机设备!"); } //遍历已连接相机信息,并添加进列表里(相机名,序列号,模式) for (int i = 0; i < mframe.Count; i++) { mFrameGrabber = mframe[i]; MessageBox.Show(mFrameGrabber.Name + mFrameGrabber.SerialNumber + mFrameGrabber.AvailableVideoFormats[0]); videoFormat.Add(mFrameGrabber.Name + mFrameGrabber.SerialNumber + mFrameGrabber.AvailableVideoFormats[0]); } return INFO_OK; } catch (Exception ex) { MessageBox.Show(ex.ToString(),"提示!",MessageBoxButtons.OKCancel,MessageBoxIcon.Error); return INFO_ERR; } } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { } private void button2_Click(object sender, EventArgs e) { gbm2.Disconnect(true); } } }