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,可获取 }
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); } }
public void SetCfg(JFXCfg cfg) { _cfg = cfg; if (_isFormLoaded) { AdjustStationView(); } }
/// <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 SetCurrRecipeID(string recipeID, out string errorInfo) { if (string.IsNullOrEmpty(recipeID)) { errorInfo = "产品ID为null/空字串"; return(false); } if (!CheckRecipeMgr(out errorInfo)) { return(false); } JFDLAFRecipeManager rm = JFHubCenter.Instance.RecipeManager as JFDLAFRecipeManager; string[] allRecipeIDs = rm.AllRecipeIDsInCategoty(SCN_CategotyProd); if (null == allRecipeIDs || !allRecipeIDs.Contains(recipeID)) { errorInfo = "产品ID:\"" + recipeID + "\"在配方管理器中不存在"; return(false); } if (WorkStatus == JFWorkStatus.Running || WorkStatus == JFWorkStatus.Interactiving || WorkStatus == JFWorkStatus.Pausing) { errorInfo = "正在运行,不能修改产品ID"; return(false); } IJFDataPool dp = JFHubCenter.Instance.DataPool; bool isOK = dp.SetItemValue(SDN_CurrRecipeID, recipeID); if (!isOK) { errorInfo = "写入数据池失败"; } else { //将当前产品信息写入SystemCfg JFXCfg sysCfg = JFHubCenter.Instance.SystemCfg; if (sysCfg.ContainsItem(SCN_CurrentRecipeID)) { sysCfg.SetItemValue(SCN_CurrentRecipeID, recipeID); //将当前产品ID 加到配置项中 sysCfg.Save(); } errorInfo = "Success"; } return(isOK); }
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> 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; } }
public bool Save() { string path = @"BoxData.ini"; JFXCfg cfg = new JFXCfg(); int i = 0; foreach (var pair in Dir_Boxes) { Box item = pair.Value; cfg.SetItemValue("Box_" + i, item); i++; } Num = Dir_Boxes.Count; cfg.SetItemValue("Count", Num); cfg.Save(path); return(true); }
/// <summary> /// 编辑系统配置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btEditSysCfg_Click(object sender, EventArgs e) { JFXCfg sysCfg = JFHubCenter.Instance.SystemCfg; FormXCfgEdit fm = new FormXCfgEdit(); fm.AllowAddTypes.Add(typeof(Point)); fm.AllowAddTypes.Add(typeof(JFMotionParam)); fm.AllowAddTypes.Add(typeof(JFHomeParam)); fm.AllowAddTypes.Add(typeof(MyStruct)); fm.AllowAddTypes.Add(typeof(JFLinearCalibData)); fm.SetCfg(sysCfg); fm.ShowDialog(); //JFXCfg _cfg = new JFXCfg(); //double[][] demo = new double[2][] { new double[]{ 0,0.1}, new double[]{1.2,3.4 } }; //_cfg.AddItem("二维数组测试", demo,"定制参数"); //_cfg.Save("111.xml"); //fm = new FormXCfgEdit(); //fm.SetCfg(_cfg); //fm.ShowDialog(); }
public bool SetCurrLotID(string lotID, out string errorInfo) { if (string.IsNullOrEmpty(lotID)) { errorInfo = "LotID为null/空字串"; return(false); } if (WorkStatus == JFWorkStatus.Running || WorkStatus == JFWorkStatus.Interactiving || WorkStatus == JFWorkStatus.Pausing) { errorInfo = "正在运行,不能修改LotID"; return(false); } IJFDataPool dp = JFHubCenter.Instance.DataPool; bool isOK = dp.SetItemValue(SDN_CurrLotID, lotID); if (!isOK) { errorInfo = "LotID写入数据池失败"; } else { //将当前产品信息写入SystemCfg JFXCfg sysCfg = JFHubCenter.Instance.SystemCfg; if (sysCfg.ContainsItem(SCN_CurrentLotID)) { sysCfg.SetItemValue(SCN_CurrentLotID, lotID); //将当前LotID 保存到配置项中 sysCfg.Save(); } errorInfo = "Success"; } return(isOK); }
//private JFDev_Aps168MotionDaq AmpMotionDaq; internal JFAps168CompareTrigger(int board_id, JFXCfg jf168Cfg, JFDev_Aps168MotionDaq _AmpMotionDaq) { trigTables = new JFXmlDictionary <int, double[]>(); trigLiners = new JFXmlDictionary <int, JFCompareTrigLinerParam>(); trigModes = new JFXmlDictionary <int, JFCompareTrigMode>(); chnTrig = new JFXmlDictionary <int, int[]>(); trigEnables = new JFXmlDictionary <int, bool>(); lcmpSource = new JFXmlDictionary <int, int>(); tcmpSource = new JFXmlDictionary <int, int>(); tcmpDir = new JFXmlDictionary <int, int>(); lcmprUsed = new JFXmlDictionary <int, bool>(); tcmprUsed = new JFXmlDictionary <int, bool>(); trigLCmprSource = new JFXmlDictionary <int, List <int> >(); trigTCmprSource = new JFXmlDictionary <int, List <int> >(); chnLcmpr = new JFXmlDictionary <int, int>(); chnTcmpr = new JFXmlDictionary <int, int>(); BoardID = board_id; TrigChannels = 0; EncoderChannels = 0; IsOpen = false; _jf168Cfg = jf168Cfg; //AmpMotionDaq = _AmpMotionDaq; }
private void button3_Click(object sender, EventArgs e) { bool isArray = typeof(List <int>).IsArray; //不是 isArray = typeof(object[]).IsArray; //是 Type bt = typeof(List <int>).GetElementType(); //返回null bool isList = typeof(IList).IsAssignableFrom(typeof(List <int>)); //是 bt = typeof(object[]).GetElementType(); //可以获取 Type t = typeof(string[]); SerializableAttribute[] sas = t.GetCustomAttributes(typeof(SerializableAttribute), false) as SerializableAttribute[]; JFXCfg cfg = new JFXCfg(); List <object> lst = new List <object>(); lst.Add(0); lst.Add(new string[] { "hehe", "haha" }); cfg.AddItem("测试复合类型", lst); cfg.Save("测试CfgDemo.xml"); }
/// <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); } } }
/// <summary> /// 编辑/保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btEditSave_Click(object sender, EventArgs e) { if (null == _station) { return; } if (tabControlCF1.SelectedIndex < 0) { return; } if (!isEditting) { TableLayoutPanel panel = tabControlCF1.SelectedTab.Controls[0] as TableLayoutPanel; if (0 == panel.Controls.Count) { //MessageBox.Show("没有可供编辑的参数项"); //return; } foreach (UcJFParamEdit ucParam in panel.Controls) { ucParam.IsValueReadOnly = false; } isEditting = true; btEditSave.Text = "保存"; btCancel.Enabled = true; btSaveAs.Enabled = true; btAddItem.Enabled = true; btDeletItem.Enabled = true; } else { TableLayoutPanel panel = tabControlCF1.SelectedTab.Controls[0] as TableLayoutPanel; foreach (UcJFParamEdit ucParam in panel.Controls) { string paramName = ucParam.GetParamDesribe().DisplayName; object paramVal; if (!ucParam.GetParamValue(out paramVal)) { MessageBox.Show("未能获取参数 Name = " + paramName); return; } //_station.SetCfgParamValue(paramName, paramVal); //ucParam.IsValueReadOnly = false; } JFXCfg cfg = _station.Config; foreach (UcJFParamEdit ucParam in panel.Controls) { string paramName = ucParam.GetParamDesribe().DisplayName; object paramVal; ucParam.GetParamValue(out paramVal); cfg.SetItemValue(paramName, paramVal);//_station.SetCfgParamValue(paramName, paramVal); ucParam.IsValueReadOnly = true; } cfg.Save(); isEditting = false; btEditSave.Text = "编辑"; btCancel.Enabled = false; btSaveAs.Enabled = false; btAddItem.Enabled = false; btDeletItem.Enabled = false; } }
void AdjustStationView() { if (InvokeRequired) { Invoke(new Action(AdjustStationView)); return; } tabControlCF1.TabPages.Clear(); isEditting = false; btEditSave.Text = "编辑"; btCancel.Enabled = false; if (null == _station) { lbInfo.Text = "工站未设置!"; btEditSave.Enabled = false; return; } JFXCfg cfg = _station.Config; lbInfo.Text = "工站:" + _station.Name + " 文件路径:" + 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.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; }
void AdjustStationView() { if (InvokeRequired) { Invoke(new Action(AdjustStationView)); return; } tabControlCF1.TabPages.Clear(); isEditting = false; btEditSave.Text = "编辑"; btCancel.Enabled = false; if (null == _station) { lbInfo.Text = "工站未设置!"; btEditSave.Enabled = false; return; } lbInfo.Text = "工站:" + _station.Name; JFXCfg cfg = _station.Config; string[] categorys = cfg.AllTags; if (null == categorys || categorys.Length < 2) //只有一个无名称Tag,由于保存私有配置 { lbInfo.Text += " 无定制化参数"; btEditSave.Enabled = false; return; } 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.ColumnCount = 1; panel.AutoScroll = true; panel.Dock = DockStyle.Fill; tp.Controls.Add(panel); foreach (string itemName in itemNames) { UcJFParamEdit ucParam = new UcJFParamEdit(); ucParam.IsHelpVisible = false; ucParam.Height = 23; ucParam.SetParamDesribe(_station.GetCfgParamDescribe(itemName)); ucParam.SetParamValue(_station.GetCfgParamValue(itemName)); ucParam.IsValueReadOnly = false; panel.Controls.Add(ucParam); ucParam.IsValueReadOnly = true; } } //if (tabControlCF1.TabCount > 0) // tabControlCF1.SelectedIndex = 0; }