| | |
| | | using LB_SmartVisionCameraSDK.PHM6000; |
| | | using LB_SmartVisionCommon; |
| | | using LB_VisionProcesses.Cameras; |
| | | using OpenVinoSharp.Extensions.model; |
| | | using SharpCompress.Common; |
| | | using Sunny.UI.Win32; |
| | | using System; |
| | | using System.Collections.Concurrent; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Drawing; |
| | | using System.Drawing.Imaging; |
| | | using System.Reflection; |
| | |
| | | { |
| | | private IntPtr _cameraHandle = IntPtr.Zero; |
| | | private PHM6000SensorConfig _sensorConfig; |
| | | |
| | | // 采集回调 |
| | | private AcquisitionCallbackZA _acquisitionCallback; |
| | | private AcquisitionCompletedCallback _acquisitionCompletedCallback; |
| | |
| | | |
| | | public void UpdateSensorConfig(PHM6000SensorConfig config) |
| | | { |
| | | _sensorConfig = config; |
| | | if (!_isConnected) return; |
| | | SetParam(EnumNameId.ExposureTime, (float)config.ExposureTime); |
| | | SetParam(EnumNameId.AnalogGain, (float)config.AnalogGain); |
| | | PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.ScanLineCount, config.ScanLineCount, 0, 0); |
| | | PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.LineScanTriggerSource, 0, 0, (int)config.LineScanTriggerSource); |
| | | PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.DataAcquisitionTriggerSource, 0, 0, (int)config.DataAcquisitionTriggerSource); |
| | | if (config.LineScanTriggerSource == EnumLineScanTriggerSource.固定频率) |
| | | //_sensorConfig = config; |
| | | //if (!_isConnected) return; |
| | | //SetParam(EnumNameId.ExposureTime, (float)config.ExposureTime); |
| | | //SetParam(EnumNameId.AnalogGain, (float)config.AnalogGain); |
| | | //PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.ScanLineCount, config.ScanLineCount, 0, 0); |
| | | //PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.LineScanTriggerSource, 0, 0, (int)config.LineScanTriggerSource); |
| | | //PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.DataAcquisitionTriggerSource, 0, 0, (int)config.DataAcquisitionTriggerSource); |
| | | //if (config.LineScanTriggerSource == EnumLineScanTriggerSource.固定频率) |
| | | //{ |
| | | // PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.SoftwareTriggerRate, 0, config.SoftwareTriggerRate, 0); |
| | | //} |
| | | |
| | | int result = 0; |
| | | var type = config.GetType(); |
| | | var propLineScan = type.GetProperty(nameof(config.LineScanTriggerSource)); |
| | | var val = (EnumLineScanTriggerSource)propLineScan.GetValue(config); |
| | | var props = config.GetType().GetProperties(); |
| | | |
| | | //排除Y轴 |
| | | props = props.Where(d => d.Name != nameof(PHM6000SensorConfig.YResolution)).ToArray(); |
| | | //排除不需要的项 |
| | | if (val == EnumLineScanTriggerSource.固定频率) |
| | | { |
| | | PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.SoftwareTriggerRate, 0, config.SoftwareTriggerRate, 0); |
| | | props = props.Where(d => d.Name != nameof(PHM6000SensorConfig.EncoderTriggerDirection) && d.Name != nameof(PHM6000SensorConfig.EncoderTriggerInterval) && d.Name != nameof(PHM6000SensorConfig.EncoderTriggerSignalCountingMode)).ToArray(); |
| | | } |
| | | else |
| | | { |
| | | props = props.Where(d => d.Name != nameof(PHM6000SensorConfig.SoftwareTriggerRate)).ToArray(); |
| | | } |
| | | foreach (var p in props) |
| | | { |
| | | //跳过自定义参数 |
| | | var iscustomAttr = p.GetCustomAttribute<IsCustomAttribute>(); |
| | | if (iscustomAttr != null) continue; |
| | | //判断是6030传感器还是普通传感器 |
| | | if (SN.StartsWith("LX030") && p.Name == nameof(config.AnalogGain)) |
| | | { |
| | | continue; |
| | | } |
| | | if (!SN.StartsWith("LX030") && p.Name == nameof(config.AnalogGainFor6030)) |
| | | { |
| | | continue; |
| | | } |
| | | var id = Convert.ToInt32(Enum.Parse(typeof(EnumNameId), p.Name)); |
| | | if (p.PropertyType == typeof(int)) |
| | | { |
| | | var value = Convert.ToInt32(p.GetValue(config)); |
| | | result = PHM6000Profiler.SetProfilerParameter(_cameraHandle, id, value, 0, 0); |
| | | } |
| | | else if (p.PropertyType == typeof(float)) |
| | | { |
| | | var value = Convert.ToDouble(p.GetValue(config)); |
| | | result = PHM6000Profiler.SetProfilerParameter(_cameraHandle, id, 0, value, 0); |
| | | } |
| | | else |
| | | { |
| | | var value = Convert.ToInt32(p.GetValue(config)); |
| | | result = PHM6000Profiler.SetProfilerParameter(_cameraHandle, id, 0, 0, value); |
| | | } |
| | | if (result == -1) |
| | | { |
| | | var disattr = p.GetCustomAttribute<DisplayNameAttribute>(); |
| | | var name = disattr?.DisplayName ?? p.Name; |
| | | throw new Exception($"设置参数{name}时不成功!"); |
| | | } |
| | | } |
| | | var finalResult = PHM6000Profiler.SaveAllParametersToDevice(_cameraHandle); |
| | | if (finalResult != 0) |
| | | { |
| | | } |
| | | PHM6000Profiler.SaveAllParametersToDevice(_cameraHandle); |
| | | } |