public void ChangeTriggerMode(bool live) { try { // Set an enum parameter. if (objDev.GetSfncVersion() < Sfnc2_0_0) { if (objDev.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart)) { if (objDev.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart)) { objDev.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart); objDev.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off); objDev.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart); objDev.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On); objDev.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Software); } else { objDev.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart); objDev.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On); objDev.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Software); } } } else // For SFNC 2.0 cameras, e.g. USB3 Vision cameras { if (objDev.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart)) { if (objDev.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart)) { objDev.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart); objDev.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off); objDev.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart); objDev.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On); objDev.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Software); } else { objDev.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart); objDev.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On); objDev.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Software); } } } stopWatch.Reset(); // **** 重置采集时间计时器 **** } catch (Exception e) { ShowException(e); } }
/// <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 ContinuousShot() { if (g_camera == null || g_camera.IsConnected == false) { return; } try { Command = Command.Video; if (g_camera.GetSfncVersion() < Sfnc2_0_0) { if (g_camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart)) { g_camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off); } if (g_camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart)) { g_camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off); } } else // For SFNC 2.0 cameras, e.g. USB3 Vision cameras { if (g_camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart)) { g_camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off); } if (g_camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart)) { g_camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off); } } IsContinuousShot = true; } catch (Exception ex) {/* * Util.WriteLog(this.GetType(), ex); * Util.Notify("相机连续采集开始异常");*/ } }