private void OnLinkLabelClicked(object sender, LinkLabelLinkClickedEventArgs e) { LinkLabel label = sender as LinkLabel; string url = label.Tag.ToString(); if (e.Button == MouseButtons.Right) { m_copyURLItem.Tag = url; m_copyMenuStrip.Show(MousePosition); } else { ManagedUtilities.LaunchBrowser(url); } }
private void DisplayCameraInformationFromRowIndex(int rowIndex) { if (rowIndex == -1) { // Nothing is selected return; } bool badCamera = false; string cellContent = m_cameraDataGridView.Rows[rowIndex].Cells[0].Value.ToString(); if (m_badCameraInfo.ContainsKey(cellContent)) { badCamera = true; } if (m_cameraDataGridView.Rows[rowIndex].DefaultCellStyle.BackColor == IMCOMPATIBLE_DRIVER) { badCamera = true; } if (badCamera) { try { CameraInfo camInfo; m_badCameraInfo.TryGetValue(m_cameraDataGridView.Rows[rowIndex].Cells[0].Value.ToString(), out camInfo); if (camInfo != null) { ShowGigEInformation(); m_cameraInfoPanel.Camera = null; m_cameraInfoPanel.UpdateBadCameraInformation(camInfo); m_cameraInfoDisplayPanel.Height = m_cameraInfoPanel.MinimumSize.Height; m_cameraInfoDisplayPanel.Width = m_cameraInfoPanel.MinimumSize.Width; m_gigEInfoPanel.Camera = null; m_gigEInfoPanel.UpdateBadGigECameraInformation(camInfo); m_gigeInfoDisplayPanel.Height = m_gigEInfoPanel.MinimumSize.Height; m_gigeInfoDisplayPanel.Width = m_gigEInfoPanel.MinimumSize.Width; m_needShrinkWindowHeight = true; AdjustWindowMinimumSize(); } else { camInfo = new CameraInfo(); camInfo.interfaceType = InterfaceType.Unknown; camInfo.maximumBusSpeed = BusSpeed.Unknown; camInfo.pcieBusSpeed = PCIeBusSpeed.Unknown; HideGigEInformation(); m_cameraInfoPanel.Camera = null; m_cameraInfoPanel.UpdateBadCameraInformation(camInfo); m_cameraInfoDisplayPanel.Height = m_cameraInfoPanel.MinimumSize.Height; m_cameraInfoDisplayPanel.Width = m_cameraInfoPanel.MinimumSize.Width; m_needShrinkWindowHeight = true; AdjustWindowMinimumSize(); } ////if window shrink is needed and current interface ////is not GigE then restore the window height (for bug 14937) //this.Height = this.MinimumSize.Height; //m_needShrinkWindowHeight = false; } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } else { ManagedPGRGuid guid; if (GetPGRGuidFromRowIndex(rowIndex, out guid) == false) { MessageBox.Show("Error getting camera information", "FlyCapture2", MessageBoxButtons.OK, MessageBoxIcon.Error); m_cameraInfoPanel.ClearInformation(); return; } InterfaceType ifType = m_busMgr.GetInterfaceTypeFromGuid(guid); ManagedCameraBase camera; if (ifType == InterfaceType.GigE) { camera = new ManagedGigECamera(); } else { camera = new ManagedCamera(); } using (camera) { if (ifType == InterfaceType.GigE) { ShowGigEInformation(); } else { HideGigEInformation(); } try { camera.Connect(guid); } catch (FC2Exception ex) { Debug.WriteLine("Unable to connect to camera."); Debug.WriteLine(ex.Message); return; } // cheeck for filter driver compatibility bool compatibleFilterDriverInstalled = true; string errorMessage = string.Empty; if (ifType == InterfaceType.GigE) { try { ManagedUtilities.CheckDriver(guid); } catch (FC2Exception ex) { compatibleFilterDriverInstalled = false; errorMessage = ex.Message; } } CameraInfo camInfo; try { camInfo = camera.GetCameraInfo(); } catch (FC2Exception ex) { Debug.WriteLine("Unable to get Camera Info. {0}", ex.Message); return; } m_cameraInfoPanel.Camera = camera; m_cameraInfoPanel.UpdateCameraInformation(camInfo); m_cameraInfoDisplayPanel.Height = m_cameraInfoPanel.MinimumSize.Height; m_cameraInfoDisplayPanel.Width = m_cameraInfoPanel.MinimumSize.Width; if (ifType == InterfaceType.GigE) { m_gigEInfoPanel.Camera = camera; m_gigEInfoPanel.UpdateGigECameraInformation(camInfo); m_gigeInfoDisplayPanel.Height = m_gigEInfoPanel.MinimumSize.Height; m_gigeInfoDisplayPanel.Width = m_gigEInfoPanel.MinimumSize.Width; m_needShrinkWindowHeight = true; if (!compatibleFilterDriverInstalled) { m_cameraInfoPanel.SetDriverCompatibilityStatus(compatibleFilterDriverInstalled, errorMessage); } } } AdjustWindowMinimumSize(); if (m_needShrinkWindowHeight == true && ifType != InterfaceType.GigE) { //if window shrink is needed and current interface //is not GigE then restore the window height (for bug 14937) this.Height = this.MinimumSize.Height; m_needShrinkWindowHeight = false; } } }
private void PopulateCameraList() { uint numCameras = 0; CameraInfo[] discoveredCameras = new CameraInfo[0]; try { numCameras = m_busMgr.GetNumOfCameras(); discoveredCameras = ManagedBusManager.DiscoverGigECameras(); } catch (FC2Exception ex) { BasePage.ShowErrorMessageDialog("Error getting number of cameras.", ex); } if (numCameras == 0 && discoveredCameras.Length == 0) { m_cameraListLabel.Text = string.Format("Camera List (No cameras detected)"); m_cameraDataGridView.Rows.Clear(); m_cameraInfoPanel.ClearInformation(); HideGigEInformation(); AdjustWindowMinimumSize(); this.Height = this.MinimumSize.Height; m_needShrinkWindowHeight = false; return; } SortedDictionary <uint, CameraInfo> discoveredCameraInfo = new SortedDictionary <uint, CameraInfo>(); m_badCameraInfo = new Dictionary <string, CameraInfo>(); m_goodCameraInfo = new Dictionary <ManagedPGRGuid, CameraInfo>(); for (uint currCamIdx = 0; currCamIdx < discoveredCameras.Length; currCamIdx++) { try { Debug.WriteLine( String.Format( "Discovered camera: {0} ({1})", discoveredCameras[currCamIdx].modelName, discoveredCameras[currCamIdx].serialNumber)); // Check if the camera already exists - we sometimes get duplicate cameras // returned from the discover call if (!discoveredCameraInfo.ContainsKey(discoveredCameras[currCamIdx].serialNumber)) { discoveredCameraInfo.Add( discoveredCameras[currCamIdx].serialNumber, discoveredCameras[currCamIdx]); } } catch (ArgumentNullException ex) { Debug.WriteLine("A null key was specified for discovered camera lookup."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); continue; } catch (ArgumentException ex) { Debug.WriteLine("An element with the same key already exists in the discovered camera dictionary."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); continue; } catch (System.Exception ex) { Debug.WriteLine("An error occurred while updating the discovered GigE camera list."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); continue; } } List <DataGridViewRow> goodCameraList = new List <DataGridViewRow>(); List <DataGridViewRow> badCameraList = new List <DataGridViewRow>(); for (uint i = 0; i < numCameras; i++) { try { ManagedPGRGuid guid; guid = m_busMgr.GetCameraFromIndex(i); InterfaceType currInterface; currInterface = m_busMgr.GetInterfaceTypeFromGuid(guid); using (ManagedCamera camera = new ManagedCamera()) { bool compatibleDriver = true; string errorMessage = string.Empty; try { camera.Connect(guid); } catch (FC2Exception ex) { if (ex.Type == ErrorType.IncompatibleDriver) { compatibleDriver = false; errorMessage = ex.Message; } } CameraInfo camInfo; if (compatibleDriver) { camInfo = camera.GetCameraInfo(); if (discoveredCameraInfo.ContainsKey(camInfo.serialNumber) == true) { // Remove good camera from dictionary discoveredCameraInfo.Remove(camInfo.serialNumber); m_goodCameraInfo.Add(guid, camInfo); } // Append the camera to the list try { DataGridViewRow newCamera = new DataGridViewRow(); DataGridViewTextBoxCell[] cells = new DataGridViewTextBoxCell[4]; for (int ci = 0; ci < cells.Length; ci++) { cells[ci] = new DataGridViewTextBoxCell(); } cells[0].Value = camInfo.serialNumber.ToString(); cells[1].Value = camInfo.modelName; cells[2].Value = InterfaceTranslator.GetInterfaceString(currInterface); cells[3].Value = camInfo.ipAddress.Equals(new IPAddress(0)) ? "N/A" : camInfo.ipAddress.ToString(); newCamera.Cells.AddRange(cells); goodCameraList.Add(newCamera); } catch (InvalidOperationException ex) { Debug.WriteLine("Error appending new row to camera list."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); continue; } catch (ArgumentNullException ex) { Debug.WriteLine("The cell in camera list contains null value."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); continue; } } else { camInfo = new CameraInfo(); DataGridViewRow newCamera = new DataGridViewRow(); newCamera.DefaultCellStyle.BackColor = IMCOMPATIBLE_DRIVER; DataGridViewTextBoxCell[] cells = new DataGridViewTextBoxCell[4]; for (int ci = 0; ci < cells.Length; ci++) { cells[ci] = new DataGridViewTextBoxCell(); } cells[0].Value = "N/A"; cells[1].Value = ManagedUtilities.GetDriverDeviceName(guid); cells[2].Value = "Incompatible Driver"; cells[3].Value = "N/A"; cells[0].ToolTipText = "An incompatible driver is installed on this device."; foreach (DataGridViewTextBoxCell cell in cells) { cell.ToolTipText = errorMessage; } newCamera.Cells.AddRange(cells); badCameraList.Add(newCamera); } } } catch (FC2Exception ex) { BasePage.ShowErrorMessageDialog("Error populating camera list.", ex); continue; } } foreach (KeyValuePair <uint, CameraInfo> pair in discoveredCameraInfo) { try { CameraInfo info = pair.Value; m_badCameraInfo.Add(info.serialNumber.ToString(), info); DataGridViewRow newCamera = new DataGridViewRow(); newCamera.DefaultCellStyle.BackColor = IP_PROBLEM; DataGridViewTextBoxCell[] cells = new DataGridViewTextBoxCell[4]; for (int ci = 0; ci < cells.Length; ci++) { cells[ci] = new DataGridViewTextBoxCell(); } cells[0].Value = info.serialNumber.ToString(); cells[1].Value = info.modelName; cells[2].Value = "GigE"; cells[3].Value = info.ipAddress.Equals(new IPAddress(0)) ? "N/A" : info.ipAddress.ToString(); cells[0].ToolTipText = "This camera is discoverable but can not be controlled"; foreach (DataGridViewTextBoxCell cell in cells) { if (m_GigEEnumerationIsDisabled) { cell.ToolTipText = "This camera cannot be enumerated by FlyCapture2 because GigE camera enumeration \n" + "has been disabled)"; } else { cell.ToolTipText = "Camera IP settings or local interface is mis-configured. Use \"Force IP\" to \n" + "correct it"; } } newCamera.Cells.AddRange(cells); badCameraList.Add(newCamera); } catch (InvalidOperationException ex) { Debug.WriteLine("Error appending new row to camera list."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); continue; } catch (ArgumentNullException ex) { Debug.WriteLine("The cell in camera list contains null value."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); continue; } } m_cameraDataGridView.Rows.Clear(); m_cameraListLabel.Text = string.Format("Camera List ({0} cameras detected)", (goodCameraList.Count + badCameraList.Count)); for (int i = 0; i < goodCameraList.Count; i++) { try { m_cameraDataGridView.Rows.Add(goodCameraList[i]); } catch (InvalidOperationException ex) { Debug.WriteLine("Error adding camera list to the view."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } catch (ArgumentNullException ex) { Debug.WriteLine("The camera list contains null value."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } catch (ArgumentException ex) { Debug.WriteLine("The camera list contains invalid value."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } for (int i = 0; i < badCameraList.Count; i++) { try { m_cameraDataGridView.Rows.Add(badCameraList[i]); } catch (InvalidOperationException ex) { Debug.WriteLine("Error adding camera list to the view."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } catch (ArgumentNullException ex) { Debug.WriteLine("The camera list contains null value."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } catch (ArgumentException ex) { Debug.WriteLine("The camera list contains invalid value."); Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } if (m_cameraDataGridView.Rows.Count > 0) { // display first camera information DisplayCameraInformationFromRowIndex(0); } else { // Nothing need to display m_cameraInfoPanel.ClearInformation(); } }