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); } }
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>; }
/// <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; }
/// <summary> /// 将当前所选页的工站配置更新到界面上 /// </summary> void UpdateCurrPage(bool isReload, bool enabled = false) { if (null == _station) { return; } TabPage currTP = tabControlCF1.SelectedTab; if (null == currTP) { return; } TableLayoutPanel currPanel = currTP.Controls[0] as TableLayoutPanel; JFXCfg cfg = _station.Config; if (isReload) { string category = currTP.Text; currPanel.Controls.Clear(); string[] itemNames = cfg.ItemNamesInTag(category); if (null == itemNames) { return; } foreach (string itemName in itemNames) { UcJFParamEdit ucParam = new UcJFParamEdit(); ucParam.IsHelpVisible = false; ucParam.Height = 50; ucParam.Width = 600; //ucParam.SetParamDesribe(JFParamDescribe.Create(itemName, cfg.GetItemValue(itemName).GetType(), JFValueLimit.NonLimit, null)); ucParam.SetParamDesribe(_station.GetCfgParamDescribe(itemName)); currPanel.Controls.Add(ucParam); } } foreach (UcJFParamEdit ucParam in currPanel.Controls) { //object paramVal = _station.GetCfgParamValue(ucParam.GetParamDesribe().DisplayName); object paramVal = cfg.GetItemValue(ucParam.GetParamDesribe().DisplayName); ucParam.SetParamValue(paramVal); ucParam.IsValueReadOnly = !enabled; } }
void AdjustStationView() { if (InvokeRequired) { Invoke(new Action(AdjustStationView)); return; } tabControlCF1.TabPages.Clear(); isEditting = false; btEditSave.Text = "编辑"; btCancel.Enabled = false; if (null == _cfg) { lbInfo.Text = "无配置项!"; btEditSave.Enabled = false; return; } lbInfo.Text = "文件路径:" + _cfg.FilePath; string[] namedCategorys = _cfg.AllTags; //if(null == categorys || categorys.Length < 2) //只有一个无名称Tag,由于保存私有配置 //{ // lbInfo.Text += " 无定制化参数"; // btEditSave.Enabled = false; // return; //} List <string> categorys = new List <string>(); if (!AllowedShowUnnameTag) { if (null == categorys || categorys.Count < 2) //只有一个无名称Tag,由于保存私有配置 { lbInfo.Text += " 无定制化参数"; btEditSave.Enabled = false; return; } } else { categorys.Add(""); } if (namedCategorys != null) { categorys.AddRange(namedCategorys); } btEditSave.Enabled = true; foreach (string category in categorys) { if (string.IsNullOrEmpty(category)) { continue; } TabPage tp = new TabPage(category); tabControlCF1.TabPages.Add(tp); string[] itemNames = _cfg.ItemNamesInTag(category); if (null == itemNames) { continue; } TableLayoutPanel panel = new TableLayoutPanel(); //panel.RowStyles[0] = new RowStyle(SizeType.Absolute, 55); panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 55)); panel.ColumnCount = 1; panel.AutoScroll = true; panel.Dock = DockStyle.Fill; tp.Controls.Add(panel); for (int i = 0; i < itemNames.Length; i++)//foreach (string itemName in itemNames) { string itemName = itemNames[i]; UcJFParamEdit ucParam = new UcJFParamEdit(); ucParam.IsHelpVisible = false; ucParam.Height = 50; ucParam.Width = 600;//panel.Width*2/3; //ucParam.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right ; //ucParam.SetParamType(_cfg.GetItemValue(itemName).GetType());//ucParam.SetParamDesribe(_station.GetCfgParamDescribe(itemName)); ucParam.SetParamDesribe(JFParamDescribe.Create(itemName, _cfg.GetItemValue(itemName).GetType(), JFValueLimit.NonLimit, null)); ucParam.SetParamValue(_cfg.GetItemValue(itemName)); ucParam.IsValueReadOnly = false; panel.Controls.Add(ucParam); ucParam.IsValueReadOnly = true; //panel.RowStyles[i].SizeType = SizeType.Absolute; //panel.RowStyles[i].Height = 55; } } //if (tabControlCF1.TabCount > 0) // tabControlCF1.SelectedIndex = 0; }
/// <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>运动控制卡Compare Trigger初始化 </summary> internal void Open() { if (IsOpen) { return; } int StartAxisId = 0, TotalAxis = 0, CardName = 0; APS168.APS_get_first_axisId(BoardID, ref StartAxisId, ref TotalAxis); APS168.APS_get_card_name(BoardID, ref CardName); if (/*CardName != (Int32)APS_Define.DEVICE_NAME_PCI_825458 && */ CardName != (Int32)APS_Define.DEVICE_NAME_AMP_20408C) { throw new Exception(string.Format("AMP204MC.Initialize Failed :运动控制卡型号不是204C或208C!")); } if (CardName == (Int32)APS_Define.DEVICE_NAME_AMP_20408C && TotalAxis == 4) { TrigChannels = 2; EncoderChannels = 4; for (int i = 0; i < TrigChannels; i++) { if (!lcmpSource.ContainsKey(i)) { lcmpSource.Add(i, (Int32)APS_Define.TGR_LCMP0_SRC + i); tcmpSource.Add(i, (Int32)APS_Define.TGR_TCMP0_SRC + i); tcmpDir.Add(i, (Int32)APS_Define.TGR_TCMP0_DIR + i); } } } if (CardName == (Int32)APS_Define.DEVICE_NAME_AMP_20408C && TotalAxis == 8) { TrigChannels = 4; EncoderChannels = 8; for (int i = 0; i < TrigChannels; i++) { if (i < 2) { if (!lcmpSource.ContainsKey(i)) { lcmpSource.Add(i, (Int32)APS_Define.TGR_LCMP0_SRC + i); tcmpSource.Add(i, (Int32)APS_Define.TGR_TCMP0_SRC + i); tcmpDir.Add(i, (Int32)APS_Define.TGR_TCMP0_DIR + i); } } else { if (!lcmpSource.ContainsKey(i)) { lcmpSource.Add(i, (Int32)APS_Define.TGR_LCMP2_SRC + i); tcmpSource.Add(i, (Int32)APS_Define.TGR_TCMP2_SRC + i); tcmpDir.Add(i, (Int32)APS_Define.TGR_TCMP2_DIR + i); } } } } #region Dictionary 初始化 lock (_jf168Cfg) { if (!_jf168Cfg.ContainsItem("Card_" + BoardID)) { _jf168Cfg.AddItem("Card_" + BoardID, new JFXmlDictionary <string, object>()); } _dictCT = _jf168Cfg.GetItemValue("Card_" + BoardID) as JFXmlDictionary <string, object>; if (_dictCT.ContainsKey(TrigTablesKeyName)) { trigTables = _dictCT[TrigTablesKeyName] as JFXmlDictionary <int, double[]>; } else { for (int i = 0; i < EncoderChannels; i++) { if (trigTables.ContainsKey(i)) { trigTables[i] = new double[0]; } else { trigTables.Add(i, new double[0]); } } _dictCT.Add(TrigTablesKeyName, trigTables); } if (_dictCT.ContainsKey(TrigLinersKeyName)) { trigLiners = _dictCT[TrigLinersKeyName] as JFXmlDictionary <int, JFCompareTrigLinerParam>; } else { for (int i = 0; i < EncoderChannels; i++) { if (trigLiners.ContainsKey(i)) { trigLiners[i] = new JFCompareTrigLinerParam(); } else { trigLiners.Add(i, new JFCompareTrigLinerParam()); } } _dictCT.Add(TrigLinersKeyName, trigLiners); } if (_dictCT.ContainsKey(TrigModesKeyName)) { trigModes = _dictCT[TrigModesKeyName] as JFXmlDictionary <int, JFCompareTrigMode>; } else { for (int i = 0; i < EncoderChannels; i++) { if (trigModes.ContainsKey(i)) { trigModes[i] = JFCompareTrigMode.disable; } else { trigModes.Add(i, JFCompareTrigMode.disable); } } _dictCT.Add(TrigModesKeyName, trigModes); } if (_dictCT.ContainsKey(ChnTrigKeyName)) { chnTrig = _dictCT[ChnTrigKeyName] as JFXmlDictionary <int, int[]>; } if (_dictCT.ContainsKey(TrigEnableKeyName)) { trigEnables = _dictCT[TrigEnableKeyName] as JFXmlDictionary <int, bool>; } else { for (int i = 0; i < TrigChannels; i++) { if (trigEnables.ContainsKey(i)) { trigEnables[i] = false; } else { trigEnables.Add(i, false); } } _dictCT.Add(TrigEnableKeyName, trigEnables); } if (_dictCT.ContainsKey(LCmprUsedKeyName)) { lcmprUsed = _dictCT[LCmprUsedKeyName] as JFXmlDictionary <int, bool>; } else { for (int i = 0; i < TrigChannels; i++) { if (lcmprUsed.ContainsKey(i)) { lcmprUsed[i] = false; } else { lcmprUsed.Add(i, false); } } _dictCT.Add(LCmprUsedKeyName, lcmprUsed); } if (_dictCT.ContainsKey(TCmprUsedKeyName)) { tcmprUsed = _dictCT[TCmprUsedKeyName] as JFXmlDictionary <int, bool>; } else { for (int i = 0; i < TrigChannels; i++) { if (tcmprUsed.ContainsKey(i)) { tcmprUsed[i] = false; } else { tcmprUsed.Add(i, false); } } _dictCT.Add(TCmprUsedKeyName, tcmprUsed); } if (_dictCT.ContainsKey(TrigLCmprKeyName)) { trigLCmprSource = _dictCT[TrigLCmprKeyName] as JFXmlDictionary <int, List <int> >; } if (_dictCT.ContainsKey(TrigTCmprKeyName)) { trigTCmprSource = _dictCT[TrigTCmprKeyName] as JFXmlDictionary <int, List <int> >; } if (_dictCT.ContainsKey(ChnTCmprKeyName)) { chnTcmpr = _dictCT[ChnTCmprKeyName] as JFXmlDictionary <int, int>; } if (_dictCT.ContainsKey(ChnLCmprKeyName)) { chnLcmpr = _dictCT[ChnLCmprKeyName] as JFXmlDictionary <int, int>; } if (!_dictCT.ContainsKey("PulseFactor")) { pulseFactors = new double[TotalAxis]; for (int i = 0; i < TotalAxis; i++) { pulseFactors[i] = 1; } } else { pulseFactors = _dictCT["PulseFactor"] as double[]; if (pulseFactors.Length < TotalAxis) { _dictCT.Remove("PulseFactor"); pulseFactors = new double[TotalAxis]; for (int i = 0; i < TotalAxis; i++) { pulseFactors[i] = 1; } _dictCT.Add("PulseFactor", pulseFactors); } } _jf168Cfg.Save(); } #endregion for (int i = 0; i < TrigChannels; i++) { if (APS168.APS_reset_trigger_count(BoardID, i) != 0)//reset count { throw new Exception(string.Format("AMP204MC.APS_reset_trigger_count Failed :重置触发通道{0}计数器失败!", i)); } if (APS168.APS_set_trigger_param(BoardID, (Int32)APS_Define.TGR_TRG0_SRC + i, 0) != 0)//Trig source bind { throw new Exception(string.Format("AMP204MC.APS_set_trigger_param Failed :接触触发通道{0}绑定关系!", i)); } //if (SetTrigEnable(i, trigEnables[i]) != (int)ErrorDef.Success)//enable or disable trig //调用慢,先屏蔽 remarked by Boby // throw new Exception(string.Format("AMP204MC.SetTrigEnable Failed :设置触发通道{0}使能状态失败!", i)); } for (int i = 0; i < EncoderChannels; i++) { if (!chnTrig.ContainsKey(i)) { continue; } if (chnTrig[i].Length <= 0) { continue; } int[] TrigChns = new int[chnTrig[i].Length]; TrigChns = chnTrig[i]; //if(SetEncoderTrigBind(i, TrigChns)!=(int)ErrorDef.Success) //调用慢,先屏蔽 remarked by Boby // throw new Exception(string.Format("AMP204MC.SetEncoderTrigBind Failed :绑定编码器{0}和触发通道{1}失败!",i, chnTrig[i])); } IsOpen = true; }