Exemplo n.º 1
0
        public List <string> ListCameraKeys()
        {
            List <IDeviceInfo> devices = Enumerator.EnumerateDevices();

            List <string> devKeys = devices.Select(di => di.Key).ToList();

            return(devKeys);
        }
Exemplo n.º 2
0
        private void Form_equipment_Load(object sender, EventArgs e)
        {
            //设备搜索
            List <IDeviceInfo> li = Enumerator.EnumerateDevices();

            if (li.Count > 0)
            {
                //禁用列表的自动生成
                dgvList.AutoGenerateColumns = true;
                dgvList.DataSource          = new BindingList <IDeviceInfo>(li);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 枚举设备
        /// </summary>
        /// <returns></returns>
        public bool EnumDevice()
        {
            // 设备搜索
            // device search
            li = Enumerator.EnumerateDevices();

            if (li.Count == 0)
            {
                return(false);
            }
            else
            {
                for (int i = 0; i < li.Count; i++)
                {
                    Dahua objCamera = new Dahua();
                    objCamera.strName = li[i].Key;
                    listCamera.Add(objCamera);//添加相机列队
                }
                return(true);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 初始化设备层
        /// </summary>
        /// <param name="num">初始化相机数量</param>
        /// <param name="protocol">重量采集协议</param>
        public bool Initialization(int num, string protocol)
        {
            MvBarCode.MvBarCodeGlobalVar.Log.Info("抵达设备层初始化");

            //不是离线模式才去发现设备
            if (!MvBarCode.MvBarCodeGlobalVar.LocalImageMode)
            {
                // 搜索设备
                List <IDeviceInfo> li = Enumerator.EnumerateDevices();
                if (li.Count < num)
                {
                    MvBarCode.MvBarCodeGlobalVar.Log.ErrorFormat("初始化失败,实际发现设备:{0},计划发现设备:{1}", li.Count.ToString(), num.ToString());
                    return(false);
                }
            }
            else
            {
                MvBarCode.MvBarCodeGlobalVar.Log.Info("离线模式:初始化设备");
            }

            // 初始化相机
            if (_BarCodeCamera == null)
            {
                // 按照索引号初始化相机
                _BarCodeCamera = new BarCodeCamera[num];
            }

            // 初始化相机组中的相机对象
            for (var i = 0; i < num; ++i)
            {
                if (_BarCodeCamera[i] == null)
                {
                    _BarCodeCamera[i] = new BarCodeCamera(i);
                }
            }

            // 初始化电子秤
            if (_Scale == null)
            {
                _Scale = ScaleBase.GetScale(protocol);
                if (_Scale == null)
                {
                    MvBarCode.MvBarCodeGlobalVar.Log.ErrorFormat("scale为null,初始化失败");
                    return(false);
                }

                // 控制采样数量
                _Scale.SampleNum = 4;

                // 控制采样精度
                _Scale.MaxDeviation = 0.03;

                StringBuilder builder = new StringBuilder(128);
                GetPrivateProfileString("WeightParam", "SampleNum", "4", builder, 128, Environment.CurrentDirectory + "\\config.ini");
                int result;
                int.TryParse(builder.ToString(), out result);
                if (result > 4)
                {
                    _Scale.SampleNum = result;
                }

                GetPrivateProfileString("WeightParam", "MaxDeviation", "0.03", builder, 128, Environment.CurrentDirectory + "\\config.ini");
                double result2;
                double.TryParse(builder.ToString(), out result2);
                if (result2 > 0)
                {
                    _Scale.MaxDeviation = result2;
                }
            }

            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取驱动个数
        /// </summary>
        /// <param name="number"></param>
        public void get_camer_number(ref int number)
        {
            List <IDeviceInfo> li = Enumerator.EnumerateDevices();

            number = li.Count;
        }
Exemplo n.º 8
0
        private void LoadFormInfo()
        {
            try
            {
                halconHelper = new HalconHelper(hWindowControl1.HalconWindow);
                List <IDeviceInfo> li = Enumerator.EnumerateDevices();
                //if (Convert.ToInt32(this.Tag) != -1)
                if (li.Count > 0)
                {
                    m_dev = Enumerator.GetDeviceByIndex(0);
                    //m_dev = Enumerator.GetDeviceByIndex(Convert.ToInt32(this.Tag));
                    // 注册链接时间

                    m_dev.CameraOpened   += OnCameraOpen;
                    m_dev.ConnectionLost += OnConnectLoss;
                    m_dev.CameraClosed   += OnCameraClose;
                    // 打开设备
                    if (!m_dev.Open())
                    {
                        MessageBox.Show(@"连接相机失败");
                        return;
                    }

                    // 关闭Trigger
                    //m_dev.TriggerSet.Close();
                    // 打开Software Trigger
                    m_dev.TriggerSet.Open(TriggerSourceEnum.Software);
                    // 设置图像格式
                    using (IEnumParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ImagePixelFormat])
                    {
                        p.SetValue("Mono8");
                    }

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

                    // 开启码流
                    if (!m_dev.GrabUsingGrabLoopThread())
                    {
                        MessageBox.Show(@"开启码流失败");
                        return;
                    }
                    else
                    {
                        m_dev.ExecuteSoftwareTrigger();
                    }
                }
                else
                {
                }
                //注册一维码识别完成事件
                halconHelper.Complete += OnComplete;
                halconHelper.Error    += OnError;
                //注册串口接收事件
                serialComm.DateReceived += new Comm.EventHandle(OnDataReceived);
                weightComm.DateReceived += new Comm.EventHandle(OnWeightDataReceived);
            }
            catch (Exception ex)
            {
                Catcher.Show(ex);
            }
        }