internal JFStationManager(string cfgPath) { _cfg.Load(cfgPath, true); if (!_cfg.ContainsItem("StationEnabled")) { _dictStationEnabled = new JFXmlDictionary <string, bool>(); _cfg.AddItem("StationEnabled", _dictStationEnabled); } else { _dictStationEnabled = _cfg.GetItemValue("StationEnabled") as JFXmlDictionary <string, bool>; } List <string> existedStationNames = _initorStationNames(); List <string> stationNamesInCfg = _dictStationEnabled.Keys.ToList(); if (null == existedStationNames) { _dictStationEnabled.Clear(); } else { foreach (string cfgName in stationNamesInCfg) //去除多余的项 { if (!existedStationNames.Contains(cfgName)) { _dictStationEnabled.Remove(cfgName); } } foreach (string exsitedName in existedStationNames) //添加缺少的项 { if (!_dictStationEnabled.ContainsKey(exsitedName)) { _dictStationEnabled.Add(exsitedName, true); //SetStationEnabled(exsitedName, true); } } } ///添加默认的消息回调 foreach (string stationName in _dictStationEnabled.Keys) { IJFStation station = GetStation(stationName); station.WorkStatusChanged += StationWorkStatusChanged; station.CustomStatusChanged += StationCustomStatusChanged; if (station is JFCmdWorkBase) { (station as JFCmdWorkBase).WorkMsg2Outter += StationTxtMsg; } if (station is JFStationBase) { (station as JFStationBase).EventCustomizeMsg += StationCustomizeMsg; (station as JFStationBase).EventProductFinished += StationProductFinished; } } _cfg.Save(); DeclearedStationNames = new List <string>(); StartShowStationLog(); }
/// <summary> /// 更新VisionCfgName /// </summary> private bool UpdateVisionCfgNames() { int startIndex = 0; int endIndex = 0; int fovCount = _visionCfgParams.Keys.Count; for (int m = 0; m < fovCount; m++) { JFXmlDictionary <string, JFXmlDictionary <string, string> > dicFovVisionCfgName = _visionCfgParams[m.ToString()]; foreach (string fovname in dicFovVisionCfgName.Keys) { JFXmlDictionary <string, string> visionCfgNames = dicFovVisionCfgName[fovname]; endIndex = startIndex + visionCfgNames.Keys.Count; visionCfgNames.Clear(); for (int i = startIndex; i < endIndex; i++) { if (dgvVisionCfg.Rows[i].Cells[1].Value.ToString() == "") { MessageBox.Show(string.Format("当前行{0}的Task名称不可为空", i)); return(false); } if (visionCfgNames.ContainsKey(dgvVisionCfg.Rows[i].Cells[1].Value.ToString())) { MessageBox.Show(string.Format("视野名称为{0}的光源配置名{1}已存在", fovname, dgvVisionCfg.Rows[i].Cells[1].Value.ToString())); return(false); } visionCfgNames.Add(dgvVisionCfg.Rows[i].Cells[1].Value.ToString(), dgvVisionCfg.Rows[i].Cells[2].Value.ToString()); } startIndex = endIndex; } } return(true); }
public void Save() { if (!IsInitOK) { return; } JFXmlDictionary <string, List <string[]> > dctRecipesInCfg = _cfg.GetItemValue("Cate-Recipes") as JFXmlDictionary <string, List <string[]> >; foreach (string categoty in _dctRecipes.Keys) { Dictionary <string, JFCommonRecipe> dctMmry = _dctRecipes[categoty]; //所有recipe内存对象 List <string[]> lstInCfg = dctRecipesInCfg[categoty]; foreach (KeyValuePair <string, JFCommonRecipe> kv in dctMmry) { foreach (string[] idAndTxt in lstInCfg) { if (idAndTxt[0] == kv.Key) { string xmlTxt = null; string typeTxt = null; JFFunctions.ToXTString(kv.Value.Dict, out xmlTxt, out typeTxt); idAndTxt[1] = xmlTxt; break; } } } } _cfg.Save(); }
///// <summary> ///// 添加一个产品类别 ///// </summary> ///// <param name="recipeCategoty"></param> //void AddRecipeCategoty(string categoty); /// <summary> /// 移除一个类别(下的所有RecipeID) /// </summary> /// <param name="recipeCategoty"></param> public void RemoveCategoty(string categoty) { if (!_cfg.ContainsItem("Categoties")) { return; } //移除配置参数 List <string> categoties = _cfg.GetItemValue("Categoties") as List <string>; if (!categoties.Contains(categoty)) { return; } categoties.Remove(categoty); JFXmlDictionary <string, List <string[]> > recipesInCfg = _cfg.GetItemValue("Cate-Recipes") as JFXmlDictionary <string, List <string[]> >; if (recipesInCfg.ContainsKey(categoty)) { recipesInCfg.Remove(categoty); } //移除内存对象 if (_dctRecipes.ContainsKey(categoty)) { _dctRecipes.Remove(categoty); } }
/// <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); }
/// <summary> /// 添加一个产品/配方 /// </summary> /// <param name="categoty"></param> /// <param name="recipeID"></param> /// <param name="recipe"></param> public bool AddRecipe(string categoty, string recipeID, IJFRecipe recipe = null) { if (string.IsNullOrEmpty(categoty)) { return(false); } if (string.IsNullOrEmpty(recipeID)) { return(false); } if (recipe != null && recipe.GetType() != typeof(JFCommonRecipe)) { return(false); } if (GetRecipe(categoty, recipeID) != null) //已已存在同名Recipe { return(false); } JFCommonRecipe cmRecipe = recipe as JFCommonRecipe; if (null == cmRecipe) { cmRecipe = new JFCommonRecipe(); } cmRecipe.ID = recipeID; cmRecipe.Categoty = categoty; List <string> lstCatesInCfg = _cfg.GetItemValue("Categoties") as List <string>; if (!lstCatesInCfg.Contains(categoty)) { lstCatesInCfg.Add(categoty); } JFXmlDictionary <string, List <string[]> > dctRecipesInCfg = _cfg.GetItemValue("Cate-Recipes") as JFXmlDictionary <string, List <string[]> >; if (!dctRecipesInCfg.ContainsKey(categoty)) { dctRecipesInCfg.Add(categoty, new List <string[]>()); } List <string[]> lstIDAndTxt = dctRecipesInCfg[categoty]; lstIDAndTxt.Add(new string[] { recipeID, cmRecipe.Dict.ToString() }); if (!_dctRecipes.ContainsKey(categoty)) { _dctRecipes.Add(categoty, new Dictionary <string, JFCommonRecipe>()); } Dictionary <string, JFCommonRecipe> dctInMmry = _dctRecipes[categoty]; dctInMmry.Add(recipeID, cmRecipe); return(true); }
/// <summary> /// 移出一个产品配方 /// </summary> /// <param name="categoty"></param> /// <param name="recipeID"></param> /// <returns></returns> public IJFRecipe RemoveRecipe(string categoty, string recipeID) { if (string.IsNullOrEmpty(categoty)) { return(null); } if (string.IsNullOrEmpty(recipeID)) { return(null); } IJFRecipe ret = GetRecipe(categoty, recipeID); if (ret == null) //已已存在同名Recipe { return(ret); } Dictionary <string, JFCommonRecipe> dctInMmry = _dctRecipes[categoty]; dctInMmry.Remove(recipeID); if (dctInMmry.Count == 0) { _dctRecipes.Remove(categoty); } JFXmlDictionary <string, List <string[]> > dctRecipesInCfg = _cfg.GetItemValue("Cate-Recipes") as JFXmlDictionary <string, List <string[]> >; List <string[]> lstIDAndTxt = dctRecipesInCfg[categoty]; for (int i = 0; i < lstIDAndTxt.Count; i++) { if (lstIDAndTxt[i][0] == recipeID) { lstIDAndTxt.RemoveAt(i); break; } } if (lstIDAndTxt.Count == 0) { dctRecipesInCfg.Remove(categoty); List <string> lstCatesInCfg = _cfg.GetItemValue("Categoties") as List <string>; lstCatesInCfg.Remove(categoty); } return(ret); }
/// <summary> /// 获取指定类别下的所有产品/配方 ID /// </summary> /// <returns></returns> public string[] AllRecipeIDsInCategoty(string categoty) { JFXmlDictionary <string, List <string[]> > cateRecipes = _cfg.GetItemValue("Cate-Recipes") as JFXmlDictionary <string, List <string[]> >; if (!cateRecipes.ContainsKey(categoty)) { return(null); } List <string[]> recipes = cateRecipes[categoty]; List <string> ret = new List <string>(); foreach (string[] sa in recipes) { ret.Add(sa[0]); } return(ret.ToArray()); }
/// <summary> /// 更新UI /// </summary> private void SetupUI() { if (_visionCfgParams != null) { int fovCount = _visionCfgParams.Keys.Count; for (int i = 0; i < fovCount; i++) { JFXmlDictionary <string, JFXmlDictionary <string, string> > fovVisionCfg = _visionCfgParams[i.ToString()]; foreach (string fovname in fovVisionCfg.Keys) { JFXmlDictionary <string, string> keyValuePairs = fovVisionCfg[fovname]; foreach (string taskname in keyValuePairs.Keys) { AddDataGridViewFunction(dgvVisionCfg, fovname, taskname, keyValuePairs[taskname].ToString()); } } } } }
//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; }
public JFCommonRecipe() { Dict = new JFXmlDictionary <string, object>(); }
public Form_VisionCfgManager(JFXmlDictionary <string, JFXmlDictionary <string, JFXmlDictionary <string, string> > > visionCfgParams) { InitializeComponent(); _visionCfgParams = new JFXmlDictionary <string, JFXmlDictionary <string, JFXmlDictionary <string, string> > >(); _visionCfgParams = visionCfgParams; }
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 { } }
/// <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> /// 根据Station中声明的设备通道变量布局界面 /// </summary> void AdjustStationView() { tabControlCF1.TabPages.Clear(); _isEditting = false; btEditCancel.Enabled = false; btEditSave.Text = "编辑"; if (null == _station) { lbStationName.Text = "未设置"; btEditSave.Enabled = false; return; } lbStationName.Text = _station.Name; btEditSave.Enabled = true; JFXmlDictionary <NamedChnType, List <List <string> > > devChns = _station.DeclearedDevChnMapping; ///工站声明的轴 if (devChns.ContainsKey(NamedChnType.Axis)) { List <List <string> > chnMapping = devChns[NamedChnType.Axis]; if (null != chnMapping && chnMapping.Count > 0) { TabPage tp = new TabPage("Axis"); tp.Tag = NamedChnType.Axis; tabControlCF1.TabPages.Add(tp); tp.AutoScroll = true; DataGridView dgv = new DataGridView(); dgv.Columns.Add(new DataGridViewTextBoxColumn()); dgv.Columns.Add(new DataGridViewComboBoxColumn()); dgv.Columns[0].HeaderText = "轴名/站内"; dgv.Columns[0].Width = 200; dgv.Columns[1].HeaderText = "全局标识名"; dgv.Columns[1].Width = 300; dgv.Dock = DockStyle.Fill; dgv.ReadOnly = true; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AllowUserToResizeRows = false; dgv.RowHeadersVisible = false; tp.Controls.Add(dgv); foreach (List <string> locAndGlobName in chnMapping) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellLocName = new DataGridViewTextBoxCell(); cellLocName.Value = locAndGlobName[0]; DataGridViewComboBoxCell cellGlobName = new DataGridViewComboBoxCell(); if (locAndGlobName.Count > 1) { cellGlobName.Value = locAndGlobName[1]; } //cellGlobName.Items.Add() row.Cells.Add(cellLocName); row.Cells.Add(cellGlobName); dgv.Rows.Add(row); } } } ///工站声明的DI if (devChns.ContainsKey(NamedChnType.Di)) { List <List <string> > chnMapping = devChns[NamedChnType.Di]; if (null != chnMapping && chnMapping.Count > 0) { TabPage tp = new TabPage("DI"); tp.Tag = NamedChnType.Di; tabControlCF1.TabPages.Add(tp); tp.AutoScroll = true; DataGridView dgv = new DataGridView(); dgv.Columns.Add(new DataGridViewTextBoxColumn()); dgv.Columns.Add(new DataGridViewComboBoxColumn()); dgv.Columns[0].HeaderText = "DI名/站内"; dgv.Columns[0].Width = 200; dgv.Columns[0].ReadOnly = true; dgv.Columns[1].HeaderText = "全局标识名"; dgv.Columns[1].Width = 300; dgv.Columns[1].ReadOnly = true; dgv.Dock = DockStyle.Fill; dgv.ReadOnly = true; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AllowUserToResizeRows = false; dgv.RowHeadersVisible = false; tp.Controls.Add(dgv); foreach (List <string> locAndGlobName in chnMapping) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellLocName = new DataGridViewTextBoxCell(); cellLocName.Value = locAndGlobName[0]; DataGridViewComboBoxCell cellGlobName = new DataGridViewComboBoxCell(); if (locAndGlobName.Count > 1) { cellGlobName.Value = locAndGlobName[1]; } //cellGlobName.Items.Add() row.Cells.Add(cellLocName); row.Cells.Add(cellGlobName); dgv.Rows.Add(row); } } } ///工站声明的DO if (devChns.ContainsKey(NamedChnType.Do)) { List <List <string> > chnMapping = devChns[NamedChnType.Do]; if (null != chnMapping && chnMapping.Count > 0) { TabPage tp = new TabPage("DO"); tp.Tag = NamedChnType.Do; tabControlCF1.TabPages.Add(tp); tp.AutoScroll = true; DataGridView dgv = new DataGridView(); dgv.Columns.Add(new DataGridViewTextBoxColumn()); dgv.Columns.Add(new DataGridViewComboBoxColumn()); dgv.Columns[0].HeaderText = "DO名/站内"; dgv.Columns[0].Width = 200; dgv.Columns[0].ReadOnly = true; dgv.Columns[1].HeaderText = "全局标识名"; dgv.Columns[1].Width = 300; dgv.Columns[1].ReadOnly = true; dgv.Dock = DockStyle.Fill; dgv.ReadOnly = true; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AllowUserToResizeRows = false; dgv.RowHeadersVisible = false; tp.Controls.Add(dgv); foreach (List <string> locAndGlobName in chnMapping) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellLocName = new DataGridViewTextBoxCell(); cellLocName.Value = locAndGlobName[0]; DataGridViewComboBoxCell cellGlobName = new DataGridViewComboBoxCell(); if (locAndGlobName.Count > 1) { cellGlobName.Value = locAndGlobName[1]; } //cellGlobName.Items.Add() row.Cells.Add(cellLocName); row.Cells.Add(cellGlobName); dgv.Rows.Add(row); } } } ///工站声明的Cmr if (devChns.ContainsKey(NamedChnType.Camera)) { List <List <string> > cmrMapping = devChns[NamedChnType.Camera]; if (null != cmrMapping && cmrMapping.Count > 0) { TabPage tp = new TabPage("Camera"); tp.Tag = NamedChnType.Camera; tabControlCF1.TabPages.Add(tp); tp.AutoScroll = true; DataGridView dgv = new DataGridView(); dgv.Columns.Add(new DataGridViewTextBoxColumn()); dgv.Columns.Add(new DataGridViewComboBoxColumn()); dgv.Columns[0].HeaderText = "相机名/站内"; dgv.Columns[0].Width = 200; dgv.Columns[0].ReadOnly = true; dgv.Columns[1].HeaderText = "全局标识名"; dgv.Columns[1].Width = 300; dgv.Columns[1].ReadOnly = true; dgv.Dock = DockStyle.Fill; dgv.ReadOnly = true; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AllowUserToResizeRows = false; dgv.RowHeadersVisible = false; tp.Controls.Add(dgv); foreach (List <string> cmrLocGlobName in cmrMapping) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellLocName = new DataGridViewTextBoxCell(); cellLocName.Value = cmrLocGlobName[0]; DataGridViewComboBoxCell cellGlobName = new DataGridViewComboBoxCell(); if (cmrLocGlobName.Count > 1) { cellGlobName.Value = cmrLocGlobName[1]; } //cellGlobName.Items.Add() row.Cells.Add(cellLocName); row.Cells.Add(cellGlobName); dgv.Rows.Add(row); } } } ///工站声明的光源 if (devChns.ContainsKey(NamedChnType.Light)) { List <List <string> > chnMapping = devChns[NamedChnType.Light]; if (null != chnMapping && chnMapping.Count > 0) { TabPage tp = new TabPage("Light"); tp.Tag = NamedChnType.Light; tabControlCF1.TabPages.Add(tp); tp.AutoScroll = true; DataGridView dgv = new DataGridView(); dgv.Columns.Add(new DataGridViewTextBoxColumn()); dgv.Columns.Add(new DataGridViewComboBoxColumn()); dgv.Columns[0].HeaderText = "开关光源名/站内"; dgv.Columns[0].Width = 200; dgv.Columns[0].ReadOnly = true; dgv.Columns[1].HeaderText = "全局标识名"; dgv.Columns[1].Width = 300; dgv.Columns[1].ReadOnly = true; dgv.Dock = DockStyle.Fill; dgv.ReadOnly = true; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AllowUserToResizeRows = false; dgv.RowHeadersVisible = false; tp.Controls.Add(dgv); foreach (List <string> locAndGlobName in chnMapping) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellLocName = new DataGridViewTextBoxCell(); cellLocName.Value = locAndGlobName[0]; DataGridViewComboBoxCell cellGlobName = new DataGridViewComboBoxCell(); if (locAndGlobName.Count > 1) { cellGlobName.Value = locAndGlobName[1]; } //cellGlobName.Items.Add() row.Cells.Add(cellLocName); row.Cells.Add(cellGlobName); dgv.Rows.Add(row); } } } ///工站声明的(光源)触发通道 if (devChns.ContainsKey(NamedChnType.Trig)) { List <List <string> > chnMapping = devChns[NamedChnType.Trig]; if (null != chnMapping && chnMapping.Count > 0) { TabPage tp = new TabPage("Trig"); tp.Tag = NamedChnType.Trig; tabControlCF1.TabPages.Add(tp); tp.AutoScroll = true; DataGridView dgv = new DataGridView(); dgv.Columns.Add(new DataGridViewTextBoxColumn()); dgv.Columns.Add(new DataGridViewComboBoxColumn()); dgv.Columns[0].HeaderText = "触发光源名/站内"; dgv.Columns[0].Width = 200; dgv.Columns[0].ReadOnly = true; dgv.Columns[1].HeaderText = "全局标识名"; dgv.Columns[1].Width = 300; dgv.Columns[1].ReadOnly = true; dgv.Dock = DockStyle.Fill; dgv.ReadOnly = true; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AllowUserToResizeRows = false; dgv.RowHeadersVisible = false; tp.Controls.Add(dgv); foreach (List <string> locAndGlobName in chnMapping) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellLocName = new DataGridViewTextBoxCell(); cellLocName.Value = chnMapping[0]; DataGridViewComboBoxCell cellGlobName = new DataGridViewComboBoxCell(); if (locAndGlobName.Count > 1) { cellGlobName.Value = locAndGlobName[1]; } //cellGlobName.Items.Add() row.Cells.Add(cellLocName); row.Cells.Add(cellGlobName); dgv.Rows.Add(row); } } } ///工站声明的比较触发器 if (devChns.ContainsKey(NamedChnType.CmpTrig)) { List <List <string> > chnMapping = devChns[NamedChnType.CmpTrig]; if (null != chnMapping && chnMapping.Count > 0) { TabPage tp = new TabPage("CmpTrig"); tp.Tag = NamedChnType.CmpTrig; tabControlCF1.TabPages.Add(tp); tp.AutoScroll = true; DataGridView dgv = new DataGridView(); dgv.Columns.Add(new DataGridViewTextBoxColumn()); dgv.Columns.Add(new DataGridViewComboBoxColumn()); dgv.Columns[0].HeaderText = "位置比较触发器名/站内"; dgv.Columns[0].Width = 200; dgv.Columns[0].ReadOnly = true; dgv.Columns[1].HeaderText = "全局标识名"; dgv.Columns[1].Width = 300; dgv.Columns[1].ReadOnly = true; dgv.Dock = DockStyle.Fill; dgv.ReadOnly = true; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AllowUserToResizeRows = false; dgv.RowHeadersVisible = false; tp.Controls.Add(dgv); foreach (List <string> locAndGlobName in chnMapping) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellLocName = new DataGridViewTextBoxCell(); cellLocName.Value = chnMapping[0]; DataGridViewComboBoxCell cellGlobName = new DataGridViewComboBoxCell(); if (locAndGlobName.Count > 1) { cellGlobName.Value = locAndGlobName[1]; } //cellGlobName.Items.Add() row.Cells.Add(cellLocName); row.Cells.Add(cellGlobName); dgv.Rows.Add(row); } } } ///工站声明的AI if (devChns.ContainsKey(NamedChnType.Ai)) { List <List <string> > chnMapping = devChns[NamedChnType.Ai]; if (null != chnMapping && chnMapping.Count > 0) { TabPage tp = new TabPage("Ai"); tp.Tag = NamedChnType.Ai; tabControlCF1.TabPages.Add(tp); tp.AutoScroll = true; DataGridView dgv = new DataGridView(); dgv.Columns.Add(new DataGridViewTextBoxColumn()); dgv.Columns.Add(new DataGridViewComboBoxColumn()); dgv.Columns[0].HeaderText = "Ai名/站内"; dgv.Columns[0].Width = 200; dgv.Columns[0].ReadOnly = true; dgv.Columns[1].HeaderText = "全局标识名"; dgv.Columns[1].Width = 300; dgv.Columns[1].ReadOnly = true; dgv.Dock = DockStyle.Fill; dgv.ReadOnly = true; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AllowUserToResizeRows = false; dgv.RowHeadersVisible = false; tp.Controls.Add(dgv); foreach (List <string> locAndGlobName in chnMapping) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellLocName = new DataGridViewTextBoxCell(); cellLocName.Value = locAndGlobName[0]; DataGridViewComboBoxCell cellGlobName = new DataGridViewComboBoxCell(); if (chnMapping.Count > 1) { cellGlobName.Value = locAndGlobName[1]; } //cellGlobName.Items.Add() row.Cells.Add(cellLocName); row.Cells.Add(cellGlobName); dgv.Rows.Add(row); } } } ///工站声明的AO if (devChns.ContainsKey(NamedChnType.Ao)) { List <List <string> > chnMapping = devChns[NamedChnType.Ao]; if (null != chnMapping && chnMapping.Count > 0) { TabPage tp = new TabPage("Ao"); tp.Tag = NamedChnType.Ao; tabControlCF1.TabPages.Add(tp); tp.AutoScroll = true; DataGridView dgv = new DataGridView(); dgv.Columns.Add(new DataGridViewTextBoxColumn()); dgv.Columns.Add(new DataGridViewComboBoxColumn()); dgv.Columns[0].HeaderText = "Ao名/站内"; dgv.Columns[0].Width = 200; dgv.Columns[0].ReadOnly = true; dgv.Columns[1].HeaderText = "全局标识名"; dgv.Columns[1].Width = 300; dgv.Columns[1].ReadOnly = true; dgv.Dock = DockStyle.Fill; dgv.ReadOnly = true; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AllowUserToResizeRows = false; dgv.RowHeadersVisible = false; tp.Controls.Add(dgv); foreach (List <string> locAndGlobName in chnMapping) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellLocName = new DataGridViewTextBoxCell(); cellLocName.Value = chnMapping[0]; DataGridViewComboBoxCell cellGlobName = new DataGridViewComboBoxCell(); if (locAndGlobName.Count > 1) { cellGlobName.Value = locAndGlobName[1]; } //cellGlobName.Items.Add() row.Cells.Add(cellLocName); row.Cells.Add(cellGlobName); dgv.Rows.Add(row); } } } LoadStation(); }
/// <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; }