/// <summary> /// 将配置数据转化为内存对象 /// </summary> /// <param name="errorInfo"></param> /// <returns></returns> bool _load(out string errorInfo) { _dctRecipes.Clear(); JFXmlDictionary <string, List <string[]> > cateRecipeInCfg = _cfg.GetItemValue("Cate-Recipes") as JFXmlDictionary <string, List <string[]> >; foreach (KeyValuePair <string, List <string[]> > cr in cateRecipeInCfg) { if (!_dctRecipes.ContainsKey(cr.Key)) { _dctRecipes.Add(cr.Key, new Dictionary <string, JFCommonRecipe>()); } Dictionary <string, JFCommonRecipe> dctInCate = _dctRecipes[cr.Key]; foreach (string[] idAndTxt in cr.Value) { JFCommonRecipe recipe = new JFCommonRecipe(); recipe.Categoty = cr.Key; recipe.ID = idAndTxt[0]; try { recipe.Dict = JFFunctions.FromXTString(idAndTxt[1], recipe.Dict.GetType()) as JFXmlDictionary <string, object>; } catch (Exception ex) { errorInfo = "Categoty = " + cr.Key + ", RecipeID = " + idAndTxt[0] + " FromXTString() Exception:" + ex.Message; return(false); } dctInCate.Add(idAndTxt[0], recipe); } } errorInfo = "Success"; return(true); }
internal void Init() { JFXmlSortedDictionary <string, List <object> > devInitParams = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >; foreach (KeyValuePair <string, List <object> > kv in devInitParams) { IJFInitializable dev = JFHubCenter.Instance.InitorHelp.CreateInstance(kv.Value[0] as string); // as IJFDevice; dictInitors.Add(kv.Key, dev); try //尝试初始化 { string[] paramNames = dev.InitParamNames; if (null != paramNames && paramNames.Length > 0) { for (int i = 0; i < paramNames.Length; i++) { object pr = i < kv.Value.Count - 1 ? kv.Value[i + 1] : null; object relParamVal = null; Type paramType = dev.GetInitParamDescribe(paramNames[i]).ParamType; SerializableAttribute[] sas = paramType.GetCustomAttributes(typeof(SerializableAttribute), false) as SerializableAttribute[]; if (sas != null && sas.Length > 0) //如果是可序列化的类型,直接保存序列化后的文本 { relParamVal = JFFunctions.FromXTString(pr as string, paramType); } else { if (paramType.IsValueType || paramType == typeof(string)) //单值对象和字符串对象直接添加 { relParamVal = pr; } else //目前支持Array 和 List { if (paramType.IsArray) //参数类型是数组 { if (null == pr || string.Empty == pr as string) { relParamVal = null; } else { string[] elmts = (pr as string).Split(new char[] { '$' }); relParamVal = GenArrayObject(paramType, elmts.Length); if (elmts.Length != 0) { for (int j = 0; j < elmts.Length; j++) { (relParamVal as Array).SetValue(JFConvertExt.ChangeType(elmts[j], paramType.GetElementType()), j); } } } } else if (typeof(IList).IsAssignableFrom(paramType)) //队列类型 { if (null == pr || string.Empty == pr as string) { relParamVal = null; } else { string[] elmts = (pr as string).Split(new char[] { '$' }); relParamVal = GenListObject(paramType); if (elmts.Length != 0) { for (int j = 0; j < elmts.Length; j++) { (relParamVal as IList).Add(JFConvertExt.ChangeType(elmts[j], paramType.GetElementType())); } } } } } } dev.SetInitParamValue(paramNames[i], relParamVal); } } dev.Initialize(); if (dev is IJFDevice) { (dev as IJFDevice).OpenDevice(); Thread.Sleep(100); } } catch { //初始化发生异常 } //dictInitors.Add(kv.Key, dev); //if (dev is IJFStation) //{ // (dev as IJFStation).WorkStatusChanged += JFHubCenter.Instance.StationMgr.StationWorkStatusChanged; // (dev as IJFStation).CustomStatusChanged += JFHubCenter.Instance.StationMgr.StationCustomStatusChanged; // if (dev is JFCmdWorkBase) // (dev as JFCmdWorkBase).WorkMsg2Outter += JFHubCenter.Instance.StationMgr.StationWorkMsg; //} } }
public void InitStationParams() { try { Dict = new JFXmlDictionary <string, object>(); visionCfgParams = new JFXmlDictionary <string, JFXmlDictionary <string, JFXmlDictionary <string, string> > >(); //系统参数 imageFolder = (string)JFHubCenter.Instance.RecipeManager.GetInitParamValue((string)JFHubCenter.Instance.RecipeManager.InitParamNames[2]); ActivePdt = (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"); formIniConfig = new IniFiles(imageFolder + "\\" + ActivePdt + "\\scanPoint.ini"); //工站参数 width = (double)GetCfgParamValue(mwidth); height = (double)GetCfgParamValue(mheight); _RunMode = (int)GetCfgParamValue(mRunMode); Num_Camera = (int)GetCfgParamValue(mNum_Camera); SelectedIndex = (int)GetCfgParamValue(mSelectIndex); Z_safe = (double)GetCfgParamValue(mZ_safe); jFDLAFProductRecipe = ((JFDLAFProductRecipe)JFHubCenter.Instance.RecipeManager.GetRecipe("Product", (string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))); //Recipe参数 if (jFDLAFProductRecipe != null) { FrameLength = jFDLAFProductRecipe.FrameLength; RowNumber = jFDLAFProductRecipe.RowNumber; ColumnNumber = jFDLAFProductRecipe.ColumnNumber; BlockNumber = jFDLAFProductRecipe.BlockNumber; visionCfgParams = jFDLAFProductRecipe.visionCfgParams; ZFocus = jFDLAFProductRecipe.ZFocus; } else { return; } if (jFDLAFProductRecipe.AutoMappingStationProInf != "") { string xmlTxt = jFDLAFProductRecipe.AutoMappingStationProInf; Dict = JFFunctions.FromXTString(xmlTxt, Dict.GetType()) as JFXmlDictionary <string, object>; xmlTxt = Dict.ContainsKey(mVisionCfgName) ? (string)Dict[mVisionCfgName] : ""; if (xmlTxt != "") { visionCfgParams = JFFunctions.FromXTString(xmlTxt, visionCfgParams.GetType()) as JFXmlDictionary <string, JFXmlDictionary <string, JFXmlDictionary <string, string> > >; } //工站中默认的参数 genMapStartX = Dict.ContainsKey(mgenMapStartX) ? (double)Dict[mgenMapStartX] : 0; genMapStartY = Dict.ContainsKey(mgenMapStartY) ? (double)Dict[mgenMapStartY] : 0; genMapEndX = Dict.ContainsKey(mgenMapEndX) ? (double)Dict[mgenMapEndX] : 0; genMapEndY = Dict.ContainsKey(mgenMapEndY) ? (double)Dict[mgenMapEndY] : 0; sameSpace = Dict.ContainsKey(msameSpace) ? (double)Dict[msameSpace] : 0; lctScoreThresh = Dict.ContainsKey(mlctScoreThresh) ? (double)Dict[mlctScoreThresh] : 0; checkMdlMethod = Dict.ContainsKey(mcheckMdlMethod) ? (int)Dict[mcheckMdlMethod] : 0; usedoubleCheck = Dict.ContainsKey(musedoubleCheck) ? (int)Dict[musedoubleCheck] : 0; //ZFocus = Dict.ContainsKey(mZFocus) ? (double)Dict[mZFocus] : 0; hv_dieWidth = Dict.ContainsKey(mdieWidth) ? (double)Dict[mdieWidth] : 0; hv_dieHeight = Dict.ContainsKey(mdieHeight) ? (double)Dict[mdieHeight] : 0; ref_x = Dict.ContainsKey(mref_x) ? (double)Dict[mref_x] : 0; ref_y = Dict.ContainsKey(mref_y) ? (double)Dict[mref_y] : 0; ref_z = Dict.ContainsKey(mref_z) ? (double)Dict[mref_z] : 0; scanRowNum = Dict.ContainsKey(mscanRowNum) ? (int)Dict[mscanRowNum] : 0; scanColNum = Dict.ContainsKey(mscanColNum) ? (int)Dict[mscanColNum] : 0; clipPosNum = Dict.ContainsKey(mclipPosNum) ? (int)Dict[mclipPosNum] : 0; scanPosNum = Dict.ContainsKey(mscanPosNum) ? (int)Dict[mscanPosNum] : 0; if (Dict.ContainsKey(mFovRow)) { ICFovRow = (List <double>)Dict[mFovRow]; } if (Dict.ContainsKey(mFovCol)) { ICFovCol = (List <double>)Dict[mFovCol]; } } else { if (Config.ContainsItem((string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID"))) { string xmlTxt = (string)GetCfgParamValue((string)JFHubCenter.Instance.SystemCfg.GetItemValue("CurrentID")); Dict = JFFunctions.FromXTString(xmlTxt, Dict.GetType()) as JFXmlDictionary <string, object>; xmlTxt = Dict.ContainsKey(mVisionCfgName) ? (string)Dict[mVisionCfgName] : ""; if (xmlTxt != "") { visionCfgParams = JFFunctions.FromXTString(xmlTxt, visionCfgParams.GetType()) as JFXmlDictionary <string, JFXmlDictionary <string, JFXmlDictionary <string, string> > >; } //工站中默认的参数 genMapStartX = Dict.ContainsKey(mgenMapStartX) ? (double)Dict[mgenMapStartX] : 0; genMapStartY = Dict.ContainsKey(mgenMapStartY) ? (double)Dict[mgenMapStartY] : 0; genMapEndX = Dict.ContainsKey(mgenMapEndX) ? (double)Dict[mgenMapEndX] : 0; genMapEndY = Dict.ContainsKey(mgenMapEndY) ? (double)Dict[mgenMapEndY] : 0; sameSpace = Dict.ContainsKey(msameSpace) ? (double)Dict[msameSpace] : 0; lctScoreThresh = Dict.ContainsKey(mlctScoreThresh) ? (double)Dict[mlctScoreThresh] : 0; checkMdlMethod = Dict.ContainsKey(mcheckMdlMethod) ? (int)Dict[mcheckMdlMethod] : 0; usedoubleCheck = Dict.ContainsKey(musedoubleCheck) ? (int)Dict[musedoubleCheck] : 0; //ZFocus = Dict.ContainsKey(mZFocus) ? (double)Dict[mZFocus] : 0; hv_dieWidth = Dict.ContainsKey(mdieWidth) ? (double)Dict[mdieWidth] : 0; hv_dieHeight = Dict.ContainsKey(mdieHeight) ? (double)Dict[mdieHeight] : 0; ref_x = Dict.ContainsKey(mref_x) ? (double)Dict[mref_x] : 0; ref_y = Dict.ContainsKey(mref_y) ? (double)Dict[mref_y] : 0; ref_z = Dict.ContainsKey(mref_z) ? (double)Dict[mref_z] : 0; scanRowNum = Dict.ContainsKey(mscanRowNum) ? (int)Dict[mscanRowNum] : 0; scanColNum = Dict.ContainsKey(mscanColNum) ? (int)Dict[mscanColNum] : 0; clipPosNum = Dict.ContainsKey(mclipPosNum) ? (int)Dict[mclipPosNum] : 0; scanPosNum = Dict.ContainsKey(mscanPosNum) ? (int)Dict[mscanPosNum] : 0; if (Dict.ContainsKey(mFovRow)) { ICFovRow = (List <double>)Dict[mFovRow]; } if (Dict.ContainsKey(mFovCol)) { ICFovCol = (List <double>)Dict[mFovCol]; } } } //else if(File.Exists(imageFolder + "\\" + ActivePdt + "\\scanPoint.ini")) //{ // formIniConfig.ReadDouble("ScanPoints", "genMapStartX", out genMapStartX); // formIniConfig.ReadDouble("ScanPoints", "genMapStartY", out genMapStartY); // formIniConfig.ReadDouble("ScanPoints", "genMapEndX", out genMapEndX); // formIniConfig.ReadDouble("ScanPoints", "genMapEndY", out genMapEndY); // formIniConfig.ReadDouble("ScanPoints", "sameSpace", out sameSpace); // formIniConfig.ReadDouble("ScanPoints", "scaleFactor", out scaleFactor); // formIniConfig.ReadDouble("ScanPoints", "lctScoreThresh", out lctScoreThresh); // formIniConfig.ReadDouble("ScanPoints", "checkPosX", out checkPosX); // formIniConfig.ReadDouble("ScanPoints", "checkPosY", out checkPosY); // formIniConfig.ReadDouble("ScanPoints", "checkPosScoreThresh", out checkPosScoreThresh); // formIniConfig.ReadDouble("ScanPoints", "widthFactor", out widthFactor); // formIniConfig.ReadDouble("ScanPoints", "heightFactor", out heightFactor); // formIniConfig.ReadInteger("ScanPoints", "CheckModelMethod", out checkMdlMethod); // formIniConfig.ReadDouble("ScanPoints", "checkPosRX", out checkPosRX); // formIniConfig.ReadDouble("ScanPoints", "checkPosRY", out checkPosRY); // formIniConfig.ReadDouble("ScanPoints", "checkPosRScoreThresh", out checkPosRScoreThresh); // formIniConfig.ReadInteger("ScanPoints", "useDoubleCheck", out usedoubleCheck); // ICFovRow = new List<double>(); // ICFovCol = new List<double>(); //} } catch { } }
private void btOK_Click(object sender, EventArgs e) { if (null == _mgr) { MessageBox.Show("无效操作,RecipeManager未设置"); return; } if (!_mgr.IsInitOK) { MessageBox.Show("无效操作,RecipeManager未初始化,ErrorInfo:" + _mgr.GetInitErrorInfo()); return; } if (string.IsNullOrWhiteSpace(cbGenCate.Text)) { MessageBox.Show("参数项 Categoty 不能为空值!"); return; } if (string.IsNullOrWhiteSpace(tbGenID.Text)) { MessageBox.Show("参数项 RecipeID 不能为空值!"); return; } string[] existIDs = _mgr.AllRecipeIDsInCategoty(cbGenCate.Text); if (null != existIDs && existIDs.Contains(tbGenID.Text)) { MessageBox.Show("添加Recipe失败,Categoty = " + cbGenCate.Text + "已包含当前RecipeID = " + tbGenID.Text); return; } JFCommonRecipe newRecipe = new JFCommonRecipe(); newRecipe.Categoty = cbGenCate.Text; newRecipe.ID = tbGenID.Text; if (chkCopy.Checked) //以拷贝的方式创建新的Recipe { if (string.IsNullOrEmpty(cbCopyCate.Text)) { MessageBox.Show("请选择待拷贝的Categoty!"); return; } if (string.IsNullOrEmpty(cbCopyID.Text)) { MessageBox.Show("请选择待拷贝的RecipeID!"); return; } JFCommonRecipe recipe = _mgr.GetRecipe(cbCopyCate.Text, cbCopyID.Text) as JFCommonRecipe; string xmlTxt; string typeTxt; JFFunctions.ToXTString(recipe.Dict, out xmlTxt, out typeTxt); newRecipe.Dict = JFFunctions.FromXTString(xmlTxt, typeTxt) as JFXmlDictionary <string, object>; } _mgr.AddRecipe(cbGenCate.Text, tbGenID.Text, newRecipe); _mgr.Save(); DialogResult = DialogResult.OK; }