Exemplo n.º 1
0
        /// <summary>
        /// Attempt to connect to camera
        /// </summary>
        /// <returns>True if connection is successful</returns>
        public bool Initialize()
        {
            ManagedBusManager busMgr = new ManagedBusManager();

            try
            {
                ManagedPGRGuid guid = busMgr.GetCameraFromSerialNumber(this.serial);
                this.camera.Connect(guid);
                GigEImageSettings config = this.camera.GetGigEImageSettings();
                config.height  = this.PixelHeight;
                config.width   = this.PixelWidth;
                config.offsetX = (2448 - this.PixelWidth) / 2;
                config.offsetY = (2048 - this.PixelHeight) / 2;
                this.camera.SetGigEImageSettings(config);
            }
            catch (Exception ex)
            {
                // Connection unsuccessful
                Logger.Out(ex.ToString());
                this.Connected = false;
                return(false);
            }
            // Set embedded timestamp to on
            EmbeddedImageInfo embeddedInfo = this.camera.GetEmbeddedImageInfo();

            embeddedInfo.timestamp.onOff = true;
            this.camera.SetEmbeddedImageInfo(embeddedInfo);
            // Start live capture
            this.Connected = true;
            this.Start();
            return(true);
        }
Exemplo n.º 2
0
        private bool GetPGRGuidFromRowIndex(int rowIndex, out ManagedPGRGuid guid)
        {
            uint cameraSerialNumber = 0;

            if (m_cameraDataGridView.Rows[rowIndex].Cells[0].Value == null)
            {
                Debug.WriteLine("Unable to get camera information. Nothing in row: " + rowIndex);
                guid = new ManagedPGRGuid();
                return(false);
            }

            try
            {
                cameraSerialNumber = Convert.ToUInt32(m_cameraDataGridView.Rows[rowIndex].Cells[0].Value);
            }
            catch (ArgumentException ex)
            {
                Debug.WriteLine("Invalid serial number.");
                Debug.WriteLine(ex.Message);
                guid = new ManagedPGRGuid();
                return(false);
            }
            catch (FormatException ex)
            {
                Debug.WriteLine("Invalid format for serial number.");
                Debug.WriteLine(ex.Message);
                guid = new ManagedPGRGuid();
                return(false);
            }
            catch (OverflowException ex)
            {
                Debug.WriteLine("The serial number is too long.");
                Debug.WriteLine(ex.Message);
                guid = new ManagedPGRGuid();
                return(false);
            }

            try
            {
                guid = m_busMgr.GetCameraFromSerialNumber(cameraSerialNumber);
            }
            catch (FC2Exception ex)
            {
                Debug.WriteLine("The camera with serial number not found.");
                Debug.WriteLine(ex.Message);
                guid = new ManagedPGRGuid();
                ex.Dispose();
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        private void InitializePage()
        {
            m_busMgr      = new ManagedBusManager();
            m_imageWidth  = m_drawingArea.Width;
            m_imageHeight = m_drawingArea.Height;
            ResetNodeInformation();
            OnRefreshTopology();
            SetColors();

            if (m_camInfo != null)
            {
                m_currCameraGuid = m_busMgr.GetCameraFromSerialNumber(m_camInfo.serialNumber);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 连接相机
        /// </summary>
        /// <param name="SerialNumber"></param>
        /// <returns></returns>
        bool ConnectCamera(string SerialNumber)
        {
            try
            {
#if (SDK)
                ManagedBusManager busMgr = new ManagedBusManager();
                //相机索引号
                uint           intSerialNumber = uint.Parse(SerialNumber);
                ManagedPGRGuid guid            = busMgr.GetCameraFromSerialNumber(intSerialNumber);
                InterfaceType  Type            = busMgr.GetInterfaceTypeFromGuid(guid);

                if (Type == InterfaceType.GigE)
                {
                    g_ManagedCameraBase = new ManagedGigECamera();
                    g_ManagedCameraBase.Connect(guid);

                    SetGigEPacketResend();//设置丢帧重传
                }
                else
                {
                    g_ManagedCameraBase = new ManagedCamera();
                    g_ManagedCameraBase.Connect(guid);
                }

                if (g_BaseParCamera.BlUsingTrigger)
                {
                    SetSoftTrriger(true);//设置触发
                }
#endif
                return(true);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(false);
            }
        }
Exemplo n.º 6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //MessageBox.Show("VS2013");

            textBox1.Text            = Properties.Settings.Default.mirrorAngleStep;
            textBox2.Text            = Properties.Settings.Default.mirrorAngle;
            textBoxDCMotorTime.Text  = Properties.Settings.Default.motorTime;
            textBoxDCMotor2Time.Text = Properties.Settings.Default.motor2Time;



            Directory.CreateDirectory(savepath);
            Directory.CreateDirectory(savepath + "\\SavedMaxima\\");
            PulseStopWatch.Start();

            comboBox1.Items.Clear();


            foreach (string item in System.IO.Ports.SerialPort.GetPortNames())
            {
                comboBox1.Items.Add(item);
            }
            //comboBox1.SelectedItem = Properties.Settings.Default.myserialport;
            try
            {
                comboBox1.SelectedItem = comboBox1.Items[0];
            }
            catch
            {
            }


            My_count = 0;
            Hide();
            //CameraSelectionDialog camSlnDlg = new CameraSelectionDialog();
            //bool retVal = camSlnDlg.ShowModal();
            //if (retVal)
            if (true)
            {
                try
                {
                    //ManagedPGRGuid[] selectedGuids = camSlnDlg.GetSelectedCameraGuids();
                    //ManagedPGRGuid guidToUse = selectedGuids[0];

                    ManagedBusManager busMgr = new ManagedBusManager();

                    /*InterfaceType ifType = busMgr.GetInterfaceTypeFromGuid(guidToUse);
                     * if (ifType == InterfaceType.GigE)
                     * {
                     *  m_camera = new ManagedGigECamera();
                     * }
                     * else
                     * {
                     *  m_camera = new ManagedCamera();
                     * }*/

                    m_camera = new ManagedCamera();

                    // Connect to the first selected GUID
                    //m_camera.Connect(guidToUse);
                    uint           serial1 = busMgr.GetCameraSerialNumberFromIndex(0);
                    ManagedPGRGuid guid    = busMgr.GetCameraFromSerialNumber(serial1);
                    m_camera.Connect(guid);
                    m_camCtlDlg.Connect(m_camera);

                    CameraInfo camInfo = m_camera.GetCameraInfo();
                    UpdateFormCaption(camInfo);

                    // Set embedded timestamp to on
                    EmbeddedImageInfo embeddedInfo = m_camera.GetEmbeddedImageInfo();
                    embeddedInfo.timestamp.onOff = true;
                    m_camera.SetEmbeddedImageInfo(embeddedInfo);

                    m_camera.StartCapture();

                    m_grabImages = true;

                    StartGrabLoop();
                }
                catch (FC2Exception ex)
                {
                    //MessageBox.Show("Camera not detected. Make sure you have connected a camera");
                    label14.Show();

                    Debug.WriteLine("Failed to load form successfully: " + ex.Message);
                    // Environment.ExitCode = -1;
                    //Application.Exit();
                    //return;
                }



                toolStripButtonStart.Enabled = false;
                toolStripButtonStop.Enabled  = true;
            }
            else
            {
                Environment.ExitCode = -1;
                Application.Exit();
                return;
            }

            Show();

            chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
            chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
            // chart1.ChartAreas[0].AxisY.
            //chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.Gray;
            //chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.Gray;
            chart1.Series[0].BorderWidth = 3;

            /*
             * if (checkBoxGraph.Checked) { timerGraph.Start(); }
             * else { timerGraph.Stop(); }*/
        }