/// <summary> /// Connect to device. /// </summary> /// <param name="ipAddress">IP address.</param> public RaptorCam(string ipAddress) { calibrationADC = new double[2]; calibrationDAC = new double[2]; counts = new int[numberOfImages, ccdImageSizeX, ccdImageSizeY]; sysStatus = new bool[8]; fpgaStatus = new bool[8]; trigMode = new bool[2]; try { // Setup GigE device device = PvDevice.CreateAndConnect(ipAddress); stream = PvStream.CreateAndOpen(ipAddress); PvDeviceGEV deviceGEV = device as PvDeviceGEV; PvStreamGEV streamGEV = stream as PvStreamGEV; deviceGEV.NegotiatePacketSize(); deviceGEV.SetStreamDestination(streamGEV.LocalIPAddress, streamGEV.LocalPort); // Setup camera serial comms serial = new PvDeviceSerialPort(); serial.Open(device, PvDeviceSerial.Bulk0); // Setup pipeline pipeline = new PvPipeline(stream); SetCameraParameters(); StartStreaming(); StartAcquisition(); Initialize(); } catch { Disconnect(); return; } }
/// <summary> /// Connects to the device from a device info /// </summary> /// <param name="aDI"></param> void Connect(PvDeviceInfo aDI) { // Just in case we came here still connected... Disconnect(); if (aDI == null) { MessageBox.Show("GigE Vision devices not currently supported by this sample.", Text); return; } // Create and connect the device controller based on the selected device mDevice = PvDevice.CreateAndConnect("192.168.1.104"); try { // Create and open stream mStream = PvStream.CreateAndOpen(aDI.ConnectionID); // GigE Vision specific connection steps if (aDI.Type == PvDeviceInfoType.GEV) { PvDeviceGEV lDeviceGEV = mDevice as PvDeviceGEV; PvStreamGEV lStreamGEV = mStream as PvStreamGEV; // Negotiate packet size lDeviceGEV.NegotiatePacketSize(); // Set stream destination to our stream object lDeviceGEV.SetStreamDestination(lStreamGEV.LocalIPAddress, lStreamGEV.LocalPort); // Setup camera serial comms serial = new PvDeviceSerialPort(); serial.Open(lDeviceGEV, PvDeviceSerial.Bulk0); } // Create pipeline - requires stream mPipeline = new PvPipeline(mStream); } catch (PvException ex) { // Failure at some point, display and abort MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); Disconnect(); return; } // Register to all events of the parameters in the device's node map foreach (PvGenParameter lParameter in mDevice.Parameters) { lParameter.OnParameterUpdate += new OnParameterUpdateHandler(OnParameterChanged); } // Connect link disconnection handler mDevice.OnLinkDisconnected += new OnLinkDisconnectedHandler(OnLinkDisconnected); // Update device attributes UpdateAttributes(aDI); // Fill acquisition mode combo box modeComboBox.Items.Clear(); PvGenEnum lMode = mDevice.Parameters.GetEnum("AcquisitionMode"); if (lMode != null) { foreach (PvGenEnumEntry lEntry in lMode) { if (lEntry.IsAvailable) { int lIndex = modeComboBox.Items.Add(lEntry.ValueString); if (lEntry.ValueInt == lMode.ValueInt) { modeComboBox.SelectedIndex = lIndex; } } } } // Ready image reception StartStreaming(); // Sync the UI with our new status EnableInterface(); }
/// <summary> /// 连接相机 /// </summary> /// <param name="Cam_">相机数据接口</param> /// <param name="i">连接第几个相机</param> /// <param name="disConnectCam_">相机丢失回调事件</param> /// <param name="CamerCallBack_">相机取图回调函数</param> /// <returns></returns> public bool SetConnectCamer(IE2VCamer_ShuJu Cam_, uint i, OnLinkDisconnectedHandler disConnectCam_, OnBufferDisplay CamerCallBack_) { bool ok = false; try { if (this._countCamer > 0 && this._countCamer > i && this.Set_Disconnect(Cam_)) { #region 无用代码 //try //{ // // Create and connect the device controller based on the selected device // mDevice = PvDevice.CreateAndConnect(aDI); // // Create and open stream // mStream = PvStream.CreateAndOpen(aDI); // // GigE Vision specific connection steps // if (aDI.Type == PvDeviceInfoType.GEV) // { // PvDeviceGEV lDeviceGEV = mDevice as PvDeviceGEV; // PvStreamGEV lStreamGEV = mStream as PvStreamGEV; // // Negotiate packet size // lDeviceGEV.NegotiatePacketSize(); // // Set stream destination to our stream object // lDeviceGEV.SetStreamDestination(lStreamGEV.LocalIPAddress, lStreamGEV.LocalPort); // } // // Create pipeline - requires stream // mPipeline = new PvPipeline(mStream); //} //catch (PvException ex) //{ // // Failure at some point, display and abort // MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); // Disconnect(); // return; //} //// Register to all events of the parameters in the device's node map //foreach (PvGenParameter lParameter in mDevice.Parameters) //{ // lParameter.OnParameterUpdate += new OnParameterUpdateHandler(OnParameterChanged); //} //// Connect link disconnection handler //mDevice.OnLinkDisconnected += new OnLinkDisconnectedHandler(OnLinkDisconnected); //// Update device attributes //UpdateAttributes(aDI); //// Fill acquisition mode combo box //modeComboBox.Items.Clear(); //PvGenEnum lMode = mDevice.Parameters.GetEnum("AcquisitionMode"); //if (lMode != null) //{ // foreach (PvGenEnumEntry lEntry in lMode) // { // if (lEntry.IsAvailable) // { // int lIndex = modeComboBox.Items.Add(lEntry.ValueString); // if (lEntry.ValueInt == lMode.ValueInt) // { // modeComboBox.SelectedIndex = lIndex; // } // } // } //} #endregion PvDeviceInfo aDI = this._pv.GetDeviceInfo(i); Thread.Sleep(800); PvDeviceInfoGEV lDeviceInfoGEV = aDI as PvDeviceInfoGEV; if (lDeviceInfoGEV != null)//这一段代码不能小否则出错 { string lMACAddress = lDeviceInfoGEV.MACAddress; string lIPAddress = lDeviceInfoGEV.IPAddress; } Cam_.MDevice = PvDevice.CreateAndConnect(aDI); Cam_.MStream = PvStream.CreateAndOpen(aDI); if (aDI.Type == PvDeviceInfoType.GEV) { PvDeviceGEV lDeviceGEV = Cam_.MDevice as PvDeviceGEV; PvStreamGEV lStreamGEV = Cam_.MStream as PvStreamGEV; // Negotiate packet size lDeviceGEV.NegotiatePacketSize(); // Set stream destination to our stream object lDeviceGEV.SetStreamDestination(lStreamGEV.LocalIPAddress, lStreamGEV.LocalPort); } // Create pipeline - requires stream Cam_.MPipeline = new PvPipeline(Cam_.MStream); if (disConnectCam_ != null) { // Connect link disconnection handler Cam_.MDevice.OnLinkDisconnected += new OnLinkDisconnectedHandler(disConnectCam_); } if (CamerCallBack_ != null) { Cam_.MDisplayThread.OnBufferDisplay += new OnBufferDisplay(CamerCallBack_); } Set_StartStreaming(Cam_); ok = true; } } catch (Exception ex) { MessageBox.Show("相机绑定出错:" + ex.Message); } return(ok); }