Exemple #1
0
 public override uint GetGain()
 {
     lock (m_lock)
     {
         uint _gain = 0;
         if (camera != null)
         {
             if (camera.IsOpen)
             {
                 IFloatParameter parameter = null;
                 if (camera.Parameters.Contains(PLCamera.GainAbs))
                 {
                     parameter = camera.Parameters[PLCamera.GainAbs];
                 }
                 else
                 {
                     parameter = camera.Parameters[PLCamera.Gain];
                 }
                 if (parameter.IsReadable)
                 {
                     _gain = (uint)parameter.GetValue();
                 }
             }
         }
         return(_gain);
     }
 }
Exemple #2
0
 public override void SetGain(uint g)
 {
     lock (m_lock)
     {
         if (camera != null)
         {
             if (camera.IsOpen)
             {
                 IFloatParameter parameter = null;
                 if (camera.Parameters.Contains(PLCamera.GainAbs))
                 {
                     parameter = camera.Parameters[PLCamera.GainAbs];
                 }
                 else
                 {
                     parameter = camera.Parameters[PLCamera.Gain];
                 }
                 if (parameter.IsWritable)
                 {
                     parameter.SetValue(g);
                 }
             }
         }
     }
 }
Exemple #3
0
 public override uint GetExpourseTime()
 {
     lock (m_lock)
     {
         uint _expourestime = 0;
         if (camera != null)
         {
             if (camera.IsOpen)
             {
                 IFloatParameter parameter = null;
                 if (camera.Parameters.Contains(PLCamera.ExposureTimeAbs))
                 {
                     parameter = camera.Parameters[PLCamera.ExposureTimeAbs];
                 }
                 else
                 {
                     parameter = camera.Parameters[PLCamera.ExposureTime];
                 }
                 if (parameter.IsReadable)
                 {
                     _expourestime = (uint)parameter.GetValue();
                 }
             }
         }
         return(_expourestime);
     }
 }
Exemple #4
0
 /// <summary>
 /// 设置曝光
 /// </summary>
 /// <param name="et"></param>
 public void SetExposureTime(string et)
 {
     using (IFloatParameter p = objDev.ParameterCollection[ParametrizeNameSet.ExposureTime])
     {
         p.SetValue(double.Parse(et));
     }
 }
Exemple #5
0
        /// <summary>
        /// 设置相机曝光
        /// </summary>
        /// <param name="IDa"></param>
        /// <param name="exposuretime"></param>
        /// <param name="gainraw"></param>
        /// <returns></returns>
        public bool set_exposuretime_gainraw(IDaHua IDa, double exposuretime, double gainraw)
        {
            bool ok = false;

            if (exposuretime != 0)
            {
                /* 设置曝光 */
                using (IFloatParameter p = IDa.Dev.ParameterCollection[ParametrizeNameSet.ExposureTime])
                {
                    p.SetValue(exposuretime);
                }
            }

            if (gainraw != 0)
            {
                /* 设置增益 */
                using (IFloatParameter p = IDa.Dev.ParameterCollection[ParametrizeNameSet.GainRaw])
                {
                    p.SetValue(1.0);
                }
            }
            Save_DaHua_ShuJu(IDa);

            ok = true;
            return(ok);
        }
Exemple #6
0
        public override void SetExpourseTime(uint t)
        {
            lock (m_lock)
            {
                if (camera != null)
                {
                    if (camera.IsOpen)
                    {
                        IFloatParameter parameter = null;

                        if (camera.Parameters.Contains(PLCamera.ExposureTimeAbs))
                        {
                            parameter = camera.Parameters[PLCamera.ExposureTimeAbs];
                        }
                        else
                        {
                            parameter = camera.Parameters[PLCamera.ExposureTime];
                        }
                        if (parameter.IsWritable)
                        {
                            parameter.SetValue(t);
                        }
                    }
                }
            }
        }
Exemple #7
0
 /// <summary>
 /// 设置增益
 /// </summary>
 /// <param name="gainRaw"></param>
 public void SetGainRaw(string gainRaw)
 {
     using (IFloatParameter p = objDev.ParameterCollection[ParametrizeNameSet.GainRaw])
     {
         p.SetValue(double.Parse(gainRaw));
     }
 }
Exemple #8
0
        public override bool SetTriggerDelay(double value)
        {
            using (IFloatParameter p = m_dev.ParameterCollection[ParametrizeNameSet.TriggerDelay])

            {
                return(p.SetValue(value));
            }
        }
Exemple #9
0
 /// <summary>
 /// 获取增益
 /// </summary>
 /// <returns></returns>
 public string GetGainRaw()
 {
     {
         using (IFloatParameter p = objDev.ParameterCollection[new FloatName("GainRaw")])
         {
             Trace.WriteLine(string.Format("ExposureTime value: {0}", p.GetValue()));
             return(p.GetValue().ToString());
         }
     }
 }
Exemple #10
0
 public void SetExposureClock(int CameraID, uint Value)
 {
     if (SelectCameraCompany == 0 && m_Camera[CameraID] != null)
     {
         m_Camera[CameraID].ExposureClock = Value;
     }
     else if (SelectCameraCompany == 1 && selectDevHandle[CameraID] != -1)
     {
         using (IFloatParameter p = m_dev[CameraID].ParameterCollection[ParametrizeNameSet.ExposureTime])
         {
             p.SetValue(Value);
         }
     }
 }
Exemple #11
0
 public void SetGain(int CameraID, ushort Value)
 {
     if (SelectCameraCompany == 0 && m_Camera[CameraID] != null)
     {
         m_Camera[CameraID].Gain = Value;
     }
     else if (SelectCameraCompany == 1 && selectDevHandle[CameraID] != -1)
     {
         using (IFloatParameter p = m_dev[CameraID].ParameterCollection[ParametrizeNameSet.GainRaw])
         {
             p.SetValue(Value);
         }
     }
 }
Exemple #12
0
        public override double GetTriggerDelayTimeMin()  // 获取最小触发延迟
        {
            try
            {
                using (IFloatParameter p = m_dev.ParameterCollection[ParametrizeNameSet.TriggerDelay])

                {
                    return(p.GetMinimum());
                }
            }
            catch (Exception)
            {
                return(0);
            }
        }
Exemple #13
0
        public override double GetExposureTime()   // 获取曝光时间
        {
            try
            {
                using (IFloatParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ExposureTime])

                {
                    return(p.GetValue());
                }
            }
            catch (Exception)
            {
                return(0);
            }
        }
Exemple #14
0
        public override bool SetGain(double value)
        {
            try
            {
                using (IFloatParameter p = m_dev.ParameterCollection[ParametrizeNameSet.GainRaw])

                {
                    return(p.SetValue(value));
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #15
0
        public override double GetMinGain()  // 获取最小增益
        {
            try
            {
                using (IFloatParameter p = m_dev.ParameterCollection[ParametrizeNameSet.GainRaw])

                {
                    return(p.GetMinimum());
                }
            }
            catch (Exception)
            {
                return(0);
            }
        }
        // 打开相机
        private void btnOpen_Click(object sender, EventArgs e)
        {
            try
            {
                // 设备搜索
                List <IDeviceInfo> li = Enumerator.EnumerateDevices();
                if (li.Count > 0)
                {
                    // 获取搜索到的第一个设备
                    m_dev = Enumerator.GetDeviceByIndex(0);

                    // 注册链接时间
                    m_dev.CameraOpened   += OnCameraOpen;
                    m_dev.ConnectionLost += OnConnectLoss;
                    m_dev.CameraClosed   += OnCameraClose;

                    // 打开设备
                    if (!m_dev.Open())
                    {
                        MessageBox.Show(@"连接相机失败");
                        return;
                    }

                    // 打开Software Trigger
                    m_dev.TriggerSet.Open(TriggerSourceEnum.Software);

                    // 设置图像格式
                    using (IEnumParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ImagePixelFormat])
                    {
                        p.SetValue("BayerRG12Packed");
                    }
                    // 设置图片亮度
                    using (IIntegraParameter p = m_dev.ParameterCollection[ParametrizeNameSet.Brightness])
                    {
                        p.SetValue(100);
                    }
                    //设置曝光时间
                    using (IFloatParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ExposureTime])
                    {
                        p.SetValue(50000);
                    }

                    /*
                     * // 设置图片高度
                     * using (IIntegraParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ImageHeight])
                     * {
                     *  p.SetValue(600);
                     * }
                     * // 设置图片宽度
                     * using (IIntegraParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ImageWidth])
                     * {
                     *  p.SetValue(600);
                     * }
                     */

                    // 注册码流回调事件
                    m_dev.StreamGrabber.ImageGrabbed += OnImageGrabbed;

                    // 开启码流
                    if (!m_dev.GrabUsingGrabLoopThread())
                    {
                        MessageBox.Show(@"开启码流失败");
                        return;
                    }

                    m_dev.ExecuteSoftwareTrigger();
                }
            }
            catch (Exception exception)
            {
                Catcher.Show(exception);
            }
        }
Exemple #17
0
        /* 打开相机按钮事件 */
        private void btnOpen_Click(object sender, EventArgs e)
        {
            try
            {
                /* 设备搜索 */
                List <IDeviceInfo> li = Enumerator.EnumerateDevices();
                if (li.Count > 0)
                {
                    /* 获取搜索到的第一个设备 */
                    m_dev = Enumerator.GetDeviceByIndex(0);

                    /* 注册链接时间 */
                    m_dev.CameraOpened   += OnCameraOpen;
                    m_dev.ConnectionLost += OnConnectLoss;
                    m_dev.CameraClosed   += OnCameraClose;

                    /* 打开设备 */
                    if (!m_dev.Open())
                    {
                        MessageBox.Show(@"连接相机失败");
                        return;
                    }

                    /* 打开Software Trigger */
                    if (bVideoMode)
                    {
                        m_dev.TriggerSet.Close();
                    }
                    else
                    {
                        m_dev.TriggerSet.Open(TriggerSourceEnum.Software);
                    }

                    /* 设置图像格式 */
                    using (IEnumParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ImagePixelFormat])
                    {
                        p.SetValue("Mono8");
                    }

                    /* 设置曝光 */
                    using (IFloatParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ExposureTime])
                    {
                        p.SetValue(nExpTime);
                    }

                    /* 设置增益 */
                    using (IFloatParameter p = m_dev.ParameterCollection[ParametrizeNameSet.GainRaw])
                    {
                        p.SetValue(fCamGain);
                    }

                    /* 设置缓存个数为8(默认值为16) */
                    m_dev.StreamGrabber.SetBufferCount(8);

                    /* 注册码流回调事件 */
                    m_dev.StreamGrabber.ImageGrabbed += OnImageGrabbed;

                    /* 开启码流 */
                    if (!m_dev.GrabUsingGrabLoopThread())
                    {
                        MessageBox.Show(@"开启码流失败");
                        return;
                    }
                }
            }
            catch (Exception exception)
            {
                Catcher.Show(exception);
            }
        }
Exemple #18
0
        /// <summary>
        /// 打开一个相机驱动,
        /// </summary>
        /// <param name="IDa"></param>
        /// <param name="camer_number"></param>
        /// <param name="CameraOpened"></param>
        /// <param name="CameraClosed"></param>
        /// <param name="event_OnConnectLoss"></param>
        /// <param name="event_OnImageGrabbed"></param>
        /// <param name="result"></param>
        public void open_camer(IDaHua IDa, int camer_number, EventHandler <EventArgs> CameraOpened,
                               EventHandler <EventArgs> CameraClosed, delegate_OnConnectLoss event_OnConnectLoss
                               , ref string result)
        {
            try
            {
                int number = 0;
                get_camer_number(ref number);
                if (number > 0)
                {
                    if (camer_number < number)
                    {
                        #region 检测打开的相机是否有配置的数据
                        #region  无用代码
                        //string filename="Camer" + camer_number.ToString();
                        //Config.IniFile.IniFiles inifiles = new Config.IniFile.IniFiles(ref filename,"DaHua", null);
                        //if (File.Exists(inifiles.FileName_Path1))
                        //{
                        //    IDa.CamerIndx1 = Convert.ToInt16(inifiles.ReadString(IDa.ToString(), "CamerIndx1", IDa.CamerIndx1.ToString()));
                        //    IDa.TriggerSourceenum= inifiles.ReadString(IDa.ToString(), "TriggerSourceenum", IDa.TriggerSourceenum);
                        //    IDa.Exposuretime=Convert.ToDouble(inifiles.ReadString(IDa.ToString(), "Exposuretime", IDa.Exposuretime.ToString()));
                        //    IDa.Gainraw=Convert.ToDouble(inifiles.ReadString(IDa.ToString(), "Gainraw", IDa.Gainraw.ToString()));
                        //}
                        //else
                        //{
                        //    inifiles.WriteString(IDa.ToString(), "CamerIndx1", camer_number.ToString());
                        //    inifiles.WriteString(IDa.ToString(), "TriggerSourceenum", IDa.TriggerSourceenum);
                        //    inifiles.WriteString(IDa.ToString(), "Exposuretime", IDa.Exposuretime.ToString());
                        //    inifiles.WriteString(IDa.ToString(), "Gainraw", IDa.Gainraw.ToString());
                        //}
                        #endregion
                        load_DaHua_ShuJu(IDa, camer_number);
                        #endregion
                        IDa.Dev = Enumerator.GetDeviceByIndex(camer_number);
                        // 注册链接时间

                        if (CameraOpened != null)
                        {
                            IDa.Dev.CameraOpened += CameraOpened;
                        }

                        IDa.Dev.ConnectionLost += IDa.OnConnectLoss;;

                        if (CameraClosed != null)
                        {
                            IDa.Dev.CameraClosed += CameraClosed;
                        }

                        if (event_OnConnectLoss != null)
                        {
                            IDa.event_OnConnectLoss += event_OnConnectLoss;
                        }

                        //if (event_OnImageGrabbed != null)
                        //{
                        //    IDa.event_OnImageGrabbed += event_OnImageGrabbed;
                        //}

                        // 打开设备
                        if (!IDa.Dev.Open())
                        {
                            result = "设备打开失败";
                            return;
                        }

                        // 打开Software Trigger
                        // IDa.Dev.TriggerSet.Open(TriggerSourceEnum.Line1);

                        IDa.Dev.TriggerSet.Open(IDa.TriggerSourceenum);

                        /* 设置图像格式 */
                        using (IEnumParameter p = IDa.Dev.ParameterCollection[ParametrizeNameSet.ImagePixelFormat])
                        {
                            p.SetValue("Mono8");
                        }

                        /* 设置曝光 */
                        using (IFloatParameter p = IDa.Dev.ParameterCollection[ParametrizeNameSet.ExposureTime])
                        {
                            p.SetValue(IDa.Exposuretime);
                        }

                        /* 设置增益 */
                        using (IFloatParameter p = IDa.Dev.ParameterCollection[ParametrizeNameSet.GainRaw])
                        {
                            p.SetValue(IDa.Gainraw);
                        }

                        /* 设置缓存个数为8(默认值为16) */
                        IDa.Dev.StreamGrabber.SetBufferCount(8);

                        // 注册码流回调事件
                        //    IDa.Dev.StreamGrabber.ImageGrabbed +=IDa.OnImageGrabbed;

                        /* 开启码流 */
                        if (!IDa.Dev.GrabUsingGrabLoopThread())
                        {
                            MessageBox.Show(@"开启码流失败");
                            return;
                        }
                    }
                    else
                    {
                        result = "绑定相机number大于相机实际个数";
                    }
                }
                else
                {
                    result = "相机驱动个数为零";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("打开相机报错:" + ex.Message, this.ToString());
            }
        }