/// <summary> /// Updates the device attributes on the form /// </summary> /// <param name="aDI"></param> void UpdateAttributes(PvDeviceInfo aDI) { string lVendorName = ""; string lModelName = ""; string lMACAddress = ""; string lIPAddress = ""; string lGUID = ""; string lUserDefinedName = ""; if (aDI != null) { // Get device attributes lVendorName = aDI.VendorName; lModelName = aDI.ModelName; lMACAddress = "N/A"; lIPAddress = "N/A"; lGUID = "N/A"; lUserDefinedName = aDI.UserDefinedName; // GigE Vision specific device attributes PvDeviceInfoGEV lDeviceInfoGEV = aDI as PvDeviceInfoGEV; if (lDeviceInfoGEV != null) { lMACAddress = lDeviceInfoGEV.MACAddress; lIPAddress = lDeviceInfoGEV.IPAddress; } // USB3 Vision specific device attributes PvDeviceInfoU3V lDeviceInfoU3V = aDI as PvDeviceInfoU3V; if (lDeviceInfoU3V != null) { lGUID = lDeviceInfoU3V.DeviceGUID; } } // Fill device attribute text boxes manufacturerTextBox.Text = lVendorName; modelTextBox.Text = lModelName; macAddressTextBox.Text = lMACAddress; ipAddressTextBox.Text = lIPAddress; guidTextBox.Text = lGUID; nameTextBox.Text = lUserDefinedName; }
/// <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); }