/// <summary> /// 添加一个单视野视觉配置参数 /// </summary> /// <param name="name"></param> /// <param name="cfg"></param> public void AddSingleVisionCfg(string name, JFSingleVisionCfgParam cfg) { if (null == cfg) { throw new ArgumentNullException("JFVisionManager.AddSingleVisionCfgParam(cfg) failed by cfg == null"); } if (_lstSVCfgs.Contains(cfg)) { throw new ArgumentException("JFVisionManager.AddSingleVisionCfgParam(cfg) failed by cfg had Contained-in!"); } if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("JFVisionManager.AddSingleVisionCfgParam(cfg) failed by cfg.Name is null or empty"); } if (ContainSingleVisionCfgByName(name)) { throw new ArgumentException("JFVisionManager.AddSingleVisionCfgParam(name ...) failed by name = " + name + " is Existed!"); } cfg.Name = name; _lstSVCfgs.Add(cfg); _cfg.Save(); }
/// <summary> /// 保存当前视觉配置 /// </summary> /// <param name="filePath"></param> public bool SaveProgram(string programName, out string errorInfo) { errorInfo = "UnknownError"; bool ret = false; do { if (string.IsNullOrEmpty(programName)) { errorInfo = "配置名称为空字串"; break; } JFVisionManager vm = JFHubCenter.Instance.VisionMgr; JFSingleVisionCfgParam vc = null; if (vm.ContainSingleVisionCfgByName(programName)) { vc = vm.GetSingleVisionCfgByName(programName); } else { vc = new JFSingleVisionCfgParam(); } string ei; if (!OpenEnableDevices(out ei)) { errorInfo = "设备未全部打开并使能:" + ei; break; } ///相机参数 double exposure = 0; //相机曝光值 double gain = 0; bool isRevsX = false; bool isRevsY = false; int errCode = _cmr.GetExposure(out exposure); if (errCode != 0) { errorInfo = "获取相机曝光值失败:" + _cmr.GetErrorInfo(errCode); break; } errCode = _cmr.GetGain(out gain); if (errCode != 0) { errorInfo = "获取相机增益值失败:" + _cmr.GetErrorInfo(errCode); break; } errCode = _cmr.GetReverseX(out isRevsX); if (errCode != 0) { errorInfo = "获取相机X镜像参数失败:" + _cmr.GetErrorInfo(errCode); break; } errCode = _cmr.GetReverseY(out isRevsY); if (errCode != 0) { errorInfo = "获取相机Y镜像参数失败:" + _cmr.GetErrorInfo(errCode); break; } ///光源通道参数 int[] intensities = null; if (_lightNames != null && _lightNames.Length > 0) { intensities = new int[_lightNames.Length]; for (int i = 0; i < _lightNames.Length; i++) { int nVal = 0; IJFDevice_LightController dev = _lightChns[i].Device() as IJFDevice_LightController; errCode = dev.GetLightIntensity(_lightChns[i].CellInfo().ChannelIndex, out nVal); if (errCode != 0) { errorInfo = "获取光源:\"" + _lightNames[i] + "\"亮度值失败:" + dev.GetErrorInfo(errCode); goto LoopExit; } intensities[i] = nVal; } } double[] axisPos = null; ///配置轴参数 if (_cfgAxisNames != null && _cfgAxisNames.Length > 0) { double dVal = 0; axisPos = new double[_cfgAxisNames.Length]; for (int i = 0; i < _cfgAxisNames.Length; i++) { IJFDevice_MotionDaq md = _cfgAxes[i].Device() as IJFDevice_MotionDaq; JFDevCellInfo ci = _cfgAxes[i].CellInfo(); errCode = md.GetMc(ci.ModuleIndex).GetFbkPos(ci.ChannelIndex, out dVal); if (errCode != 0) { errorInfo = "获取轴:\"" + _cfgAxisNames[i] + "\"位置失败:" + md.GetMc(ci.ModuleIndex).GetErrorInfo(errCode); goto LoopExit; } axisPos[i] = dVal; } } vc.CmrReverseX = isRevsX; vc.CmrReverseY = isRevsY; vc.CmrExposure = exposure; vc.CmrGain = gain; vc.LightChnNames = _lightNames == null ? new string[] { } : _lightNames; vc.LightIntensities = intensities == null ? new int[] { } : intensities; vc.AxisNames = _cfgAxisNames == null ? new string[] { } : _cfgAxisNames; vc.AxisPositions = axisPos == null ? new double[] { } : axisPos; if (!vm.ContainSingleVisionCfgByName(programName)) { vc.Name = programName; vc.OwnerAssist = Name; vm.AddSingleVisionCfg(programName, vc); } else { vm.Save(); } errorInfo = "Success"; ret = true; } while (false); LoopExit: return(ret); }