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); }
public bool OpenCamera() { if (camera.IsOpen == false) { //camera.CameraOpened += Configuration.SoftwareTrigger; camera.CameraOpened += Configuration.AcquireContinuous; //camera.CameraOpened += Configuration.; camera.Open(); LOG("camera opened"); camera.Parameters[PLCamera.ExposureMode].SetValue(PLCamera.ExposureMode.Timed); RefreshExposureTimeInCamera(); camera.Parameters[PLCameraInstance.MaxNumBuffer].SetValue(maxNumBuffer); //camera.Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.Continuous); //streamController.Camera = camera; //streamController.Camera.StreamGrabber.Start(GrabStrategy.LatestImages, GrabLoop.ProvidedByStreamGrabber); //streamController.Camera.StreamGrabber.Stop(); lock (initialize_locker) { initialized = false; } return(true); } return(false); }
/// <summary> /// 打开相机 /// </summary> /// <returns></returns> public override bool DoOpen() { bool rt = false; try { if (_device != null) { if (!_device.IsOpen) { _device.Open(); } if (!_isBandedCameraEvent) { _device.StreamGrabber.ImageGrabbed += DeviceStreamGrabber_ImageGrabbedEvent; // 绑定采集回调函数 _device.ConnectionLost += Device_ConnectionLost; _isBandedCameraEvent = true; } if (_device.GetSfncVersion() < SFNC2_0_0) { _imageWidth = _device.Parameters[Basler.Pylon.PLCamera.Width].GetValue(); // 获取图像宽 _imageHeight = _device.Parameters[Basler.Pylon.PLCamera.Height].GetValue(); // 获取图像高 } else { _imageWidth = _device.Parameters[Basler.Pylon.PLUsbCamera.Width].GetValue(); _imageHeight = _device.Parameters[Basler.Pylon.PLUsbCamera.Height].GetValue(); } 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); }
public override void Open() { try { objDev.Open(); SetHeartBeatTime(5000); //objDev.Parameters[PLCamera.AcquisitionFrameRateEnable].SetValue(true); // 限制相机帧率 //objDev.Parameters[PLCamera.AcquisitionFrameRateAbs].SetValue(90); //objDev.Parameters[PLCameraInstance.MaxNumBuffer].SetValue(10); // 设置内存中接收图像缓冲区大小 imageWidth = objDev.Parameters[PLCamera.Width].GetValue(); // 获取图像宽 imageHeight = objDev.Parameters[PLCamera.Height].GetValue(); // 获取图像高 // GetMinMaxExposureTime(); // GetMinMaxGain(); objDev.StreamGrabber.ImageGrabbed += OnImageGrabbed; // 注册采集回调函数 objDev.ConnectionLost += OnConnectionLost; } catch (Exception e) { ShowException(e); } }
private string mark() { try { camera = new Camera(); camera.Open(); // camera.StreamGrabber.Start(); grabOne(); } catch { MessageBox.Show("相机不可用"); } return("0,0,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; }
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}"); } }
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); }
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); } }
/// <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); }
public void Open() { camera.Open(); RaisePropertyChanged("IsOpen"); }
public override bool Open() { return(camera.Open(timeoutMs, TimeoutHandling.Return)); }