| LB_VisionProcesses/Cameras/BaseCamera.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/Cameras/ICamera.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
LB_VisionProcesses/Cameras/BaseCamera.cs
@@ -14,7 +14,15 @@ protected BaseCamera() { } #region Parm /// <summary> /// 相机SN号 /// </summary> public string SN { get; set; } = string.Empty; /// <summary> /// 相机名称 /// </summary> public string CameraName { get; set; } = string.Empty; public CameraBrand Brand { get; set; } = CameraBrand.UNSUPPORTED; public bool isGrabbing = false; @@ -64,96 +72,24 @@ public abstract bool InitDevice(string SN, object Handle = null); public bool StartWith_SoftTriggerModel() { SetTriggerMode(TriggerMode.Off, TriggerSource.Software); return StartGrabbing(); } public abstract bool StartWith_SoftTriggerModel(); public bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0) { if (hardtriggeritem == TriggerSource.Software) hardtriggeritem = TriggerSource.Line0; SetTriggerMode(TriggerMode.On, hardtriggeritem); return StartGrabbing(); } public abstract bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0); /// <summary> /// 等待硬触发获取图像 /// 等待软/硬触发获取图像 /// </summary> /// <param name="bitmap"></param> /// <param name="outtime"></param> /// <returns></returns> public bool GetImage(out Bitmap bitmap, int outtime = 3000) { bitmap = null; try { // 设置超时时间 DateTime lastTime = DateTime.Now.AddMilliseconds(outtime); // 判断是否超时 while (lastTime > DateTime.Now)// 设置超时时间为 3 秒 { if (CallBackImg != null) { lock (CallBackImg) { // 保存旧 Bitmap 并释放 bitmap = CallBackImg.Clone() as Bitmap; // 创建副本 } // 释放旧资源 CallBackImg.Dispose(); CallBackImg = null; return true; } } return false; } catch { return bitmap == null ? false : true; } } public abstract bool GetImage(out Bitmap bitmap, int outtime = 3000); /// <summary> /// 软触发获取图像 /// </summary> /// <param name="bitmap"></param> /// <param name="outtime"></param> /// <returns></returns> public bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000) { if (!isGrabbing) StartGrabbing(); GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource); if (triggerMode != TriggerMode.On && triggerSource != TriggerSource.Software) SetTriggerMode(TriggerMode.On, TriggerSource.Software); bitmap = null; CallBackImg = null; if (!SoftTrigger()) return false; // 开始时间 DateTime startTime = DateTime.Now; // 当前时间 // 判断是否超时 while (DateTime.Now < startTime.AddMilliseconds(outtime))// 设置超时时间为 3 秒 { GetImage(out bitmap, 50); if (bitmap != null) break; Thread.Sleep(10); } if (triggerMode != TriggerMode.On) SetTriggerMode(TriggerMode.On, triggerSource); return (bitmap != null); } public abstract bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000); /// <summary> /// 软触发 @@ -195,40 +131,8 @@ #endregion #region SettingConfig public void SetCamConfig(CameraConfig config) { if (Enum.TryParse(config.Params.Inputs["触发模式"].ToString(), out TriggerMode TriggerMode) && Enum.TryParse(config.Params.Inputs["触发方式"].ToString(), out TriggerSource TriggerSource) && Enum.TryParse(config.Params.Inputs["触发极性"].ToString(), out TriggerPolarity TriggerPolarity) ) { SetTriggerMode(TriggerMode, TriggerSource); SetTriggerPolarity(TriggerPolarity); SetTriggerFliter(Convert.ToDouble(config.Params.Inputs["触发消抖"].ToString())); SetTriggerDelay(Convert.ToDouble(config.Params.Inputs["触发延时"].ToString())); SetExpouseTime(Convert.ToDouble(config.Params.Inputs["曝光时间"].ToString())); SetGain(Convert.ToDouble(config.Params.Inputs["增益"].ToString())); } } public void GetCamConfig(out CameraConfig config) { GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource); GetTriggerPolarity(out TriggerPolarity triggerPolarity); GetTriggerFliter(out double triggerfilter); GetTriggerDelay(out double triggerdelay); GetExpouseTime(out double expouseTime); GetGain(out double gain); config = new CameraConfig(null); config.Params.Inputs.Add("触发模式", triggerMode); config.Params.Inputs.Add("触发方式", triggerSource); config.Params.Inputs.Add("触发极性", triggerPolarity); config.Params.Inputs.Add("触发消抖", triggerfilter); config.Params.Inputs.Add("触发延时", triggerdelay); config.Params.Inputs.Add("曝光时间", expouseTime); config.Params.Inputs.Add("增益", gain); } public abstract void SetCamConfig(CameraConfig config); public abstract void GetCamConfig(out CameraConfig config); /// <summary> /// 设置触发模式及触发源 LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs
@@ -1130,6 +1130,123 @@ GC.SuppressFinalize(this); } public override bool StartWith_SoftTriggerModel() { SetTriggerMode(TriggerMode.Off, TriggerSource.Software); return StartGrabbing(); } public override bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0) { if (hardtriggeritem == TriggerSource.Software) hardtriggeritem = TriggerSource.Line0; SetTriggerMode(TriggerMode.On, hardtriggeritem); return StartGrabbing(); } public override bool GetImage(out Bitmap bitmap, int outtime = 3000) { bitmap = null; try { // 设置超时时间 DateTime lastTime = DateTime.Now.AddMilliseconds(outtime); // 判断是否超时 while (lastTime > DateTime.Now)// 设置超时时间为 3 秒 { if (CallBackImg != null) { lock (CallBackImg) { // 保存旧 Bitmap 并释放 bitmap = CallBackImg.Clone() as Bitmap; // 创建副本 } // 释放旧资源 CallBackImg.Dispose(); CallBackImg = null; return true; } } return false; } catch { return bitmap == null ? false : true; } } public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000) { if (!isGrabbing) StartGrabbing(); GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource); if (triggerMode != TriggerMode.On && triggerSource != TriggerSource.Software) SetTriggerMode(TriggerMode.On, TriggerSource.Software); bitmap = null; CallBackImg = null; if (!SoftTrigger()) return false; // 开始时间 DateTime startTime = DateTime.Now; // 当前时间 // 判断是否超时 while (DateTime.Now < startTime.AddMilliseconds(outtime))// 设置超时时间为 3 秒 { GetImage(out bitmap, 50); if (bitmap != null) break; Thread.Sleep(10); } if (triggerMode != TriggerMode.On) SetTriggerMode(TriggerMode.On, triggerSource); return (bitmap != null); } public override void SetCamConfig(CameraConfig config) { if (Enum.TryParse(config.Params.Inputs["触发模式"].ToString(), out TriggerMode TriggerMode) && Enum.TryParse(config.Params.Inputs["触发方式"].ToString(), out TriggerSource TriggerSource) && Enum.TryParse(config.Params.Inputs["触发极性"].ToString(), out TriggerPolarity TriggerPolarity) ) { SetTriggerMode(TriggerMode, TriggerSource); SetTriggerPolarity(TriggerPolarity); SetTriggerFliter(Convert.ToDouble(config.Params.Inputs["触发消抖"].ToString())); SetTriggerDelay(Convert.ToDouble(config.Params.Inputs["触发延时"].ToString())); SetExpouseTime(Convert.ToDouble(config.Params.Inputs["曝光时间"].ToString())); SetGain(Convert.ToDouble(config.Params.Inputs["增益"].ToString())); } } public override void GetCamConfig(out CameraConfig config) { GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource); GetTriggerPolarity(out TriggerPolarity triggerPolarity); GetTriggerFliter(out double triggerfilter); GetTriggerDelay(out double triggerdelay); GetExpouseTime(out double expouseTime); GetGain(out double gain); config = new CameraConfig(null); config.Params.Inputs.Add("触发模式", triggerMode); config.Params.Inputs.Add("触发方式", triggerSource); config.Params.Inputs.Add("触发极性", triggerPolarity); config.Params.Inputs.Add("触发消抖", triggerfilter); config.Params.Inputs.Add("触发延时", triggerdelay); config.Params.Inputs.Add("曝光时间", expouseTime); config.Params.Inputs.Add("增益", gain); } #endregion } } LB_VisionProcesses/Cameras/ICamera.cs
@@ -63,7 +63,7 @@ bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0); /// <summary> /// 等待硬触发获取图像 /// 等待软/硬触发获取图像 /// </summary> /// <param name="bitmap"></param> /// <param name="outtime"></param> LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
@@ -23,6 +23,11 @@ return true; } public override void GetCamConfig(out CameraConfig config) { throw new NotImplementedException(); } public override bool GetExpouseTime(out double value) { value = 0; @@ -33,6 +38,16 @@ { gain = 0; return true; } public override bool GetImage(out Bitmap bitmap, int outtime = 3000) { throw new NotImplementedException(); } public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000) { throw new NotImplementedException(); } public override bool GetLineStatus(IOLines line, out LineStatus lineStatus) @@ -74,6 +89,11 @@ public override bool InitDevice(string SN, object Handle = null) { return true; } public override void SetCamConfig(CameraConfig config) { throw new NotImplementedException(); } public override bool SetExpouseTime(double value) @@ -126,6 +146,16 @@ return true; } public override bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0) { throw new NotImplementedException(); } public override bool StartWith_SoftTriggerModel() { throw new NotImplementedException(); } public override bool StopGrabbing() { return true;