Esempio n. 1
0
        /// <summary>
        /// Acquisition mode combo box changed. Propagate to device.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void modeComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Nothing selected? Unexpected, just do nothing...
            if (modeComboBox.SelectedIndex < 0)
            {
                return;
            }

            PvGenEnum lMode = mDevice.Parameters.GetEnum("AcquisitionMode");

            // Take selection, propagate to parameter
            string lSelected = (string)modeComboBox.SelectedItem;

            lMode.ValueString = lSelected;
        }
Esempio n. 2
0
        /// <summary>
        /// Acquisition mode event handler in main thread.
        /// </summary>
        private void OnAcquisitionModeChanged()
        {
            // Get parameter
            PvGenEnum lParameter = mDevice.Parameters.GetEnum("AcquisitionMode");

            // Update value: find which matches in the combo box
            string lValue = lParameter.ValueString;

            foreach (string lString in modeComboBox.Items)
            {
                if (lValue == lString)
                {
                    modeComboBox.SelectedValue = lString;
                }
            }
        }
Esempio n. 3
0
        //#region   设置相机增益
        ///// <summary>
        ///// 设置相机增益
        ///// </summary>
        ///// <returns></returns>
        //public bool Set_Gain(IE2VCamer_ShuJu IE2VCamer_, string zengYi_)
        //{
        //    bool ok = false;

        //    try
        //    {
        //        double num_ = Convert.ToDouble(zengYi_);
        //        IE2VCamer_.MDevice.Parameters.SetFloatValue("Gain", num_);
        //        ok = true;
        //    }
        //    catch(Exception ex)
        //    {
        //        MessageBox.Show("设置相机增益出错");
        //    }
        //        return ok;
        //}
        //#endregion
        #endregion

        #region  设置触发模式
        /// <summary>
        /// 设置触发模式
        /// </summary>
        /// <param name="IE2VCamer_"></param>
        /// <returns></returns>
        public bool Set_Trigger(IE2VCamer_ShuJu IE2VCamer_, string strTrigger)
        {
            bool ok = false;

            try
            {
                PvGenEnum lMode = IE2VCamer_.MDevice.Parameters.GetEnum("AcquisitionMode");
                lMode.ValueString = strTrigger;
            }
            catch (Exception ex)
            {
                MessageBox.Show("设置触发模式出错:" + ex.Message);
            }

            ok = true;
            return(ok);
        }
Esempio n. 4
0
        /// <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();
        }