Пример #1
0
        /// <summary>
        /// 关闭相机,停止抓取相机并断开相机连接
        /// </summary>
        public override bool CloseCamera()
        {
            try
            {
#if (SDK)
                if (g_BaseParCamera.BlUsingTrigger)
                {
                    //关闭软触发
                }
                if (g_Camera != null && g_Camera.IsOpen && g_Camera.StreamGrabber.IsGrabbing)
                {
                    g_Camera.StreamGrabber.Stop();
                    g_Camera.Close();
                    g_Camera.Dispose();
                    g_Camera = null;
                }
#endif
                return(true);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(false);
            }
        }
Пример #2
0
        public override bool Init(HardwareData hardeareData)
        {
            bInitOk = false;
            #region TCP/IP
            if (!(null == _aca500M_Camera))
            {
                _aca500M_Camera.Dispose();
            }
            try
            {
                aca500M_Camera = new BP.Camera(cameraData.SerialNumber);
                GetParameter();
                if (!_aca500M_Camera.IsOpen)
                {
                    _aca500M_Camera.Open();
                }
                if (!_aca500M_Camera.StreamGrabber.IsGrabbing)
                {
                    _aca500M_Camera.StreamGrabber.Start(cameraData.maxPictureNumber, GrabStrategy.OneByOne, GrabLoop.ProvidedByUser);
                    bAsync = false;
                }


                bInitOk = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            #endregion
            return(bInitOk);
        }
Пример #3
0
        /// <summary>
        /// 根据相机索引获取相机
        /// [相机索引号由其上电顺序得来,非固定]
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public override bool DoGetCameraByIdx(int index)
        {
            bool rt = false;

            try
            {
                if (_deviceList != null)
                {
                    if (index >= 0 && index < _deviceList.Count())
                    {
                        foreach (Basler.Pylon.ICameraInfo cameraInfo in _deviceList)
                        {
                            string s = cameraInfo[Basler.Pylon.CameraInfoKey.DeviceIdx];
                            if (!string.IsNullOrEmpty(s))
                            {
                                if (index == System.Convert.ToInt32(s.Substring(2, s.Length - 2), 10))
                                {
                                    _device = new Basler.Pylon.Camera(cameraInfo);
                                    rt      = true;
                                    break;
                                }
                            }
                        }

                        if (!rt)
                        {
                            if (DriverExceptionDel != null)
                            {
                                DriverExceptionDel(string.Format("错误:巴斯勒相机获取设备失败!\n索引:{0}\n异常描述:{1}",
                                                                 index, "未找到指定索引相机(字符串形式索引)"));
                            }
                        }
                    }
                    else
                    {
                        if (DriverExceptionDel != null)
                        {
                            DriverExceptionDel(string.Format("错误:巴斯勒相机获取设备失败!\n索引:{0}\n异常描述:{1}",
                                                             index, "超出设备索引范围"));
                        }
                    }
                }
                else
                {
                    if (DriverExceptionDel != null)
                    {
                        DriverExceptionDel(string.Format("错误:巴斯勒相机获取索引对应设备失败!\n:{0}",
                                                         "设备列表为空"));
                    }
                }
            }
            catch
            {
            }
            finally
            {
            }

            return(rt);
        }
Пример #4
0
        public override void Close()
        {
            try
            {
                IsLink = false;
                // Reset the stopwatch.
                //stopWatch.Reset();
                if (g_camera != null)
                {
                    // Stop the grabbing.
                    g_camera.StreamGrabber.Stop();
                    // Close the connection to the camera device.
                    g_camera.Close();
                    g_camera.Dispose();
                    g_camera = null;
                }

                if (m_latestFrameAddress != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(m_latestFrameAddress);
                    m_latestFrameAddress = IntPtr.Zero;
                }
            }
            catch (Exception ex)
            {/*
              * Util.WriteLog(this.GetType(), ex);
              * Util.Notify("相机关闭异常");*/
            }
        }
Пример #5
0
 public override bool CloseCamera()
 {
     camera1.StreamGrabber.Stop();
     camera1.Close();
     camera1.Dispose();
     camera1 = null;
     return(true);
 }
Пример #6
0
 private string mark()
 {
     try
     {
         camera = new Camera();
         camera.Open();
         // camera.StreamGrabber.Start();
         grabOne();
     }
     catch {
         MessageBox.Show("相机不可用");
     }
     return("0,0,0");
 }
Пример #7
0
 public short Close()
 {
     if (camera == null)
     {
         return(-1);
     }
     else
     {
         camera.Close();
         camera.Dispose();
         camera = null;
         return(0);
     }
 }
Пример #8
0
        /// <summary>
        /// 根据相机名称获取相机
        /// </summary>
        /// <param name="camName"></param>
        /// <returns></returns>
        public override bool DoGetCameraByName(string camName)
        {
            bool rt = false;

            try
            {
                if (_deviceList != null)
                {
                    foreach (Basler.Pylon.ICameraInfo cameraInfo in _deviceList)
                    {
                        if (camName == cameraInfo[Basler.Pylon.CameraInfoKey.UserDefinedName])
                        {
                            _device = new Basler.Pylon.Camera(cameraInfo);
                            rt      = true;
                            break;
                        }
                    }

                    if (!rt)
                    {
                        if (DriverExceptionDel != null)
                        {
                            DriverExceptionDel(string.Format("错误:巴斯勒相机获取设备失败!\n设备名称:{0}\n异常描述{1}",
                                                             camName, "指定名称不匹配"));
                        }
                    }
                }
                else
                {
                    if (DriverExceptionDel != null)
                    {
                        DriverExceptionDel(string.Format("错误:巴斯勒相机获取索引对应设备失败!\n:{0}",
                                                         "设备列表为空"));
                    }
                }
            }
            catch
            {
            }
            finally
            {
            }

            return(rt);
        }
Пример #9
0
        private void btnSearchCamera_Click(object sender, EventArgs e)//枚举相机
        {
            cameraInfo = BP.CameraFinder.Enumerate();

            if (cameraInfo == null)
            {
                MessageBox.Show("Can not find any camera");
                return;
            }
            int       i            = 0;
            DataTable dtCameraInfo = new DataTable();

            dtCameraInfo.Columns.Add(new DataColumn("name"));
            dtCameraInfo.Columns.Add(new DataColumn("value"));

            foreach (var item in cameraInfo)
            {
                DataRow   row     = dtCameraInfo.NewRow();
                BP.Camera myCmera = new BP.Camera(item);
                try
                {
                    myCmera.Open();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                String strSerialNum = myCmera.Parameters[BP.PLCamera.DeviceID].GetValue();


                String strCameraInfo = String.Format("Camera{0}:serialNumber:{1}", i, strSerialNum);

                row["name"]  = strCameraInfo;
                row["value"] = strSerialNum;
                myCmera.Close();
                dtCameraInfo.Rows.Add(row);
            }
            cmbCamera.DisplayMember = "name";
            cmbCamera.ValueMember   = "value";

            cmbCamera.DataSource = dtCameraInfo;
        }
Пример #10
0
        public BaslerCameraControl()//StreamController guiStreamController, ImageViewer guiImageViewer, CameraLister guiCameraLister)
        {
            //StoreYawPitchRollOnCapture(e_valueType.wantedValue);
            camera           = new BaslerCamera(CameraSelectionStrategy.FirstFound);
            streamController = new StreamController();

            converter = new PixelDataConverter();
            converter.OutputPixelFormat = cameraOutputPixelFormat;

            camera.StreamGrabber.ImageGrabbed += OnImageGrabbed;

            OpenCamera();
            LOG(string.Format("Model: {0}", camera.Parameters[PLCamera.DeviceModelName].GetValue()));

            StartGrabbing();

            ////if (camera.WaitForFrameTriggerReady(100, TimeoutHandling.Return) == true)
            //{
            //    camera.ExecuteSoftwareTrigger();
        }
Пример #11
0
 public override void OpenCamera()
 {
     lock (m_lock)
     {
         List <ICameraInfo> allCameras = CameraFinder.Enumerate();
         foreach (ICameraInfo cameraInfo in allCameras)
         {
             if (this.m_Cameraname == cameraInfo[CameraInfoKey.UserDefinedName])
             {
                 camera = new Camera(cameraInfo);
                 if (!camera.Open(1000, TimeoutHandling.Return))
                 {
                     throw new Exception($"faile to open the camera{this.m_Cameraname}");
                 }
                 return;
             }
         }
         throw new Exception($"cannot find the camera named as{this.m_Cameraname}");
     }
 }
Пример #12
0
 public override bool DoInit()
 {
     try {
         if (this.myCamPara.CameraName == CameraEnum.Cam0)
         {
             camera1 = new Basler.Pylon.Camera("22954016");
         }
         else
         {
             camera1 = new Basler.Pylon.Camera("22970222");
         }
         camera1.CameraOpened += Basler.Pylon.Configuration.AcquireContinuous;
         camera1.Open();
         this.SetCamPara();
         camera1.Parameters[PLCameraInstance.MaxNumBuffer].SetValue(5);
         this.IsOpen = true;
     }
     catch {
         return(false);
     }
     return(true);
 }
Пример #13
0
        public BaslerCamera(ICameraInfo info, BaslerCameraPlugin provider)
        {
            this.info     = info;
            this.provider = provider;

            camera = new Basler.Pylon.Camera(info);

            camera.CameraOpened += Configuration.AcquireContinuous;

            camera.StreamGrabber.ImageGrabbed += OnImageGrabbed;

            parameters = new List <ICameraParameter>
            {
                new CameraParameter("Exposure Time", () => ExposureTime, (value) => ExposureTime = (double)value),
                new CameraParameter("Frame Rate", () => FrameRate, (value) => FrameRate          = (double)value)
                //  new CameraParameter("Binning", () => Binning, (value) => Binning = (Point)value),
                //   new CameraParameter("AOI Offset", () => AOIOffset, (value) => AOIOffset = (Point)value),
                //  new CameraParameter("AOI Size", () => AOISize, (value) => AOISize = (Point)value),
                //  new CameraParameter("Pixel Clock", () => PixelClock, (value) => PixelClock = (int)value),
                //  new CameraParameter("Managed Image", () => ManagedImages, (value) => ManagedImages = (bool)value),
            };
        }
Пример #14
0
        public short Open()
        {
            try
            {
                camera         = new Basler.Pylon.Camera();
                this.ModelName = camera.CameraInfo[CameraInfoKey.ModelName];

                // Set the acquisition mode to free running continuous acquisition when the camera is opened.
                camera.CameraOpened += Configuration.AcquireContinuous;

                // Open the connection to the camera device.
                camera.Open();

                // The parameter MaxNumBuffer can be used to control the amount of buffers
                // allocated for grabbing. The default value of this parameter is 10.
                camera.Parameters[PLCameraInstance.MaxNumBuffer].SetValue(5);

                //如果触发是AcquisisionStart,则要设置AcquisionFrameCount值为1
                //camera.Parameters[PLCamera.AcquisitionFrameCount].SetValue(1);

                //设置参数
                //camera.Parameters[PLCamera.ExposureAuto].SetValue(PLCamera.ExposureAuto.Off);
                //camera.Parameters[PLCamera.GainAuto].SetValue(PLCamera.GainAuto.Off);

                camera.Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.Continuous);//连续取图模式

                this.converter = new PixelDataConverter();
                camera.StreamGrabber.ImageGrabbed += onIamgeGrabbed;

                return(0);
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }
Пример #15
0
 public PylonCamera()
 {
     camera = new Basler.Pylon.Camera();
 }
Пример #16
0
        /// <summary>
        /// 打开相机,并传入相机参数
        /// </summary>
        public override bool OpenCamera(BaseParCamera baseParCamera)
        {
            try
            {
                g_BaseParCamera = baseParCamera;
                g_SerialNumber  = baseParCamera.Serial_Camera;//序列号
#if (SDK)
                g_Camera = new Basler.Pylon.Camera(g_SerialNumber);
                g_Camera.Open();

                // 设置触发模式
                if (g_BaseParCamera.BlUsingTrigger)
                {
                    g_Camera.Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.Continuous);
                    g_Camera.StreamGrabber.Start(GrabStrategy.OneByOne, GrabLoop.ProvidedByStreamGrabber);
                    SetTrigger();
                }
                else
                {
                    g_Camera.Parameters[PLCamera.TriggerMode].TrySetValue("Off");
                    g_Camera.Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.SingleFrame);
                    SetContinue();
                }

                //通过像素格式来判断是否彩色相机
                g_PixelFormat = g_Camera.Parameters[PLCamera.PixelFormat].GetValue();
                if (g_PixelFormat.Contains("Mono"))
                {
                    BlColor = false;
                }
                else
                {
                    BlColor = true;
                }
                //触发模式
                if (g_BaseParCamera.BlUsingTrigger)
                {
                    g_Camera.StreamGrabber.ImageGrabbed += StreamGrabber_ImageGrabbed;
                }

                string path = new DirectoryInfo("../").FullName;
                if (path.Contains("bin"))//调试状态
                {
                    //设置60000ms检测不到心跳,那么相机自动断开,防止相机需要断电处理
                    g_Camera.Parameters[PLTransportLayer.HeartbeatTimeout].TrySetToMaximum();
                    double heartbeatValue = g_Camera.Parameters[PLTransportLayer.HeartbeatTimeout].GetValue();
                }
                else
                {
                    //设置4000ms检测不到心跳,那么相机自动断开,防止相机需要断电处理
                    g_Camera.Parameters[PLTransportLayer.HeartbeatTimeout].TrySetValue(4000, IntegerValueCorrection.Nearest);
                }
                try
                {
                    if (g_Camera.Parameters[PLCamera.PixelFormat].TrySetValue(PLCamera.PixelFormat.BayerBG8))
                    {
                    }
                }
                catch (Exception ex)
                {
                }
#endif
                //相机打开成功的标志位
                BlOpen = true;
            }
            catch (Exception ex)
            {
                BlOpen = false;
                Log.L_I.WriteError(NameClass, ex);
            }
            return(BlOpen);
        }
Пример #17
0
 public BaslerCamera(Basler.Pylon.Camera g_camera, int index)
 {
     this.g_camera    = g_camera;
     this.cameraIndex = index;
 }
Пример #18
0
 public PylonCamera(CameraInfo <ICameraInfo> cameraInfo)
 {
     camera = new Basler.Pylon.Camera(cameraInfo.Instance);
 }