Esempio n. 1
0
        /// <summary>
        /// 抓取相机的图像,输出所有的格式
        /// </summary>
        public override ImageAll GrabImageAll()
        {
            ImageAll imageAll = new ImageAll();

            try
            {
                if (!BlOpen ||
                    g_BaseParCamera.BlUsingTrigger)   //外触发模式不进行All抓取
                {
                    return(null);
                }
#if (SDK)
                if (g_Camera != null && g_Camera.IsOpen)
                {
                    if (g_BaseParCamera.BlUsingTrigger &&
                        g_Camera.StreamGrabber.IsGrabbing)
                    {
                        g_Camera.ExecuteSoftwareTrigger();
                        g_AutoResetEvent.WaitOne(500);
                    }
                    else
                    {
                        try
                        {
                            g_Camera.StreamGrabber.Start();
                            g_GrabResult = g_Camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
                        }
                        catch (Exception ex)
                        {
                            Log.L_I.WriteError(NameClass, ex); //The stream grabber is already grabbing.说明取图太快,或者两个线程取图冲突
                        }
                    }
                }

                using (g_GrabResult)
                {
                    if (g_GrabResult != null && g_GrabResult.GrabSucceeded)
                    {
                        imageAll.Ho_Image     = ConvertHobject(g_GrabResult);
                        imageAll.BitmapSource = ConvertImageBitmap(g_GrabResult);

                        PathDirectory p = new PathDirectory();
                        imageAll.TimeShort = p.GetShortTimeName();//图像抓取短时间
                        imageAll.Time      = p.GetTimeName();
                    }
                }

                g_Camera.StreamGrabber.Stop();
#endif
                return(imageAll);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 同步方式抓图
        /// </summary>
        /// <param name="strBarCode">读码结果</param>
        /// <param name="iTimeout">超时时间</param>
        /// <returns></returns>
        public bool GrabImage(out IGrabResult grabResult)//同步单次拍照
        {
            Stopwatch sw = new Stopwatch();

            Exception ex = new Exception("Please open the camera");


            if (!_aca500M_Camera.IsOpen)
            {
                MessageBox.Show(ex.Message);
            }
            if (!_aca500M_Camera.StreamGrabber.IsGrabbing)
            {
                _aca500M_Camera.StreamGrabber.Start(cameraData.maxPictureNumber, GrabStrategy.OneByOne, GrabLoop.ProvidedByUser);
                bAsync = false;
            }
            else
            {
                if (bAsync)
                {
                    _aca500M_Camera.StreamGrabber.Stop();
                    _aca500M_Camera.StreamGrabber.Start(cameraData.maxPictureNumber, GrabStrategy.OneByOne, GrabLoop.ProvidedByUser);
                    bAsync = false;
                }
            }

            try
            {
                sw.Start();
                _aca500M_Camera.WaitForFrameTriggerReady(1000, TimeoutHandling.ThrowException);
                _aca500M_Camera.ExecuteSoftwareTrigger();
                grabResult = _aca500M_Camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
                sw.Stop();
            }
            catch (Exception th_ex)
            {
                MessageBox.Show(th_ex.Message);
                grabResult = null;
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
 public override void Grad()
 {
     try
     {
         if (objDev.WaitForFrameTriggerReady(1000, TimeoutHandling.ThrowException))
         {
             objDev.ExecuteSoftwareTrigger(); //发送软触发命令
             stopWatch.Restart();             // ****  重启采集时间计时器   ****
         }
     }
     catch (Exception exception)
     {
         ShowException(exception);
     }
 }
Esempio n. 4
0
 public override void OneShot(Command command)
 {
     try
     {
         if (IsContinuousShot || IsExtTrigger)
         {
             ContinuousShotStop();
         }
         Command = command;
         // Execute the software trigger. Wait up to 1000 ms until the camera is ready for trigger.
         if (g_camera.WaitForFrameTriggerReady(100, TimeoutHandling.ThrowException))
         {
             g_camera.ExecuteSoftwareTrigger();
         }
     }
     catch
     {
         IsLink = false;/*
                         * Util.Notify("相机软触发异常");*/
     }
 }
Esempio n. 5
0
        /// <summary>
        /// 软触发一次
        /// </summary>
        /// <returns></returns>
        public override bool DoSoftTriggerOnce()
        {
            bool rt = false;

            try
            {
                if (_device != null)
                {
                    //if (_device.WaitForFrameTriggerReady(2000, Basler.Pylon.TimeoutHandling.ThrowException))
                    {
                        _device.ExecuteSoftwareTrigger();
                        _stopWatch.Restart();
                        rt = true;
                    }
                }
                else
                {
                    if (DriverExceptionDel != null)
                    {
                        DriverExceptionDel(string.Format("错误:巴斯勒相机单次软触发采集失败!\n:{0}", "设备未连接"));
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (DriverExceptionDel != null)
                {
                    DriverExceptionDel(string.Format("错误:巴斯勒相机单次软触发采集失败!\n错误描述:{0}", ex.Message));
                }
            }
            finally
            {
            }

            return(rt);
        }