Exemplo n.º 1
0
        /// <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,可获取
        }
Exemplo n.º 2
0
        private void btAddItem_Click(object sender, EventArgs e)
        {
            if (null == _cfg)
            {
                return;
            }
            if (tabControlCF1.SelectedIndex < 0)
            {
                MessageBox.Show("请在右侧Tab栏选择数据项类别!");
                return;
            }
            FormXCfgItemEdit fmAddItem = new FormXCfgItemEdit();

            fmAddItem.SetItemAllowedTypes(AllowAddTypes.ToArray());
            if (DialogResult.OK == fmAddItem.ShowDialog())
            {
                string itemName = fmAddItem.GetItemName();
                if (_cfg.ContainsItem(itemName))
                {
                    MessageBox.Show("已包含同名配置项,不能重复添加");
                    return;
                }
                string itemTag = tabControlCF1.SelectedTab.Text;
                object itemVal = fmAddItem.GetItemValue();

                _cfg.AddItem(itemName, itemVal, itemTag);
                _cfg.Save();
                UpdateCurrPage(true);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        /// <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);
                }
            }
        }
Exemplo n.º 7
0
        /// <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;
        }