Ejemplo n.º 1
0
        private void OnPacketResendLoad()
        {
            // TODO: check GigE part
            if (!IsGEV())
            {
                return;
            }

            GigEConfig        currConfig;
            ManagedGigECamera camera = (ManagedGigECamera)m_camera;

            try
            {
                currConfig = camera.GetGigEConfig();
            }
            catch (FC2Exception ex)
            {
                // TODO: Print error
                Debug.WriteLine(ex.Message);
                ex.Dispose();
                return;
            }

            m_enableGigEPacketResendCheckBox.Checked = currConfig.enablePacketResend;
        }
Ejemplo n.º 2
0
        static void DisableHeartbeat(ManagedGigECamera cam)
        {
            const uint k_GVCPCapabilityAddr = 0x0934;
            const uint k_GVCPConfigAddr     = 0x0954;

            // Determine if heartbeat can be disabled by reading the GVCP Capability register
            uint       regVal  = cam.ReadGVCPRegister(k_GVCPCapabilityAddr);
            const uint BitMask = 0x20000000;

            System.Boolean canDisableHeartbeat = ((regVal & BitMask) == BitMask);

            if (canDisableHeartbeat)
            {
                regVal = cam.ReadGVCPRegister(k_GVCPConfigAddr);

                // Disable heartbeat by setting GVCP Configuration register's bit 31 to 1
                regVal |= 0x00000001;

                cam.WriteGVCPRegister(k_GVCPConfigAddr, regVal);

                Console.WriteLine("");
                Console.WriteLine("NOTE: GigE camera's heartbeat is disabled in Debug Mode.");
                Console.WriteLine("      Please power cycle the camera to re-enable the heartbeat.");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Main version of capture
        /// </summary>
        /// <param name="Angle"></param>
        /// <param name="cropOn"></param>
        /// <returns></returns>
        public Image <Bgr, byte> capture(ManagedGigECamera camera, int Angle) //, bool cropOn)
        {
            Image <Bgr, byte> bmp = null;

            if (camera == null)
            {
                return(bmp);
            }
            try
            {
                camera.RetrieveBuffer(m_rawImage);
            }
            catch (FC2Exception ex)
            {
                Debug.WriteLine("Error: " + ex.Message);
            }
            lock (this)
            {
                m_rawImage.Convert(FlyCapture2Managed.PixelFormat.PixelFormatBgr, m_processedImage);
                bmp = new Image <Bgr, byte>(m_processedImage.bitmap);
            }

            //if (Angle != 0) bmp = bmp.Convert<Bgr, Byte>().Rotate(Angle, new Bgr(0, 0, 0), cropOn);
            if (Angle != 0)
            {
                bmp = bmp.Convert <Bgr, Byte>().Rotate(Angle, new Bgr(0, 0, 0), false);
            }
            return(bmp);
        }
Ejemplo n.º 4
0
        private void m_enableGigEPacketResendCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            // TODO: check GigE part
            if (!IsGEV())
            {
                return;
            }

            GigEConfig        currConfig;
            ManagedGigECamera camera = (ManagedGigECamera)m_camera;

            try
            {
                currConfig = camera.GetGigEConfig();
            }
            catch (FC2Exception ex)
            {
                // TODO: Print error
                Debug.WriteLine(ex.Message);
                return;
            }

            currConfig.enablePacketResend = m_enableGigEPacketResendCheckBox.Checked;

            try
            {
                camera.SetGigEConfig(currConfig);
            }
            catch (FC2Exception ex)
            {
                // TODO: Print error
                Debug.WriteLine(ex.Message);
                return;
            }
        }
Ejemplo n.º 5
0
        private void OnConfigurationButtonClick(object sender, EventArgs e)
        {
            ManagedPGRGuid[] guids = GetCurrentSelectedGuids();
            foreach (ManagedPGRGuid guid in guids)
            {
                try
                {
                    InterfaceType ifType = m_busMgr.GetInterfaceTypeFromGuid(guid);

                    ManagedCameraBase camera;
                    if (ifType == InterfaceType.GigE)
                    {
                        camera = new ManagedGigECamera();
                    }
                    else
                    {
                        camera = new ManagedCamera();
                    }

                    camera.Connect(guid);

                    CameraInfo camInfo = camera.GetCameraInfo();

                    DialogHolder dialogHolder;
                    if (m_activeDialogs.TryGetValue(camInfo.serialNumber, out dialogHolder))
                    {
                        camera.Disconnect();
                        dialogHolder.camCtlMF.ReconnectCamera(guid);
                        dialogHolder.camCtlMF.ShowWindow();
                    }
                    else
                    {
                        CameraControlMainFrame camControlDialog;
                        camControlDialog = new CameraControlMainFrame();
                        camControlDialog.Connect(camera);

                        if (m_currentCustomTitle != null)
                        {
                            camControlDialog.SetTitle(m_currentCustomTitle);
                        }

                        camControlDialog.ShowWindow();
                        dialogHolder = new DialogHolder(camera, camControlDialog);
                        m_activeDialogs.Add(camInfo.serialNumber, dialogHolder);
                    }
                }
                catch (FC2Exception ex)
                {
                    string error = string.Format("Failed to launch camera control dialog for camera: {0}", ex.Message);
                    Debug.WriteLine(error);
                    MessageBox.Show(error, "FlyCapture2", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ex.Dispose();
                    return;
                }
            }
        }
Ejemplo n.º 6
0
        public void ChooseCamera()
        {
            StopStreaming();
            DeleteCamera();

beginSelecCamera:
            CameraSelectionDialog selectDialog = new CameraSelectionDialog();

            if (selectDialog.ShowModal() == true)
            {
                ManagedPGRGuid[] guids = selectDialog.GetSelectedCameraGuids();

                if (guids.Length < 1)
                {
                    if (MessageBox.Show("You have not selected a camera. Do you want to restart camera selection diaolog?", "No camera", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        goto beginSelecCamera;
                    }
                    else
                    {
                        Application.Current.Shutdown();
                    }
                }
                m_busManager = new ManagedBusManager();

                var interfaceType = m_busManager.GetInterfaceTypeFromGuid(guids[0]);
                if (interfaceType == InterfaceType.GigE)
                {
                    m_camera = new ManagedGigECamera();
                }
                else
                {
                    m_camera = new ManagedCamera();
                }

                m_camera.Connect(guids[0]);

                EmbeddedImageInfo embeddedInfo = m_camera.GetEmbeddedImageInfo();
                embeddedInfo.timestamp.onOff = true;
                embeddedInfo.exposure.onOff  = true;
                embeddedInfo.shutter.onOff   = true;
                embeddedInfo.gain.onOff      = true;
                m_camera.SetEmbeddedImageInfo(embeddedInfo);

                float shutterMin = m_camera.GetPropertyInfo(PropertyType.Shutter).absMin, shutterMax = m_camera.GetPropertyInfo(PropertyType.Shutter).absMax;
                m_commonViewModel.CameraShutterRangeBegin = shutterMin; m_commonViewModel.CameraShutterRangeEnd = shutterMax;
                FC2Config config = m_camera.GetConfiguration();
                config.grabMode = GrabMode.BufferFrames;
                m_camera.SetConfiguration(config);
                m_cameraCtrlDialog.Connect(m_camera);
                m_commonViewModel.IsCameraChosen        = true;
                m_commonViewModel.IsStreamingWasStarted = false;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 设置丢帧重传
        /// </summary>
        void SetGigEPacketResend()
        {
            try
            {
#if (SDK)
                ManagedGigECamera managedGigECamera = (ManagedGigECamera)g_ManagedCameraBase;
                GigEConfig        gigEConfig        = managedGigECamera.GetGigEConfig();
                gigEConfig.enablePacketResend = true;
                managedGigECamera.SetGigEConfig(gigEConfig);//设置丢帧重传
#endif
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
            }
        }
Ejemplo n.º 8
0
 public void SetModeAndStartCapture(ManagedGigECamera camera, Mode mode)
 {
     try
     {
         camera.SetGigEImagingMode(mode);
         // Start streaming on camera
         camera.StartCapture();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error starting camera : {0}", ex.Message);
         Console.WriteLine("Press any key to exit...");
         Console.ReadLine();
         return;
     }
 }
Ejemplo n.º 9
0
        public bool CamConnection(uint[] serialList)
        {
            NumCameras = serialList.Length;
            ManagedBusManager busMgr = new ManagedBusManager();

            mCameras = new ManagedGigECamera[NumCameras];

            for (uint i = 0; i < NumCameras; i++)
            {
                if (serialList[i] == 0)
                {
                    continue;
                }

                mCameras[i] = new ManagedGigECamera();

                try
                {
                    ManagedPGRGuid guid = busMgr.GetCameraFromSerialNumber(serialList[i]);

                    // Connect to a camera
                    mCameras[i].Connect(guid);

                    // Turn trigger mode off
                    TriggerMode trigMode = new TriggerMode();
                    trigMode.onOff = false;
                    mCameras[i].SetTriggerMode(trigMode);

                    // Turn Timestamp on
                    EmbeddedImageInfo imageInfo = new EmbeddedImageInfo();
                    imageInfo.timestamp.onOff = true;
                    mCameras[i].SetEmbeddedImageInfo(imageInfo);

                    //IsConnected[i] = true;

                    GV.IsCameraConnected = true;
                }
                catch (Exception ex)
                {
                    //IsConnected[i] = false;

                    GV.IsCameraConnected = false;
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 10
0
        private string GenerateToolTipString(ManagedPGRGuid guid)
        {
            if (guid.Equals(m_lastTooltipGuid))
            {
                return(m_tooltipString);
            }

            m_lastTooltipGuid = guid;

            if (guid.Equals(m_currCameraGuid))
            {
                StringBuilder tooltipStr = new StringBuilder();
                tooltipStr.AppendFormat("Camera: {0} {1} ({2})", m_camInfo.vendorName, m_camInfo.modelName, m_camInfo.serialNumber).AppendLine();
                tooltipStr.AppendFormat("Sensor: {0}", m_camInfo.sensorInfo).AppendLine();
                tooltipStr.AppendFormat("Firmware: {0} Built: {1}", m_camInfo.firmwareVersion, m_camInfo.firmwareBuildTime).AppendLine();
                tooltipStr.AppendFormat("Driver: {0}", m_camInfo.driverName).AppendLine();

                m_tooltipString = tooltipStr.ToString();
                return(m_tooltipString);
            }

            ManagedCameraBase tempCamera = null;

            if (m_busMgr.GetInterfaceTypeFromGuid(guid) == InterfaceType.GigE)
            {
                tempCamera = new ManagedGigECamera();
            }
            else
            {
                tempCamera = new ManagedCamera();
            }

            using (tempCamera)
            {
                tempCamera.Connect(guid);
                CameraInfo camInfo = tempCamera.GetCameraInfo();

                StringBuilder tooltipStr = new StringBuilder();
                tooltipStr.AppendFormat("Camera: {0} {1} ({2})", camInfo.vendorName, camInfo.modelName, camInfo.serialNumber).AppendLine();
                tooltipStr.AppendFormat("Sensor: {0}", camInfo.sensorInfo).AppendLine();
                tooltipStr.AppendFormat("Firmware: {0} Built: {1}", camInfo.firmwareVersion, camInfo.firmwareBuildTime).AppendLine();
                tooltipStr.AppendFormat("Driver: {0}", camInfo.driverName).AppendLine();

                m_tooltipString = tooltipStr.ToString();
                return(m_tooltipString);
            }
        }
Ejemplo n.º 11
0
        static void Main()
        {
            ManagedBusManager busMgr = new ManagedBusManager();

            // Pop up the camera selection dialog
            FlyCapture2Managed.Gui.CameraSelectionDialog camSlnDlg = new FlyCapture2Managed.Gui.CameraSelectionDialog();
            if (camSlnDlg.ShowModal() == false)
            {
                MessageBox.Show("No cameras selected.", "Flycapture2", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            ManagedPGRGuid[] selectedGuids = camSlnDlg.GetSelectedCameraGuids();

            // Only start the first selected camera
            ManagedPGRGuid    guid = selectedGuids[0];
            InterfaceType     ifType;
            ManagedCameraBase camera;

            try
            {
                ifType = busMgr.GetInterfaceTypeFromGuid(guid);//unable to handle this error
            }
            catch (FC2Exception ex)
            {
                string error = string.Format("Failed to get interface for camera. {0}", ex.Message);
                Console.WriteLine(error);
                MessageBox.Show(error, "Flycapture 2", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (ifType == InterfaceType.GigE)
            {
                camera = new ManagedGigECamera();
            }
            else
            {
                camera = new ManagedCamera();
            }
            camera.Connect(guid);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            CameraControlMainFrame mainWindow = new CameraControlMainFrame();

            mainWindow.Connect(camera);
            mainWindow.ShowWindow();
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Create a NFOV camera from its serial number and apply the specified calibration
 /// </summary>
 /// <param name="name">Name of camera in settings</param>
 public NFOV(string name)
 {
     this.serial            = (uint)Program.Settings.json[name]["camera serial"];
     this.Scale             = (double)Program.Settings.json[name]["units / pixel"];
     this.CalibrationHeight = (double)Program.Settings.json[name]["calibration height"];
     this.Recording         = false;
     // Initialize camera object. Connection occurs when initialize() is called
     this.camera = new ManagedGigECamera();
     // Save image dimensions to be used
     this.PixelHeight = (uint)Program.Settings.json[name]["height"];
     this.PixelWidth  = (uint)Program.Settings.json[name]["width"];
     // Initialize images
     this.rawImage       = new ManagedImage();
     this.ProcessedImage = new ManagedImage();
     // Event that occurs when grab thead is exited
     this.grabThreadExited = new AutoResetEvent(false);
 }
Ejemplo n.º 13
0
 protected bool IsPacketResendSupported()
 {
     try
     {
         ManagedGigECamera gigECam = (ManagedGigECamera)m_camera;
         uint regVal = gigECam.ReadGVCPRegister(0x0934);
         if ((regVal & 0x4) != 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 14
0
        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;
                }
            }
        }
Ejemplo n.º 15
0
        private void OnWriteRegBlockButtonClick(object sender, EventArgs e)
        {
            uint numQuadlets = (uint)m_regValueBlock.Rows.Count;

            uint[] regBlockArray = new uint[numQuadlets];

            for (int i = 0; i < (int)numQuadlets; i++)
            {
                string valStr = (string)m_regValueBlock.Rows[i].Cells[1].Value;
                try
                {
                    regBlockArray[i] = Convert.ToUInt32(valStr.Substring(2), 16);
                }
                catch (ArgumentException ex)
                {
                    Debug.WriteLine(ex.Message);
                    MessageBox.Show(
                        "The value is invalid. Please enter a valid hex number.",
                        "Invalid Value",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                    return;
                }
                catch (FormatException ex)
                {
                    Debug.WriteLine(ex.Message);
                    MessageBox.Show(
                        "The value \"" + valStr.Substring(2) + "\" is invalid.",
                        "Invalid Value",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                    return;
                }
                catch (OverflowException ex)
                {
                    Debug.WriteLine(ex.Message);
                    MessageBox.Show(
                        "The value \"" + valStr.Substring(2) + "\" is too large. Please enter a valid register address.",
                        "Invalid Value",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                    return;
                }
            }

            if (m_registerSet == RegisterSet.REGISTER_SET_IIDC)
            {
                try
                {
                    m_camera.WriteRegisterBlock(0xFFFF, m_lastRegBlockOffset + 0xF0F00000, regBlockArray);
                }
                catch (FC2Exception ex)
                {
                    string error = string.Format(
                        "There was an error writing register block {0:x} - {1:x}.",
                        m_lastRegBlockOffset,
                        m_lastRegBlockOffset + (4 * numQuadlets));
                    ShowErrorMessageDialog(error, ex);
                    return;
                }
            }
            else if (m_registerSet == RegisterSet.REGISTER_SET_GEV)
            {
                if (IsGEV() != true)
                {
                    return;
                }

                ManagedGigECamera camera = (ManagedGigECamera)m_camera;
                try
                {
                    camera.WriteGVCPRegisterBlock(m_lastRegBlockOffset, regBlockArray);
                }
                catch (FC2Exception ex)
                {
                    ShowErrorMessageDialog(
                        string.Format(
                            "There was an error writing GVCP register block 0x{0:X8} - 0x{1:X8}.",
                            m_lastRegBlockOffset,
                            m_lastRegBlockOffset + (4 * numQuadlets)),
                        ex);
                }
            }
        }
Ejemplo n.º 16
0
        private void ReadRegisterBlockValueFromCamera()
        {
            // Get the text in the box
            uint regBlockOffset = 0;

            try
            {
                // Get the text in the box
                regBlockOffset = Convert.ToUInt32(m_regBlockEntryTextBox.Text, 16);
            }
            catch (ArgumentException ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                ShowErrorMessageDialog("Invalid argument in function ReadRegisterBlockValueFromCamera().", ex);
                return;
            }
            catch (FormatException ex)
            {
                Debug.WriteLine(ex.Message);
                MessageBox.Show(
                    "Please enter a valid register address.",
                    "Invalid Register Address",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }
            catch (OverflowException ex)
            {
                Debug.WriteLine(ex.Message);
                MessageBox.Show(
                    "The number you entered is too large. Please enter a valid register address.",
                    "Invalid Register Address",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }

            int numQuadlets = Convert.ToInt32(m_numOfQuadletsToReadSpinButton.Value);

            uint[] values = new uint[numQuadlets];
            if (m_registerSet == RegisterSet.REGISTER_SET_IIDC)
            {
                try
                {
                    m_camera.ReadRegisterBlock(0xFFFF, regBlockOffset + 0xF0F00000, values);
                }
                catch (FC2Exception ex)
                {
                    ShowErrorMessageDialog(
                        string.Format(
                            "There was an error reading IIDC register block 0x{0:X8} - 0x{1:X8}.",
                            regBlockOffset,
                            regBlockOffset + (4 * numQuadlets)),
                        ex);
                    return;
                }
            }
            else if (m_registerSet == RegisterSet.REGISTER_SET_GEV)
            {
                if (IsGEV() != true)
                {
                    return;
                }

                ManagedGigECamera camera = (ManagedGigECamera)m_camera;
                try
                {
                    camera.ReadGVCPRegisterBlock(regBlockOffset, values);
                }
                catch (FC2Exception ex)
                {
                    ShowErrorMessageDialog(
                        string.Format(
                            "There was an error reading GVCP register block 0x{0:X8} - 0x{1:X8}.",
                            regBlockOffset,
                            regBlockOffset + (4 * numQuadlets)),
                        ex);
                    return;
                }
            }

            m_lastRegBlockOffset = regBlockOffset;
            m_regValueBlock.Rows.Clear();
            m_updatingDatagridview = true;
            for (int i = 0; i < numQuadlets; i++)
            {
                uint currentRegVal = (uint)(regBlockOffset + (i * 4));
                m_regValueBlock.Rows.Add(new DataGridViewRow());
                m_regValueBlock.Rows[i].Cells[0].Value = string.Format("0x{0:X}", currentRegVal);
                m_regValueBlock.Rows[i].Cells[1].Value = string.Format("0x{0:X8}", values[i]);
                double ieeeVal = MathUtilities.Convert32bitIEEEToFloat(values[i]);
                m_regValueBlock.Rows[i].Cells[2].Value = ieeeVal;
                m_regValueBlock.Rows[i].Cells[3].Value = ManagedCameraBase.GetRegisterString(currentRegVal);
            }
            m_updatingDatagridview = false;
        }
Ejemplo n.º 17
0
        private void OnWriteRegButtonClick(object sender, EventArgs e)
        {
            // Get the text in the box
            uint registerVal = 0;

            try
            {
                // Get the text in the box
                registerVal = Convert.ToUInt32(m_regEntryTextBox.Text, 16);
            }
            catch (ArgumentException ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                ShowErrorMessageDialog("Invalid argument in function OnWriteRegButtonClick().", ex);
                return;
            }
            catch (FormatException ex)
            {
                Debug.WriteLine(ex.Message);
                MessageBox.Show(
                    "Please enter a valid register address.",
                    "Invalid Register Address",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }
            catch (OverflowException ex)
            {
                Debug.WriteLine(ex.Message);
                MessageBox.Show(
                    "The number you entered is too large. Please enter a valid register address.",
                    "Invalid Register Address",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }

            uint value = 0;

            try
            {
                value = GetRegisterValueFromPage();
            }
            catch (ArgumentException ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                ShowErrorMessageDialog("Invalid argument in function ReadRegisterValueFromCamera().", ex);
                return;
            }
            catch (FormatException ex)
            {
                Debug.WriteLine(ex.Message);
                MessageBox.Show(
                    "Register value is invalid.",
                    "Invalid Value",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }
            catch (OverflowException ex)
            {
                Debug.WriteLine(ex.Message);
                MessageBox.Show(
                    "The number you entered is too large. Register value is invalid.",
                    "Invalid Value",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }

            if (m_registerSet == RegisterSet.REGISTER_SET_IIDC)
            {
                try
                {
                    m_camera.WriteRegister(registerVal, value);
                }
                catch (FC2Exception ex)
                {
                    ShowErrorMessageDialog("There was an error writing IIDC register", ex);
                    return;
                }
            }
            else if (m_registerSet == RegisterSet.REGISTER_SET_GEV)
            {
                if (IsGEV() != true)
                {
                    return;
                }

                ManagedGigECamera camera = (ManagedGigECamera)m_camera;
                try
                {
                    camera.WriteGVCPRegister(registerVal, value);
                }
                catch (FC2Exception ex)
                {
                    ShowErrorMessageDialog(
                        string.Format(
                            "There was an error writing GVCP register 0x{0:X8} with the value {1:X8}.",
                            registerVal,
                            value),
                        ex);
                }
            }

            if (registerVal == 0x830 || registerVal == 0x834)
            {
                UpdateGPIOPage(EventArgs.Empty);
            }
        }
Ejemplo n.º 18
0
        private void ReadRegisterValueFromCamera()
        {
            m_isReadingRegister = true;

            // Get the text in the box
            uint registerVal = 0;

            try
            {
                // Get the text in the box
                registerVal = Convert.ToUInt32(m_regEntryTextBox.Text, 16);
            }
            catch (ArgumentException ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                ShowErrorMessageDialog("Invalid argument in function ReadRegisterValueFromCamera().", ex);
                return;
            }
            catch (FormatException ex)
            {
                Debug.WriteLine(ex.Message);
                MessageBox.Show(
                    "Please enter a valid register address.",
                    "Invalid Register Address",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }
            catch (OverflowException ex)
            {
                Debug.WriteLine(ex.Message);
                MessageBox.Show(
                    "The number you entered is too large. Please enter a valid register address.",
                    "Invalid Register Address",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }

            uint value = 0;

            if (m_registerSet == RegisterSet.REGISTER_SET_IIDC)
            {
                try
                {
                    value = m_camera.ReadRegister(registerVal);
                }
                catch (FC2Exception ex)
                {
                    ShowErrorMessageDialog(
                        string.Format(
                            "There was an error reading register 0x{0:X8}.",
                            registerVal),
                        ex);
                    return;
                }
            }
            else if (m_registerSet == RegisterSet.REGISTER_SET_GEV)
            {
                if (IsGEV() != true)
                {
                    return;
                }

                ManagedGigECamera camera = (ManagedGigECamera)m_camera;
                try
                {
                    value = camera.ReadGVCPRegister(registerVal);
                }
                catch (FC2Exception ex)
                {
                    ShowErrorMessageDialog(
                        string.Format(
                            "There was an error reading GVCP register 0x{0:X8}.",
                            registerVal),
                        ex);
                    return;
                }
            }

            SetRegisterValueToPage(value);
            UpdateIEEE754TextBox();
            m_isReadingRegister = false;
        }
Ejemplo n.º 19
0
        public void UpdateGigECameraInformation(CameraInfo cameraInfo)
        {
            if (m_camera == null || m_camera.IsConnected() == false)
            {
                Debug.WriteLine("Camera not found or disconnected");
                return;
            }

            if (cameraInfo.interfaceType != InterfaceType.GigE)
            {
                string blankStr = "N/A";
                m_versionValue.Text        = blankStr;
                m_userDefNameValue.Text    = blankStr;
                m_xmlURL1Value.Text        = blankStr;
                m_xmlURL2Value.Text        = blankStr;
                m_macAddressValue.Text     = blankStr;
                m_ipValue.Text             = blankStr;
                m_subnetMaskValue.Text     = blankStr;
                m_defaultGatewayValue.Text = blankStr;

                m_lblLLAStatus.Text          = blankStr;
                m_lblDHCPStatus.Text         = blankStr;
                m_lblPersistentIPStatus.Text = blankStr;

                return;
            }

            m_versionValue.Text     = string.Format("{0}.{1}", cameraInfo.gigEMajorVersion, cameraInfo.gigEMinorVersion);
            m_userDefNameValue.Text = cameraInfo.userDefinedName;
            m_xmlURL1Value.Text     = cameraInfo.xmlURL1;
            m_xmlURL2Value.Text     = cameraInfo.xmlURL2;
            byte[] macAddrBytes = cameraInfo.macAddress.GetAddressBytes();
            m_macAddressValue.Text = string.Format(
                "{0:X2}:{1:X2}:{2:X2}:{3:X2}:{4:X2}:{5:X2}",
                macAddrBytes[0],
                macAddrBytes[1],
                macAddrBytes[2],
                macAddrBytes[3],
                macAddrBytes[4],
                macAddrBytes[5]);
            m_ipValue.Text             = cameraInfo.ipAddress.ToString();
            m_subnetMaskValue.Text     = cameraInfo.subnetMask.ToString();
            m_defaultGatewayValue.Text = cameraInfo.defaultGateway.ToString();

            m_ipValue.ForeColor             = Color.Black;
            m_subnetMaskValue.ForeColor     = Color.Black;
            m_defaultGatewayValue.ForeColor = Color.Black;

            m_tooltip.RemoveAll();

            try
            {
                ManagedGigECamera gigECam = (ManagedGigECamera)m_camera;
                uint ipConfigurationVal   = gigECam.ReadGVCPRegister(0x0014);
                m_lblLLAStatus.Text          = string.Format("{0}", (ipConfigurationVal & 0x4) != 0 ? "Enabled" : "Disabled");
                m_lblDHCPStatus.Text         = string.Format("{0}", (ipConfigurationVal & 0x2) != 0 ? "Enabled" : "Disabled");
                m_lblPersistentIPStatus.Text = string.Format("{0}", (ipConfigurationVal & 0x1) != 0 ? "Enabled" : "Disabled");
            }
            catch (InvalidCastException)
            {
                Debug.WriteLine("Camera is not a GigE camera");
            }
            catch (FC2Exception ex)
            {
                Debug.WriteLine("Failed to read IP configuration status: " + ex.Message);
            }
        }
Ejemplo n.º 20
0
        void RunSingleCamera(ManagedPGRGuid guid)
        {
            const int k_numImages = 10;

            ManagedGigECamera cam = new ManagedGigECamera();

            // Connect to a camera
            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();
            PrintCameraInfo(camInfo);

            uint numStreamChannels = cam.GetNumStreamChannels();
            for (uint i=0; i < numStreamChannels; i++)
            {
                PrintStreamChannelInfo(cam.GetGigEStreamChannelInfo(i));
            }

            GigEImageSettingsInfo imageSettingsInfo = cam.GetGigEImageSettingsInfo();

            GigEImageSettings imageSettings = new GigEImageSettings();
            imageSettings.offsetX = 0;
            imageSettings.offsetY = 0;
            imageSettings.height = imageSettingsInfo.maxHeight;
            imageSettings.width = imageSettingsInfo.maxWidth;
            imageSettings.pixelFormat = PixelFormat.PixelFormatMono8;

            cam.SetGigEImageSettings(imageSettings);

            // Get embedded image info from camera
            EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();

            // Enable timestamp collection
            if (embeddedInfo.timestamp.available == true)
            {
                embeddedInfo.timestamp.onOff = true;
            }

            // Set embedded image info to camera
            cam.SetEmbeddedImageInfo(embeddedInfo);

            // Start capturing images
            cam.StartCapture();

            ManagedImage rawImage = new ManagedImage();
            for (int imageCnt = 0; imageCnt < k_numImages; imageCnt++)
            {
                // Retrieve an image
                cam.RetrieveBuffer(rawImage);

                // Get the timestamp
                TimeStamp timeStamp = rawImage.timeStamp;

                Console.WriteLine(
                   "Grabbed image {0} - {1} {2} {3}",
                   imageCnt,
                   timeStamp.cycleSeconds,
                   timeStamp.cycleCount,
                   timeStamp.cycleOffset);

                // Create a converted image
                ManagedImage convertedImage = new ManagedImage();

                // Convert the raw image
                rawImage.Convert(PixelFormat.PixelFormatBgr, convertedImage);

                // Create a unique filename
                string filename = String.Format(
                   "GigEGrabEx_CSharp-{0}-{1}.bmp",
                   camInfo.serialNumber,
                   imageCnt);

                // Get the Bitmap object. Bitmaps are only valid if the
                // pixel format of the ManagedImage is RGB or RGBU.
                System.Drawing.Bitmap bitmap = convertedImage.bitmap;

                // Save the image
                bitmap.Save(filename);
            }

            // Stop capturing images
            cam.StopCapture();

            // Disconnect the camera
            cam.Disconnect();
        }
Ejemplo n.º 21
0
        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 (badCamera)
            {
                try
                {
                    CameraInfo camInfo;
                    m_badCameraInfo.TryGetValue(m_cameraDataGridView.Rows[rowIndex].Cells[0].Value.ToString(), out camInfo);
                    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();

                    ////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;
                    }

                    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;
                    }
                }
                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;
                }
            }
        }
Ejemplo n.º 22
0
        void RunSingleCamera(ManagedPGRGuid guid)
        {
            const int k_numImages = 10;

            ManagedGigECamera cam = new ManagedGigECamera();

            // Connect to a camera
            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();

            PrintCameraInfo(camInfo);

            uint numStreamChannels = cam.GetNumStreamChannels();

            for (uint i = 0; i < numStreamChannels; i++)
            {
                PrintStreamChannelInfo(cam.GetGigEStreamChannelInfo(i));
            }

            GigEImageSettingsInfo imageSettingsInfo = cam.GetGigEImageSettingsInfo();

            GigEImageSettings imageSettings = new GigEImageSettings();

            imageSettings.offsetX     = 0;
            imageSettings.offsetY     = 0;
            imageSettings.height      = imageSettingsInfo.maxHeight;
            imageSettings.width       = imageSettingsInfo.maxWidth;
            imageSettings.pixelFormat = PixelFormat.PixelFormatMono8;

            cam.SetGigEImageSettings(imageSettings);

            // Get embedded image info from camera
            EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();

            // Enable timestamp collection
            if (embeddedInfo.timestamp.available == true)
            {
                embeddedInfo.timestamp.onOff = true;
            }

            // Set embedded image info to camera
            cam.SetEmbeddedImageInfo(embeddedInfo);

            // Start capturing images
            cam.StartCapture();

            ManagedImage rawImage = new ManagedImage();

            for (int imageCnt = 0; imageCnt < k_numImages; imageCnt++)
            {
                // Retrieve an image
                cam.RetrieveBuffer(rawImage);

                // Get the timestamp
                TimeStamp timeStamp = rawImage.timeStamp;

                Console.WriteLine(
                    "Grabbed image {0} - {1} {2} {3}",
                    imageCnt,
                    timeStamp.cycleSeconds,
                    timeStamp.cycleCount,
                    timeStamp.cycleOffset);

                // Create a converted image
                ManagedImage convertedImage = new ManagedImage();

                // Convert the raw image
                rawImage.Convert(PixelFormat.PixelFormatBgr, convertedImage);

                // Create a unique filename
                string filename = String.Format(
                    "GigEGrabEx_CSharp-{0}-{1}.bmp",
                    camInfo.serialNumber,
                    imageCnt);

                // Get the Bitmap object. Bitmaps are only valid if the
                // pixel format of the ManagedImage is RGB or RGBU.
                System.Drawing.Bitmap bitmap = convertedImage.bitmap;

                // Save the image
                bitmap.Save(filename);
            }

            // Stop capturing images
            cam.StopCapture();

            // Disconnect the camera
            cam.Disconnect();
        }