public void UpdateBadCameraInformation(CameraInfo cameraInfo) { m_model.Text = cameraInfo.modelName; m_vendor.Text = cameraInfo.vendorName; m_sensor.Text = "N/A"; m_resolution.Text = "N/A"; m_interface.Text = InterfaceTranslator.GetInterfaceString(cameraInfo.interfaceType); m_busSpeed.Text = BusSpeedTranslator.GetBusSpeedString(cameraInfo.maximumBusSpeed); m_pciEBusSpeed.Text = BusSpeedTranslator.GetPCIeBusSpeedString(cameraInfo.pcieBusSpeed); m_iidcVersion.Text = "N/A"; m_firmwareVersion.Text = "N/A"; m_firmwareBuildTime.Text = "N/A"; m_driver.Text = "N/A"; if (cameraInfo.interfaceType == InterfaceType.Usb3 && cameraInfo.pcieBusSpeed == PCIeBusSpeed.Speed_2_5) { // Insufficient speed, set the text to red m_pciEBusSpeed.ForeColor = Color.Red; toolTipPCIeBusSpeed.SetToolTip(m_pciEBusSpeed, "PCIe bus speed is too low - USB 3.0 performance may be degraded"); toolTipPCIeBusSpeed.Active = true; } else { m_pciEBusSpeed.ForeColor = m_pciEBusSpeedLabel.ForeColor; toolTipPCIeBusSpeed.Active = false; } // Reset tooltip and text color if (m_driverTooltip == null) { m_driverTooltip = new ToolTip(); } m_driver.ForeColor = m_driverLabel.ForeColor; m_driverTooltip.Active = false; if (IsLadybug2) { const uint Ladybug2HeadRegAddress = 0x1F80; uint uiHeadNumber = 0; try { uiHeadNumber = m_camera.ReadRegister(Ladybug2HeadRegAddress); } catch (FC2Exception ex) { BasePage.ShowErrorMessageDialog("Unable to read head number in the register. Initialize camera information page failed.", ex); ClearInformation(); return; } m_serialNumber.Text = string.Format("{0} (Head S/N.{1}", cameraInfo.serialNumber, uiHeadNumber); } else { m_serialNumber.Text = cameraInfo.serialNumber.ToString(); } }
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(); } }
public void UpdateCameraInformation(CameraInfo cameraInfo) { m_model.Text = cameraInfo.modelName; m_vendor.Text = cameraInfo.vendorName; m_sensor.Text = cameraInfo.sensorInfo; m_resolution.Text = cameraInfo.sensorResolution; m_interface.Text = InterfaceTranslator.GetInterfaceString(cameraInfo.interfaceType); m_busSpeed.Text = BusSpeedTranslator.GetBusSpeedString(cameraInfo.maximumBusSpeed); m_pciEBusSpeed.Text = BusSpeedTranslator.GetPCIeBusSpeedString(cameraInfo.pcieBusSpeed); m_iidcVersion.Text = string.Format("{0:0.##}", (float)cameraInfo.iidcVersion / 100.0f); m_firmwareVersion.Text = cameraInfo.firmwareVersion; m_firmwareBuildTime.Text = cameraInfo.firmwareBuildTime; m_driver.Text = cameraInfo.driverName; if (m_camera == null || m_camera.IsConnected() == false) { Debug.WriteLine("Camera not found or disconnected"); ClearInformation(); return; } if (cameraInfo.interfaceType == InterfaceType.Usb3 && cameraInfo.pcieBusSpeed == PCIeBusSpeed.Speed_2_5) { // Insufficient speed, set the text to red m_pciEBusSpeed.ForeColor = Color.Red; toolTipPCIeBusSpeed.SetToolTip(m_pciEBusSpeed, "PCIe bus speed is too low - USB 3.0 performance may be degraded"); toolTipPCIeBusSpeed.Active = true; } else { m_pciEBusSpeed.ForeColor = m_pciEBusSpeedLabel.ForeColor; toolTipPCIeBusSpeed.Active = false; } if (cameraInfo.interfaceType == InterfaceType.GigE && !m_driverIsCompatible) { m_driver.ForeColor = Color.Red; if (m_driverTooltip == null) { m_driverTooltip = new ToolTip(); } m_driverTooltip.SetToolTip(m_driver, m_driverTooltipText); m_driverTooltip.Active = true; } else { if (m_driverTooltip == null) { m_driverTooltip = new ToolTip(); } m_driver.ForeColor = m_driverLabel.ForeColor; m_driverTooltip.Active = false; } if (IsLadybug2) { const uint Ladybug2HeadRegAddress = 0x1F80; uint uiHeadNumber = 0; try { uiHeadNumber = m_camera.ReadRegister(Ladybug2HeadRegAddress); } catch (FC2Exception ex) { BasePage.ShowErrorMessageDialog("Unable to read head number in the register. Initialize camera information page failed.", ex); ClearInformation(); ex.Dispose(); return; } m_serialNumber.Text = string.Format("{0} (Head S/N.{1}", cameraInfo.serialNumber, uiHeadNumber); } else { m_serialNumber.Text = cameraInfo.serialNumber.ToString(); } }