private void btSingleVisionCfgEdit_Click(object sender, EventArgs e) { JFXCfg cfg = new JFXCfg(); //序列化存储已测试 List <JFSingleVisionCfgParam> _lst = new List <JFSingleVisionCfgParam>(); JFSingleVisionCfgParam cp1 = new JFSingleVisionCfgParam(); //cp1.Name = "hehe"; cp1.LightChnNames = new string[] { "Light1", "Light2" }; cp1.LightIntensities = new int[] { 11, 22 }; //cp1.TestMethodFlowTxt = "测试方法流Demo"; JFSingleVisionCfgParam cp2 = new JFSingleVisionCfgParam(); //cp2.Name = "haha"; cp2.LightChnNames = new string[] { "Light3", "Light4" }; cp2.LightIntensities = new int[] { 33, 44 }; _lst.Add(cp1); _lst.Add(cp2); cfg.AddItem("SVCfgs", _lst, "单视野参数配置"); cfg.Save("视觉配置Demo"); JFXCfg cfg1 = new JFXCfg(); cfg1.Load("视觉配置Demo", false); List <JFSingleVisionCfgParam> _lst1 = cfg1.GetItemValue("SVCfgs") as List <JFSingleVisionCfgParam>; }
public bool Load() { JFXCfg cfg = new JFXCfg(); string path = @"BoxData.ini"; if (File.Exists(@"BoxData.ini")) { cfg.Load(path, true); Num = (int)cfg.GetItemValue("Count"); //Dir_Boxes = new ConcurrentDictionary<int, Box>(); Box BoxItem = null; for (int i = 0; i < Num; i++) { BoxItem = new Box(); BoxItem = cfg.GetItemValue("Box_" + i) as Box; if (BoxItem.Name == null) { BoxItem.Name = "Box_" + i; } if (BoxItem.Name == "") { BoxItem.Name = "Box_" + i; } Dir_Boxes.TryAdd(BoxItem.Idx, BoxItem); } return(true); } else { return(true); } }
/// <summary> /// 工站点位存取测试 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btLoadSaveAxisPos_Click(object sender, EventArgs e) { JFXCfg cfg = new JFXCfg(); cfg.Load("StationDemoPosTable.xml", true); List <JFMultiAxisPosition> maPoses = new List <JFMultiAxisPosition>(); JFMultiAxisPosition maPos1 = new JFMultiAxisPosition(); maPos1.Name = "Pos1"; maPos1.Positions.Add(JFAxisPos.Create("X", 1.23)); maPos1.Positions.Add(JFAxisPos.Create("Y", 4.56)); maPoses.Add(maPos1); JFMultiAxisPosition maPos2 = new JFMultiAxisPosition(); maPos2.Name = "Pos2"; maPos2.Positions.Add(JFAxisPos.Create("Y", 9.87)); maPos2.Positions.Add(JFAxisPos.Create("Z", 6.54)); maPoses.Add(maPos2); if (!cfg.ContainsItem("Positions")) { cfg.AddItem("Positions", maPoses); } else { cfg.SetItemValue("Positions", maPoses); } cfg.Save(); JFXCfg cfgAnother = new JFXCfg(); cfgAnother.Load("StationDemoPosTable.xml", false); List <JFMultiAxisPosition> maPoses1 = cfgAnother.GetItemValue("Positions") as List <JFMultiAxisPosition>;//测试OK,可获取 }
/// <summary>初始化HubCenter</summary> void Initialize() { dataPool = new JFDataPool(); string chkError = ""; string sysCfgFile = SystemCfgFilePath; while (string.IsNullOrEmpty(sysCfgFile) || //系统配置文件未设置 !File.Exists(sysCfgFile) || //系统配置文件已设置,但是文件不存在 !_CheckSysCfg(sysCfgFile, false, out chkError)) //系统文件已存在,但是格式不正确 { FormSelCfg fm = new FormSelCfg(); if (string.IsNullOrEmpty(sysCfgFile)) { fm.Tips = "系统配置文件未设置!"; } else if (!File.Exists(sysCfgFile)) { fm.Tips = "系统配置文件:" + "\"" + sysCfgFile + "\"不存在!\n请检查路径或选择/创建新的配置文件"; } else//(!_CheckSysCfg(SystemCfgFilePath,false)) //文件已存在,但格式不正确(缺少必要的数据项) { fm.Tips = "系统配置文件:" + "\"" + sysCfgFile + "\"格式错误!\nError:" + chkError + "\n请检查文件或选择/创建新的配置文件"; } fm.ShowDialog();//////////FormInitHub.ShowDialog()中有退出程序的出口,如果运行到下一步,肯定是已经选择了配置文件 sysCfgFile = fm.SysCfgFilePath; if (_CheckSysCfg(sysCfgFile, true, out chkError)) { SetSystemCfgFilePath(sysCfgFile);//退出程序,重新启动 break; } }//end while , 系统配置文件检查OK SystemCfg = new JFXCfg(); SystemCfg.Load(sysCfgFile, false); InitorHelp = new JFinitializerHelper(); //加载JFDll库文件 List <string> dllFiles = SystemCfg.GetItemValue(CK_ExpandDllFiles) as List <string>; foreach (string dllFile in dllFiles) { try { InitorHelp.AppendDll(dllFile); } catch (Exception ex) { MessageBox.Show("Hub-Center 加载dll = \"" + dllFile + "\"异常:\n" + ex); } } _mdCellNameMgr = new JFDevCellNameManeger(sysCfgFile);//运动控制卡单元名称管理 return; }
public bool Initialize() { bool ret = false; if (IsDeviceOpen) CloseDevice(); IsInitOK = false; do { if (string.IsNullOrEmpty(_cfgFilePath)) { _initErrorInfo = "初始化参数:\"控制器参数配置文件\" 未设置"; return false; } mdCfg = new JFXCfg(); try { mdCfg.Load(_cfgFilePath, true); } catch(Exception ex) { _initErrorInfo = "\"控制器参数配置文件\" 加载失败:Path = " + _cfgFilePath + "ErrorInfo:" + ex.Message; return false; } if (_boardID < 0) { IsInitOK = false; _initErrorInfo = "初始化参数:BoardID = " + _boardID + " 非法值/未设置"; return false; } //dio = new JFAps168DIO(BoardId); //mc = new JFAps168MC(BoardId, ConfigPath,this); //cmpTrigs = new JFAps168CompareTrigger(BoardId, ConfigPath,this); ret = true; IsInitOK = true; _initErrorInfo = "Success"; } while (false); return ret; }
/// <summary> /// 对象初始化 /// </summary> /// <returns>操作成功返回True,失败返回false,可通过GetInitErrorInfo()获取错误信息</returns> public bool Initialize() { _isInitOK = false; _initErrorInfo = "Unknown-Error"; do { if (string.IsNullOrEmpty(_initParamValues[0])) { _initErrorInfo = _initParamNames[0] + " 未设置/空值"; break; } if (string.IsNullOrEmpty(_initParamValues[1])) { _initErrorInfo = _initParamNames[1] + " 未设置/空值"; break; } bool isCreateWhenFileNotExist = false; if (_initParamValues[1] == "新创建") { isCreateWhenFileNotExist = true; } else if (_initParamValues[1] == " 报错") { isCreateWhenFileNotExist = false; } else { _initErrorInfo = _initParamNames[1] + " 参数错误,Value = " + _initParamValues[1] + "不存在于可选值列表[\"新创建\",\"报错\"]"; break; } if (!File.Exists(_initParamValues[0])) { if (!isCreateWhenFileNotExist) { _initErrorInfo = _initParamNames[0] + " = \"" + _initParamValues[0] + "\"文件不存在"; break; } } try { _cfg.Load(_initParamValues[0], isCreateWhenFileNotExist); if (!_cfg.ContainsItem("Categoties"))///保存所有的产品类别() { _cfg.AddItem("Categoties", new List <string>()); } if (!_cfg.ContainsItem("Cate-Recipes")) /// { _cfg.AddItem("Cate-Recipes", new JFXmlDictionary <string, List <string[]> >()); } //............................................. 类别->Recipe[ID, innerTxt] string errInfo; if (!_load(out errInfo)) { _initErrorInfo = "加载配置文件出错:" + errInfo; break; } JFXmlDictionary <string, List <string[]> > dctCateRecipes = _cfg.GetItemValue("Cate-Recipes") as JFXmlDictionary <string, List <string[]> >; } catch (Exception ex) { _initErrorInfo = "加载配置文件发生异常:" + ex.Message; break; } _isInitOK = true; _initErrorInfo = "Success"; } while (false); return(_isInitOK); }
/// <summary> /// 检查配置文件是否合规(如果缺少必要的数据项,则返回false) /// </summary> /// <param name="filePath">文件路径</param> /// <param name="isOpenOrCreate">如果文件不存在,是否创建</param> bool _CheckSysCfg(string filePath, bool isOpenOrCreate, out string errorInfo) { errorInfo = ""; if (string.IsNullOrEmpty(filePath)) { errorInfo = "文件名为空值(或空格)"; return(false); } if (!File.Exists(filePath)) //文件不存在 { if (!isOpenOrCreate) { errorInfo = "文件不存在"; return(false); } try { JFXCfg cfg = new JFXCfg(); cfg.Load(filePath, true); cfg.AddItem(CK_ExpandDllFiles, new List <string>(), CT_DLL); cfg.AddItem(CK_InitDevParams, new JFXmlSortedDictionary <string, List <object> >(), CT_DEV); //////////////////////////////////////////////// ///添加其他配置项初始化动作 /// /// cfg.Save(); return(true); } catch (Exception ex) { errorInfo = ex.Message; return(false); } //break; } else //文件已存在,检查格式(只检查必须项是否存在) { try { bool isCheckOK = true; StringBuilder sbError = new StringBuilder(); JFXCfg cfg = new JFXCfg(); cfg.Load(filePath, false); if (!cfg.ContainsItem(CK_ExpandDllFiles)) { sbError.Append("文件中不存在配置项:" + CK_ExpandDllFiles + "\n"); isCheckOK = false; } if (!cfg.ContainsItem(CK_InitDevParams)) { sbError.Append("文件中不存在配置项:" + CK_InitDevParams + "\n"); isCheckOK = false; } //////////////////////////////////////////////// ///添加其他配置项检查动作 /// /// if (!isCheckOK) { errorInfo = sbError.ToString(); } return(isCheckOK); } catch (Exception ex) { errorInfo = ex.Message; return(false); } } }