Example #1
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            string diName = GetInitParamValue("DI通道名称") as string;

            if (!JFHubCenter.Instance.MDCellNameMgr.ContainDiName(diName))
            {
                errorInfo = "DI通道名称:" + diName + " 在设备命名表中不存在";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            IJFInitializable dev = null;
            JFDevCellInfo    ci  = null;

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.DI, diName, out dev, out ci, out errorInfo))
            {
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            bool isTurnOn = false;
            int  errCode  = (dev as IJFDevice_MotionDaq).GetDio(ci.ModuleIndex).GetDI(ci.ChannelIndex, out isTurnOn);

            if (errCode != 0)
            {
                errorInfo = (dev as IJFDevice_MotionDaq).GetDio(ci.ModuleIndex).GetErrorInfo(errCode);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            errorInfo = "Success";
            SetOutputParamValue("执行结果", JFWorkCmdResult.Success);
            SetOutputParamValue("DI状态", isTurnOn);
            return(true);
        }
Example #2
0
        /// <summary>
        /// 软触发
        /// </summary>
        /// <param name="TrigChnName"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public int SWPosTrig(string[] TrigChnName, out string errMsg)
        {
            IJFInitializable dev = null;
            JFDevCellInfo    ci  = null;

            errMsg = "";

            if (TrigChnName.Length == 0)
            {
                errMsg = "触发通道名称为空";
                return((int)ErrorDef.InvokeFailed);
            }

            int[] trigChns = new int[TrigChnName.Length];
            for (int i = 0; i < TrigChnName.Length; i++)
            {
                if (!JFCMFunction.CheckDevCellName(JFCMFunction.CmpTrig, TrigChnName[i], out dev, out ci, out errMsg))
                {
                    return((int)ErrorDef.InvokeFailed);
                }
                trigChns[i] = ci.ChannelIndex;
            }

            IJFModule_CmprTrigger md = (dev as IJFDevice_MotionDaq).GetCompareTrigger(ci.ModuleIndex);
            int errCode = md.SoftTrigge(trigChns);

            if (errCode != (int)ErrorDef.Success)
            {
                errMsg = md.GetErrorInfo(errCode);
                return(errCode);
            }
            return((int)ErrorDef.Success);
        }
Example #3
0
        /// <summary>
        /// 将界面上的初始化参数保存到Method中
        /// </summary>
        /// <returns></returns>
        bool UI2InitParam()
        {
            if (null == _method)
            {
                return(true);
            }
            if (!(_method is IJFInitializable))
            {
                return(true);
            }
            IJFInitializable initor = _method as IJFInitializable;

            string[] initName = initor.InitParamNames;
            if (null == initName)
            {
                return(true);
            }
            for (int i = 0; i < initName.Length; i++)
            {
                object val;
                if (!_lstUcParam[i].GetParamValue(out val))
                {
                    MessageBox.Show("参数\"" + initName[i] + "\"设置失败,错误信息:\n" + _lstUcParam[i].GetParamErrorInfo());
                    return(false);
                }
                if (!initor.SetInitParamValue(initName[i], val))
                {
                    MessageBox.Show("参数\"" + initName[i] + "\"设置失败,错误信息:\n" + initor.GetInitErrorInfo());
                    return(false);
                }
            }

            return(true);
        }
Example #4
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            IJFInitializable dev    = null;
            JFDevCellInfo    ci     = null;
            string           axisID = GetInitParamValue("轴ID") as string;

            if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisID))
            {
                errorInfo = "参数项:\"轴ID\" = " + axisID + " 在设备名称表中不存在";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.Axis, axisID, out dev, out ci, out errorInfo))
            {
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            bool             isPositive = (bool)GetInitParamValue("正向移动");
            IJFModule_Motion md         = (dev as IJFDevice_MotionDaq).GetMc(ci.ModuleIndex);
            int errCode = md.Jog(ci.ChannelIndex, isPositive);

            if (errCode < 0)
            {
                errorInfo = "SDK调用出错:" + md.GetErrorInfo(errCode);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }
            errorInfo = "Success";
            SetOutputParamValue("执行结果", JFWorkCmdResult.Success);
            return(true);
        }
Example #5
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            string doName  = GetMethodInputValue("DO通道名称") as string;
            bool   enabled = (bool)GetMethodInputValue("DO状态");

            if (!JFHubCenter.Instance.MDCellNameMgr.ContainDoName(doName))
            {
                errorInfo = "参数项:\"DO通道名称\"的值:\"" + doName + "\"在设备名称表中不存在";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            IJFInitializable dev = null;
            JFDevCellInfo    ci  = null;

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.DO, doName, out dev, out ci, out errorInfo))
            {
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            int errCode = (dev as IJFDevice_MotionDaq).GetDio(ci.ModuleIndex).SetDO(ci.ChannelIndex, enabled);

            if (errCode != 0)
            {
                errorInfo = (enabled ? "打开" : "关闭") + "DO = " + doName + " 失败," + (dev as IJFDevice_MotionDaq).GetDio(ci.ModuleIndex).GetErrorInfo(errCode);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }
            errorInfo = "Success";
            SetOutputParamValue("执行结果", JFWorkCmdResult.Success);
            return(true);
        }
Example #6
0
        public int CaputreOneImage(string cmrName, string imageType, out HObject hObject, out string errMsg, int timeoutMilSwconds = -1)
        {
            IJFInitializable dev   = null;
            JFDevCellInfo    ci    = null;
            IJFImage         image = null;

            hObject = null;
            errMsg  = "";

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.Cmr, cmrName, out dev, out ci, out errMsg))
            {
                return((int)ErrorDef.InvokeFailed);
            }

            IJFDevice_Camera cmr = (dev as IJFDevice_Camera);

            cmr.ClearBuff();
            int errCode = cmr.GrabOne(out image, timeoutMilSwconds);

            if (errCode != (int)ErrorDef.Success)
            {
                errMsg = cmr.GetErrorInfo(errCode);
                return(errCode);
            }

            if (GenImgObject(imageType, image, out hObject, out errMsg) != 0)
            {
                return((int)ErrorDef.InvokeFailed);
            }
            return((int)ErrorDef.Success);
        }
Example #7
0
 /// <summary>
 /// 获取Initor对象对应的ID
 /// </summary>
 /// <param name="initor"></param>
 /// <returns></returns>
 public string GetIDByInitor(IJFInitializable initor)
 {
     if (!dictInitors.ContainsValue(initor))
     {
         return(null);
     }
     return(dictInitors.FirstOrDefault(q => q.Value == initor).Key);
 }
Example #8
0
        /// <summary>初始化设备</summary>
        private void btInit_Click(object sender, EventArgs e)
        {
            IJFInitializable initor = JFHubCenter.Instance.InitorManager[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()];

            if (!initor.Initialize())
            {
                MessageBox.Show("初始化失败:" + initor.GetInitErrorInfo());
            }
        }
Example #9
0
        /// <summary>取消编辑,将配置中的参数恢复到界面和对象中</summary>
        private void btCancel_Click(object sender, EventArgs e)
        {
            IJFInitializable dev = JFHubCenter.Instance.InitorManager[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()];
            JFXmlSortedDictionary <string, List <object> > devCfg = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >;
            List <object> initParams = devCfg[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()];

            for (int i = 1; i < initParams.Count; i++)
            {
                UcJFParamEdit pe = gbParams.Controls[i + 4] as UcJFParamEdit;
                pe.SetParamValue(initParams[i]);
                pe.IsValueReadOnly = true;
                dev.SetInitParamValue(dev.InitParamNames[i - 1], initParams[i]);
            }
            btInit.Enabled   = !dev.IsInitOK;
            btAdd.Enabled    = true;
            btRemove.Enabled = true;
            //btDebug.Enabled = true;
            isEditting       = false;
            btEditSave.Text  = "编辑参数";
            btCancel.Enabled = false;
            dgvDevs.Enabled  = true;

            Type devType = dev.GetType();

            if (typeof(IJFDevice_Camera).IsAssignableFrom(devType) ||
                typeof(IJFDevice_LightController).IsAssignableFrom(devType) ||
                typeof(IJFDevice_MotionDaq).IsAssignableFrom(devType) ||
                typeof(IJFDevice_TrigController).IsAssignableFrom(devType) ||
                typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) //提供调试界面
            {
                btDebug.Enabled = true;
                if (typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType))
                {
                    chkSelfUI.Enabled = true;
                }
                else
                {
                    chkSelfUI.Checked = false;
                    chkSelfUI.Enabled = false;
                }
            }
            else
            {
                btDebug.Enabled = false;
            }

            if (typeof(IJFConfigUIProvider).IsAssignableFrom(devType))
            {
                btCfg.Enabled = true;
            }
            else
            {
                btCfg.Enabled = false;
            }
        }
Example #10
0
 /// <summary>
 /// 设置/保存 初始化参数
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void OnButtonClick_InitParamSetSave(object sender, EventArgs e)
 {
     if (!isInitParamEditting) //开放参数编辑
     {
         isInitParamEditting = true;
         foreach (UcJFParamEdit pe in _lstUcParam)
         {
             pe.IsValueReadOnly = false;
         }
         btSetSaveInit.Text   = "保存初始化参数";
         btCancelInit.Enabled = true;
     }
     else //保存参数修改
     {
         if (UI2InitParam())
         {
             foreach (UcJFParamEdit pe in _lstUcParam)
             {
                 pe.IsValueReadOnly = true;
             }
             btSetSaveInit.Text   = "编辑初始化参数";
             btCancelInit.Enabled = false;
             isInitParamEditting  = false;
             ///添加方法对象的(重新)初始化动作
             IJFInitializable initor = _method as IJFInitializable;
             foreach (UcJFParamEdit pe in _lstUcParam)
             {
                 string initParamName = pe.GetParamDesribe().DisplayName;
                 object paramValue    = null;
                 bool   isOK          = pe.GetParamValue(out paramValue);
                 if (!isOK)
                 {
                     MessageBox.Show("未能重新初始化方法对象\n请检查参数:\"" + initParamName + "\"");
                     return;
                 }
                 isOK = initor.SetInitParamValue(initParamName, paramValue);
                 if (!isOK)
                 {
                     MessageBox.Show("未能重新初始化方法对象\n设置参数:\"" + initParamName + "\"失败:" + initor.GetInitErrorInfo());
                     return;
                 }
                 isOK = initor.Initialize();
                 if (!isOK)
                 {
                     MessageBox.Show("重新初始化方法对象失败\n错误信息:" + initor.GetInitErrorInfo());
                     return;
                 }
             }
         }
     }
 }
Example #11
0
        /// <summary>确定创建Initor对象</summary>
        private void btOK_Click(object sender, EventArgs e)
        {
            if (dgvTypes.SelectedRows == null || dgvTypes.SelectedRows.Count == 0)
            {
                MessageBox.Show("请选择需要创建的设备类型");
                return;
            }
            if (string.IsNullOrWhiteSpace(tbID.Text))
            {
                MessageBox.Show("设备ID不能为空,请重新输入");
                tbID.Focus();
                return;
            }

            if (!_isFixedID && JFHubCenter.Instance.InitorManager.ContainID(tbID.Text))
            {
                IJFInitializable dev         = JFHubCenter.Instance.InitorManager.GetInitor(tbID.Text);
                string           disTypeName = JFinitializerHelper.DispalyTypeName(dev.GetType());
                MessageBox.Show(string.Format("Initor列表中已存在ID = \"{0}\" Type = \"{1}\"的设备\n请重新输入ID!", tbID.Text, disTypeName));
                tbID.Focus();
                return;
            }
            //IJFDevice newDev = JFHubCenter.Instance.InitorHelp.CreateInstance(dgvTypes.SelectedRows[0].Cells[0].Value.ToString()) as IJFDevice;

            //for (int i = 2; i < gbParams.Controls.Count;i++)
            for (int i = 0; i < panelParams.Controls.Count; i++)
            {
                //UcJFParamEdit pe = gbParams.Controls[i] as UcJFParamEdit;
                UcJFParamEdit pe       = panelParams.Controls[i] as UcJFParamEdit;
                object        paramVal = null;
                if (!pe.GetParamValue(out paramVal))
                {
                    MessageBox.Show("初始化参数:\"" + pe.Name + "\"获取失败!Error:" + pe.GetParamErrorInfo());
                    //newDev.Dispose();
                    pe.Focus();
                    return;
                }
                if (!initor.SetInitParamValue(initor.InitParamNames[i], paramVal))
                {
                    MessageBox.Show(string.Format("设置初始化参数失败:Name = {0},Value = {1}", initor.InitParamNames[i], paramVal.ToString()));
                    //newDev.Dispose();
                    pe.Focus();
                    return;
                }
            }

            DialogResult = DialogResult.OK;
        }
Example #12
0
        private void btCfg_Click(object sender, EventArgs e)
        {
            if (dgvDevs.SelectedRows == null || dgvDevs.SelectedRows.Count == 0)
            {
                MessageBox.Show("请选择需要设置的" + InitorCaption + "对象!");
                return;
            }

            IJFInitializable initor  = JFHubCenter.Instance.InitorManager[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()];
            Type             devType = initor.GetType();

            if (!typeof(IJFConfigUIProvider).IsAssignableFrom(devType))
            {
                MessageBox.Show(InitorCaption + "对象未提供参数配置界面!");
                return;
            }

            (initor as IJFConfigUIProvider).ShowCfgDialog();
        }
Example #13
0
        /// <summary>
        /// 从系统中删除一个单相机视觉示教助手
        /// </summary>
        /// <param name="name"></param>
        public void DelSVAssist(string name)
        {
            if (!ContainSVAssistName(name))
            {
                return;
            }
            IJFInitializable initor = JFHubCenter.Instance.InitorManager.GetInitor(name);

            if (typeof(JFSingleVisionAssist) != initor.GetType())
            {
                throw new Exception("DelSVAssist(string name = " + name + ") failed by the initor's type is not JFSingleVisionAssist");
            }
            JFHubCenter.Instance.InitorManager.Remove(name); //从设备管理器中删除
            JFXmlSortedDictionary <string, List <object> > devCfg = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >;

            devCfg.Remove(name);//从设备配置文件中删除
            JFHubCenter.Instance.SystemCfg.NotifyItemChanged(JFHubCenter.CK_InitDevParams);
            JFHubCenter.Instance.SystemCfg.Save();
        }
Example #14
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            IJFInitializable dev    = null;
            JFDevCellInfo    ci     = null;
            string           axisID = GetInitParamValue("轴ID") as string;

            if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisID))
            {
                errorInfo = "参数:\"轴ID\" = " + axisID + " 在设备名称表中不存在";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.Axis, axisID, out dev, out ci, out errorInfo))
            {
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            IJFModule_Motion md = (dev as IJFDevice_MotionDaq).GetMc(ci.ModuleIndex);
            int  err            = 0;
            bool IsServoOn      = (bool)GetInitParamValue("轴是否励磁");

            if (IsServoOn)
            {
                err = md.ServoOn(ci.ChannelIndex);
            }
            else
            {
                err = md.ServoOff(ci.ChannelIndex);
            }
            if (err != 0)
            {
                errorInfo = (IsServoOn ? "励磁使能ON" : "励磁使能OFF") + "失败:" + md.GetErrorInfo(err);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            errorInfo = "Success";
            SetOutputParamValue("执行结果", JFWorkCmdResult.Success);
            return(true);
        }
Example #15
0
        /// <summary>
        /// 只是获取通道对应的设备,不做安全性检查(如通道序号是否合法/设备是否已经打开...)
        /// </summary>
        /// <returns></returns>
        public IJFDevice Device()
        {
            JFDevCellInfo ci = CellInfo();

            if (null == ci)
            {
                return(null);
            }
            IJFInitializable initor = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID);

            switch (CellType)
            {
            case JFDevCellType.DI:
                return(initor as IJFDevice_MotionDaq);

            case JFDevCellType.DO:
                return(initor as IJFDevice_MotionDaq);

            case JFDevCellType.Axis:
                return(initor as IJFDevice_MotionDaq);

            case JFDevCellType.AI:
                return(initor as IJFDevice_MotionDaq);

            case JFDevCellType.AO:
                return(initor as IJFDevice_MotionDaq);

            case JFDevCellType.CmpTrig:
                return(initor as IJFDevice_MotionDaq);

            case JFDevCellType.Light:
                return(initor as IJFDevice_LightController);

            case JFDevCellType.Trig:
                return(initor as IJFDevice_TrigController);

            default:
                break;
            }
            return(null);
        }
Example #16
0
        public int ClearImageQueue(string cmrName, out string errMsg)
        {
            IJFInitializable dev = null;
            JFDevCellInfo    ci  = null;

            errMsg = "";

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.Cmr, cmrName, out dev, out ci, out errMsg))
            {
                return((int)ErrorDef.InvokeFailed);
            }

            IJFDevice_Camera cmr = (dev as IJFDevice_Camera);
            int errCode          = cmr.ClearBuff();

            if (errCode != (int)ErrorDef.Success)
            {
                errMsg = cmr.GetErrorInfo(errCode);
                return(errCode);
            }
            return((int)ErrorDef.Success);
        }
Example #17
0
        /// <summary>
        /// 将初始化参数加载到界面上
        /// </summary>
        void InitParam2UI()
        {
            if (null == _method)
            {
                return;
            }
            if (!(_method is IJFInitializable))
            {
                return;
            }
            IJFInitializable initor = _method as IJFInitializable;

            string[] initName = initor.InitParamNames;
            if (null == initName)
            {
                return;
            }
            for (int i = 0; i < initName.Length; i++)
            {
                _lstUcParam[i].SetParamValue(initor.GetInitParamValue(initName[i]));
            }
        }
Example #18
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            string axisID = GetInitParamValue("轴ID") as string;

            if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisID))
            {
                errorInfo = "参数项:\"轴ID\" = " + axisID + " 在设备名称表中不存在";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            IJFInitializable dev = null;
            JFDevCellInfo    ci  = null;

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.Axis, axisID, out dev, out ci, out errorInfo))
            {
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }
            IJFModule_Motion md = (dev as IJFDevice_MotionDaq).GetMc(ci.ModuleIndex);
            //if(!md.IsSVO(ci.ChannelIndex)) //HTM控制卡在未上电时,调用Stop会异常退出
            //{
            //    errorInfo = "\"轴ID\" = " + axisID + " 未励磁";
            //    SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
            //    return true;
            //}
            int errCode = md.StopAxis(ci.ChannelIndex);

            if (errCode != 0)
            {
                errorInfo = md.GetErrorInfo(errCode);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            errorInfo = "Success";
            SetOutputParamValue("执行结果", JFWorkCmdResult.Success);
            return(true);
        }
Example #19
0
        /// <summary>
        /// 注册一个工站(不可删除),
        /// 在Application.Run()运行之前调用
        /// </summary>
        /// <param name="station"></param>
        public void DeclearStation(IJFStation station)
        {
            if (station == null)
            {
                throw new ArgumentNullException("StationManager.DeclearStation(IJFStation station) failed by station = null");
            }
            //if (_lstDeclearStations.Contains(station))
            //    throw new ArgumentException("StationManager.DeclearStation(IJFStation station) failed by station is already decleared!");
            string name = station.Name;

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("StationManager.DeclearStation(IJFStation station) failed by station's Name null or empty");
            }
            if (_initorStationNames().Contains(name))
            {
                IJFInitializable existedStation = JFHubCenter.Instance.InitorManager.GetInitor(name);
                if (existedStation.GetType() != station.GetType())
                {
                    throw new Exception("StationManager.DeclearStation(IJFStation station) failed by:Exist a station with same name and type unmatched: Decleared Type = " + station.GetType() + " ; Existed Type = " + existedStation.GetType());
                }
                (existedStation as IJFStation).Name = name;
                DeclearedStationNames.Add(station.Name);
                //station.WorkStatusChanged += StationWorkStatusChanged;
                //station.CustomStatusChanged += StationCustomStatusChanged;
                //if(station is JFCmdWorkBase)
                //    (station as JFCmdWorkBase).WorkMsg2Outter += StationTxtMsg;
                return;
                //throw new ArgumentException("StationManager.DeclearStation(IJFStation station) failed by station's Name = \"" + name + "\" is exsited in InitorStation-List!");
            }

            JFHubCenter.Instance.InitorManager.Add(station.Name, station);
            DeclearedStationNames.Add(station.Name);
            //station.WorkStatusChanged += StationWorkStatusChanged;
            //station.CustomStatusChanged += StationCustomStatusChanged;
            //if (station is JFCmdWorkBase)
            //    (station as JFCmdWorkBase).WorkMsg2Outter += StationTxtMsg;
        }
Example #20
0
        private void FormDevMgr_Load(object sender, EventArgs e)
        {
            isEditting        = false;
            btCancel.Enabled  = false;
            btInit.Enabled    = false;
            btRemove.Enabled  = false;
            btDebug.Enabled   = false;
            btCfg.Enabled     = false;
            chkSelfUI.Enabled = false;
            ///加载现有设备到列表中
            dgvDevs.Rows.Clear();
            string[] devIDs = JFHubCenter.Instance.InitorManager.GetIDs(InitorType);
            foreach (string devID in devIDs)
            {
                IJFInitializable        dev    = JFHubCenter.Instance.InitorManager[devID];
                DataGridViewRow         row    = new DataGridViewRow();
                DataGridViewTextBoxCell cellID = new DataGridViewTextBoxCell();
                cellID.Value = devID;
                row.Cells.Add(cellID);

                DataGridViewTextBoxCell cellModel = new DataGridViewTextBoxCell();
                cellModel.Value = JFinitializerHelper.DispalyTypeName(dev.GetType());
                row.Cells.Add(cellModel);
                DataGridViewTextBoxCell cellType = new DataGridViewTextBoxCell();
                cellType.Value = dev.GetType().Name;
                row.Cells.Add(cellType);
                dgvDevs.Rows.Add(row);
                if (!dev.IsInitOK)
                {
                    row.DefaultCellStyle.ForeColor = Color.Red;
                }
            }

            dgvDevs.ClearSelection();
            RemoveAllPEs();
        }
Example #21
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            IJFInitializable dev    = null;
            JFDevCellInfo    ci     = null;
            string           axisID = GetInitParamValue("轴ID") as string;

            if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisID))
            {
                errorInfo = "参数项:\"轴ID\" = " + axisID + " 在设备名称表中不存在";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.Axis, axisID, out dev, out ci, out errorInfo))
            {
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }
            JFHomeParam hp = (JFHomeParam)GetInitParamValue("轴归零参数");

            /*
             * 归零模式  0:使用Org(原点)作为归零参考   1:使用限位信号作为归零参考   2:仅使用EZ信号作为归零参考
             */
            if (hp.mode != 0 && hp.mode != 1 && hp.mode != 2 && hp.mode != -1 && hp.mode != -2)
            {
                errorInfo = "归零模式设置错误,mode=" + hp.mode;
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (hp.acc <= 0)
            {
                errorInfo = "加速度/减速度acc <= 0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (hp.vm <= 0)
            {
                errorInfo = "最大速度参数vm <= 0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (hp.vo <= 0)
            {
                errorInfo = "寻找原点速度vo <= 0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (hp.va <= 0)
            {
                errorInfo = "接近速度va <= 0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (hp.shift < 0)
            {
                errorInfo = "回零偏移量sift < 0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (hp.offset < 0)
            {
                errorInfo = "回零补偿值offset < 0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            IJFModule_Motion md = (dev as IJFDevice_MotionDaq).GetMc(ci.ModuleIndex);
            int errCode         = md.SetHomeParam(ci.ChannelIndex, hp);

            if (errCode < 0)
            {
                errorInfo = "SDK调用出错:" + md.GetErrorInfo(errCode);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }
            errorInfo = "Success";
            SetOutputParamValue("执行结果", JFWorkCmdResult.Success);
            return(true);
        }
Example #22
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            IJFInitializable dev    = null;
            JFDevCellInfo    ci     = null;
            string           axisID = GetInitParamValue("轴ID") as string;

            if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisID))
            {
                errorInfo = "参数:\"轴ID\" = " + axisID + " 在设备名称表中不存在";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.Axis, axisID, out dev, out ci, out errorInfo))
            {
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            IJFModule_Motion md = (dev as IJFDevice_MotionDaq).GetMc(ci.ModuleIndex);

            bool[] AxisStatus = null;
            int    err        = md.GetMotionStatus(ci.ChannelIndex, out AxisStatus);

            if (err != 0)
            {
                errorInfo = "开始运动前检测轴状态失败:" + md.GetErrorInfo(err);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            //if(md.IsSVO)
            if (!AxisStatus[md.MSID_SVO])
            {
                errorInfo = "轴伺服未上电";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (AxisStatus[md.MSID_ALM])
            {
                errorInfo = "轴伺服已报警";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (!AxisStatus[md.MSID_MDN])
            {
                errorInfo = "轴当前运动未完成";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            double dPos      = Convert.ToDouble(GetInitParamValue("目标位置"));
            bool   IsAbsMove = Convert.ToBoolean(GetInitParamValue("绝对位置模式"));

            if (IsAbsMove)
            {
                err = md.AbsMove(ci.ChannelIndex, dPos);
            }
            else
            {
                err = md.RelMove(ci.ChannelIndex, dPos);
            }
            if (err != 0)
            {
                errorInfo = (IsAbsMove?"绝对":"相对") + "位置运动失败:" + md.GetErrorInfo(err);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            errorInfo = "Success";
            SetOutputParamValue("执行结果", JFWorkCmdResult.Success);
            return(true);
        }
Example #23
0
        bool isEditting; ///是否处于编辑初始化参数状态
        /// <summary>编辑/保存 初始化参数</summary>
        private void btEditSave_Click(object sender, EventArgs e)
        {
            if (!isEditting)//参数未编辑状态
            {
                if (dgvDevs.SelectedRows == null || 0 == dgvDevs.SelectedRows.Count)
                {
                    MessageBox.Show("请选择需要编辑参数的对象");
                    return;
                }

                if (gbParams.Controls.Count <= 5) //没有初始化参数
                {
                    return;
                }

                for (int i = 5; i < gbParams.Controls.Count; i++)
                {
                    UcJFParamEdit pe = gbParams.Controls[i] as UcJFParamEdit;
                    pe.IsValueReadOnly = false;
                }

                dgvDevs.Enabled  = false;
                btEditSave.Text  = "保存";
                btCancel.Enabled = true;
                btInit.Enabled   = false;
                btAdd.Enabled    = false;
                btRemove.Enabled = false;
                btDebug.Enabled  = false;
                isEditting       = true;
            }
            else //编辑完成,需要存储编辑后的参数
            {
                IJFInitializable dev        = JFHubCenter.Instance.InitorManager[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()];
                List <object>    initParams = new List <object>();
                initParams.Add(dev.GetType().AssemblyQualifiedName);//DevType
                for (int i = 5; i < gbParams.Controls.Count; i++)
                {
                    object        paramVal = null;
                    UcJFParamEdit pe       = gbParams.Controls[i] as UcJFParamEdit;
                    if (!pe.GetParamValue(out paramVal))
                    {
                        pe.Focus();
                        MessageBox.Show("参数\"" + dev.InitParamNames[i - 5] + "\"格式错误:" + pe.GetParamErrorInfo());
                        return;
                    }
                    if (!dev.SetInitParamValue(dev.InitParamNames[i - 5], paramVal))
                    {
                        pe.Focus();
                        MessageBox.Show("设置参数\"" + dev.InitParamNames[i - 5] + "\"失败:" + dev.GetInitErrorInfo());
                        return;
                    }
                    //initParams.Add(paramVal); //替换为以下代码,适应数组/基类型混编的参数列表



                    //paramsInCfg.Add(dev.GetInitParamValue(dev.InitParamNames[i])); 本行代码用以下代码代替,以支持有限的 简单类型 + 数组(列表)类型的组合
                    //暂时的解决方法:将数组类型转化为字符串存储
                    Type paramType = dev.GetInitParamDescribe(dev.InitParamNames[i - 5]).ParamType;
                    SerializableAttribute[] sas = paramType.GetCustomAttributes(typeof(SerializableAttribute), false) as SerializableAttribute[];
                    if (sas != null && sas.Length > 0)     //如果是可序列化的类型,直接保存序列化后的文本
                    {
                        StringBuilder buffer     = new StringBuilder();
                        XmlSerializer serializer = new XmlSerializer(paramType);
                        using (TextWriter writer = new StringWriter(buffer))
                        {
                            serializer.Serialize(writer, paramVal);
                        }
                        string xmlTxt = buffer.ToString();
                        initParams.Add(xmlTxt); // paramsInCfg.Add(xmlTxt);
                    }
                    else
                    {
                        if (paramType.IsValueType || paramType == typeof(string))     //单值对象和字符串对象直接添加
                        {
                            initParams.Add(paramVal);
                        }
                        else                       //目前支持Array 和 List
                        {
                            if (paramType.IsArray) //参数类型是数组
                            {
                                if (null == paramVal)
                                {
                                    initParams.Add("");
                                }
                                else
                                {
                                    StringBuilder sb          = new StringBuilder();
                                    string        splitString = "$";
                                    for (int j = 0; j < (paramVal as Array).Length; j++)
                                    {
                                        sb.Append((paramVal as Array).GetValue(j).ToString());
                                        if (j < (paramVal as Array).Length - 1)
                                        {
                                            sb.Append(splitString);
                                        }
                                    }
                                    initParams.Add(sb.ToString());//paramsInCfg.Add(string.Join(splitString, paramVal)); //使用ASC 响铃符作为间隔
                                }
                            }
                            else if (typeof(IList).IsAssignableFrom(paramType))     //除了数组之外的队列类型
                            {
                                if (null == paramVal)
                                {
                                    initParams.Add("");
                                }
                                else
                                {
                                    StringBuilder sb          = new StringBuilder();
                                    string        splitString = "$";
                                    for (int j = 0; j < (paramVal as IList).Count; j++)
                                    {
                                        sb.Append((paramVal as IList)[j].ToString());
                                        if (j < (paramVal as IList).Count - 1)
                                        {
                                            sb.Append(splitString);
                                        }
                                    }
                                    initParams.Add(sb.ToString());
                                    //paramsInCfg.Add(string.Join(System.Text.Encoding.ASCII.GetString(new byte[] { 0x07 }), paramVal)); //使用ASC 响铃符作为间隔
                                }
                            }
                        }
                    }
                }
                for (int i = 5; i < gbParams.Controls.Count; i++)
                {
                    UcJFParamEdit pe = gbParams.Controls[i] as UcJFParamEdit;
                    pe.IsValueReadOnly = true;
                }
                if (!dev.Initialize())
                {
                    MessageBox.Show("用当前参数初始化设备失败:" + dev.GetInitErrorInfo());
                }
                JFXmlSortedDictionary <string, List <object> > devCfg = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >;
                devCfg[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()] = initParams;
                JFHubCenter.Instance.SystemCfg.NotifyItemChanged(JFHubCenter.CK_InitDevParams);
                JFHubCenter.Instance.SystemCfg.Save();

                btInit.Enabled   = true;
                btAdd.Enabled    = true;
                btRemove.Enabled = true;
                //btDebug.Enabled = true;

                isEditting       = false;
                btEditSave.Text  = "编辑参数";
                btCancel.Enabled = false;
                dgvDevs.Enabled  = true;


                Type devType = dev.GetType();
                if (typeof(IJFDevice_Camera).IsAssignableFrom(devType) ||
                    typeof(IJFDevice_LightController).IsAssignableFrom(devType) ||
                    typeof(IJFDevice_MotionDaq).IsAssignableFrom(devType) ||
                    typeof(IJFDevice_TrigController).IsAssignableFrom(devType) ||
                    typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) //提供调试界面
                {
                    btDebug.Enabled = true;
                    if (typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType))
                    {
                        chkSelfUI.Enabled = true;
                    }
                    else
                    {
                        chkSelfUI.Checked = false;
                        chkSelfUI.Enabled = false;
                    }
                }
                else
                {
                    btDebug.Enabled = false;
                }

                if (typeof(IJFConfigUIProvider).IsAssignableFrom(devType))
                {
                    btCfg.Enabled = true;
                }
                else
                {
                    btCfg.Enabled = false;
                }
            }
        }
Example #24
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            IJFInitializable dev    = null;
            JFDevCellInfo    ci     = null;
            string           axisID = GetInitParamValue("轴ID") as string;

            if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisID))
            {
                errorInfo = "参数项:\"轴ID\" = " + axisID + " 在设备名称表中不存在";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.Axis, axisID, out dev, out ci, out errorInfo))
            {
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            bool   isPositive = (bool)GetInitParamValue("正向移动");
            double velocity   = Convert.ToDouble(GetInitParamValue("移动速度"));

            IJFModule_Motion md = (dev as IJFDevice_MotionDaq).GetMc(ci.ModuleIndex);

            bool[] AxisStatus = null;
            int    err        = md.GetMotionStatus(ci.ChannelIndex, out AxisStatus);

            if (err != 0)
            {
                errorInfo = "开始运动前检测轴状态失败:" + md.GetErrorInfo(err);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            //if(md.IsSVO)
            if (!AxisStatus[md.MSID_SVO])
            {
                errorInfo = "轴伺服未上电";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (AxisStatus[md.MSID_ALM])
            {
                errorInfo = "轴伺服已报警";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (!AxisStatus[md.MSID_MDN])
            {
                errorInfo = "轴当前运动未完成";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            int errCode = md.VelMove(ci.ChannelIndex, velocity, isPositive);

            if (errCode < 0)
            {
                errorInfo = "SDK调用出错:" + md.GetErrorInfo(errCode);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            errorInfo = "Success";
            SetOutputParamValue("执行结果", JFWorkCmdResult.Success);
            return(true);
        }
Example #25
0
        /// <summary>选择设备</summary>
        private void dgvDevs_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgvDevs.SelectedRows.Count == 0)
            {
                return;
            }
            btRemove.Enabled = true;
            RemoveAllPEs();

            DataGridViewRow  row     = dgvDevs.SelectedRows[0];
            IJFInitializable dev     = JFHubCenter.Instance.InitorManager[row.Cells[0].Value.ToString()];
            Type             devType = dev.GetType();

            if (typeof(IJFDevice_Camera).IsAssignableFrom(devType) ||
                typeof(IJFDevice_LightController).IsAssignableFrom(devType) ||
                typeof(IJFDevice_MotionDaq).IsAssignableFrom(devType) ||
                typeof(IJFDevice_TrigController).IsAssignableFrom(devType) ||
                typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) //提供调试界面
            {
                btDebug.Enabled = true;
                if (typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType))
                {
                    chkSelfUI.Enabled = true;
                }
                else
                {
                    chkSelfUI.Checked = false;
                    chkSelfUI.Enabled = false;
                }
            }
            else
            {
                btDebug.Enabled = false;
            }

            if (typeof(IJFConfigUIProvider).IsAssignableFrom(devType))
            {
                btCfg.Enabled = true;
            }
            else
            {
                btCfg.Enabled = false;
            }



            tbDevID.Text   = row.Cells[0].Value.ToString();
            btInit.Enabled = !dev.IsInitOK;
            string[] iniParamNames = dev.InitParamNames;
            if (null == iniParamNames)
            {
                btEditSave.Enabled = false;
                return;
            }
            btEditSave.Enabled = true;
            int locY = btInit.Location.Y + btInit.Size.Height + 5;

            foreach (string ipName in iniParamNames)
            {
                UcJFParamEdit pe = new UcJFParamEdit();
                pe.Width    = gbParams.Width - 1;
                pe.Location = new Point(4, locY);
                pe.SetParamDesribe(dev.GetInitParamDescribe(ipName));
                locY += pe.Height;
                pe.SetParamValue(dev.GetInitParamValue(ipName));
                pe.IsValueReadOnly = true;
                gbParams.Controls.Add(pe);
            }
        }
Example #26
0
        /// <summary>
        /// 检查设备通道是否存在并且可用
        /// </summary>
        /// <param name="category"></param>
        /// <param name="cellName"></param>
        /// <param name="initor"></param>
        /// <param name="cellInfo"></param>
        /// <param name="errorInfo"></param>
        /// <returns></returns>
        public static bool CheckDevCellName(string category, string cellName, out IJFInitializable initor, out JFDevCellInfo ci, out string errorInfo)
        {
            initor    = null;
            ci        = null;
            errorInfo = null;

            if (string.IsNullOrEmpty(cellName))
            {
                errorInfo = "参数项\"cellName\"为空";
                return(false);
            }
            JFDevCellNameManeger nameMgr   = JFHubCenter.Instance.MDCellNameMgr;
            JFInitorManager      initorMgr = JFHubCenter.Instance.InitorManager;
            JFDevCellInfo        cellInfo  = null;

            if (category == DO) //获取数字量输出通道信息
            {
                cellInfo = nameMgr.GetDoCellInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在DO:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq ";
                    return(false);
                }

                IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq;
                if (!md.IsInitOK)
                {
                    errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ModuleIndex >= md.DioCount)
                {
                    errorInfo = "DO:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备DIO模块数量: " + md.DioCount;
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.GetDio(cellInfo.ModuleIndex).DOCount)
                {
                    errorInfo = "DO:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出模块DO通道数量: " + md.GetDio(cellInfo.ModuleIndex).DOCount;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == DI) //获取数字量输入
            {
                cellInfo = nameMgr.GetDiCellInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在DI:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq ";
                    return(false);
                }

                IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq;
                if (!md.IsInitOK)
                {
                    errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ModuleIndex >= md.DioCount)
                {
                    errorInfo = "DI:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备DIO模块数量: " + md.DioCount;
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.GetDio(cellInfo.ModuleIndex).DICount)
                {
                    errorInfo = "DI:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出模块DI通道数量: " + md.GetDio(cellInfo.ModuleIndex).DOCount;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == AI)
            {
            }
            else if (category == AO)
            {
            }
            else if (category == Axis)
            {
                cellInfo = nameMgr.GetAxisCellInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在Axis:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq ";
                    return(false);
                }

                IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq;
                if (!md.IsInitOK)
                {
                    errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ModuleIndex >= md.McCount)
                {
                    errorInfo = "Axis:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备轴模块数量: " + md.McCount;
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.GetMc(cellInfo.ModuleIndex).AxisCount)
                {
                    errorInfo = "Axis:\"" + cellName + "\" Channel = :" + cellInfo.ModuleIndex + "超出模块轴通道数量: " + md.GetMc(cellInfo.ModuleIndex).AxisCount;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == CmpTrig)
            {
                cellInfo = nameMgr.GetCmpTrigCellInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在CmpTrig:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq ";
                    return(false);
                }

                IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq;
                if (!md.IsInitOK)
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ModuleIndex >= md.CompareTriggerCount)
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备比较触发模块数量: " + md.CompareTriggerCount;
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.GetCompareTrigger(cellInfo.ModuleIndex).EncoderChannels)
                {
                    errorInfo = "CmpTrig:\"" + cellName + "\" Channel = :" + cellInfo.ModuleIndex + "超出模块比较触发通道数量: " + md.GetCompareTrigger(cellInfo.ModuleIndex).EncoderChannels;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == LightCtrl)
            {
                cellInfo = nameMgr.GetLightCtrlChannelInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在LightCtrl:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_LightController).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是IJFDevice_LightController ";
                    return(false);
                }

                IJFDevice_LightController md = dev as IJFDevice_LightController;
                if (!md.IsInitOK)
                {
                    errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.LightChannelCount)
                {
                    errorInfo = "LightCtrl:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出设备光源通道数量: " + md.LightChannelCount;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == LightTrig)
            {
                cellInfo = nameMgr.GetTrigCtrlChannelInfo(cellName);
                if (null == cellInfo)
                {
                    errorInfo = "设备命名表中不存在LightTrig:" + cellName;
                    return(false);
                }

                IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID);
                if (null == dev)
                {
                    errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_TrigController).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是IJFDevice_TrigController ";
                    return(false);
                }

                IJFDevice_TrigController md = dev as IJFDevice_TrigController;
                if (!md.IsInitOK)
                {
                    errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 ";
                    return(false);
                }

                if (!md.IsDeviceOpen)
                {
                    errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 ";
                    return(false);
                }

                if (cellInfo.ChannelIndex >= md.TrigChannelCount)
                {
                    errorInfo = "LightTrig:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出设备触发通道数量: " + md.TrigChannelCount;
                    return(false);
                }
                initor    = dev;
                ci        = cellInfo;
                errorInfo = "Success";
                return(true);
            }
            else if (category == Cmr)
            {
                IJFInitializable dev = initorMgr.GetInitor(cellName);
                if (null == dev)
                {
                    errorInfo = "Camera:\"" + cellName + "\" 在设备列表中不存在";
                    return(false);
                }

                if (!typeof(IJFDevice_Camera).IsAssignableFrom(dev.GetType()))
                {
                    errorInfo = "Camera:\"" + cellName + "\" 设备类型不是IJFDevice_Camera ";
                    return(false);
                }
                initor    = dev;
                errorInfo = "Success";
                return(true);
            }
            else
            {
                errorInfo = "不支持的参数项\"category\" = " + category;
            }
            return(false);
        }
Example #27
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            string[] axisIDList = GetInitParamValue("轴ID列表") as string[];
            double[] dPosList   = GetMethodInputValue("目标位置列表") as double[];
            bool     IsAbsMove  = (bool)GetMethodInputValue("绝对位置模式");

            if (axisIDList == null || dPosList == null)
            {
                errorInfo = "轴ID列表长度或者目标位置列表长度为空";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            int[] iaxisIDList = new int[axisIDList.Length];
            if (axisIDList.Length <= 0)
            {
                errorInfo = "轴ID列表长度<=0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (dPosList.Length <= 0)
            {
                errorInfo = "目标位置列表<=0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (axisIDList.Length != dPosList.Length)
            {
                errorInfo = "轴ID列表长度为" + axisIDList.ToString() + "与目标列表长度" + dPosList.Length.ToString() + "不一致。";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            IJFInitializable     dev        = null;
            IJFInitializable     devbuff    = null;
            JFDevCellInfo        ci         = null;
            List <JFDevCellInfo> cibuffList = new List <JFDevCellInfo>();

            for (int m = 0; m < axisIDList.Length; m++)
            {
                if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisIDList[m]))
                {
                    errorInfo = "参数项:\"轴ID\" = " + axisIDList[m] + " 在设备名称表中不存在";
                    SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                    return(false);
                }
                if (!JFCMFunction.CheckDevCellName(JFCMFunction.Axis, axisIDList[m], out dev, out ci, out errorInfo))
                {
                    SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                    return(false);
                }
                iaxisIDList[m] = ci.ChannelIndex;
                if (devbuff != null)
                {
                    if (devbuff != dev)
                    {
                        errorInfo = "轴ID列表中的所有轴并不来源于同一个设备";
                        SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                        return(false);
                    }
                }
                devbuff = dev;

                if (cibuffList.Contains(ci))
                {
                    errorInfo = "轴ID列表中存在重复的轴名称";
                    SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                    return(false);
                }
                cibuffList.Add(ci);
            }

            IJFModule_Motion md = (dev as IJFDevice_MotionDaq).GetMc(ci.ModuleIndex);

            bool[] AxisStatus = null;
            int    err        = md.GetMotionStatus(ci.ChannelIndex, out AxisStatus);

            if (err != 0)
            {
                errorInfo = "开始运动前检测轴状态失败:" + md.GetErrorInfo(err);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            //if(md.IsSVO)
            if (!AxisStatus[md.MSID_SVO])
            {
                errorInfo = "轴伺服未上电";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (AxisStatus[md.MSID_ALM])
            {
                errorInfo = "轴伺服已报警";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (!AxisStatus[md.MSID_MDN])
            {
                errorInfo = "轴当前运动未完成";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (IsAbsMove)
            {
                err = md.AbsLine(iaxisIDList, dPosList);
            }
            else
            {
                err = md.RelLine(iaxisIDList, dPosList);
            }
            if (err != 0)
            {
                errorInfo = (IsAbsMove ? "绝对" : "相对") + "直线插补运动失败:" + md.GetErrorInfo(err);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            errorInfo = "Success";
            SetOutputParamValue("执行结果", JFWorkCmdResult.Success);
            return(true);
        }
Example #28
0
        void AdjustView()
        {
            timerFlush.Enabled = false;
            tpRealtime.Controls.Clear();
            tpInitCfg.Controls.Clear();
            _lstUcParam.Clear();
            if (null == _method)
            {
                Label lb1 = new Label();
                lb1.Text = "方法对象未设置";
                tpRealtime.Controls.Add(lb1);
                Label lb2 = new Label();
                lb2.Text = "方法对象未设置";
                tpInitCfg.Controls.Add(lb1);
                return;
            }
            if (_method is IJFRealtimeUIProvider)
            {
                JFRealtimeUI ui = (_method as IJFRealtimeUIProvider).GetRealtimeUI();
                if (null != ui)
                {
                    ui.Dock = DockStyle.Fill;
                    tpRealtime.Controls.Add(ui);
                    timerFlush.Enabled = true;
                }
            }
            else
            {
                UcCommonMethodRtUi ui = new UcCommonMethodRtUi();
                ui.Dock = DockStyle.Fill;
                ui.SetMethod(_method);
                tpRealtime.Controls.Add(ui);
                timerFlush.Enabled = true;
            }

            int locX = 3, locY = 3;

            if (_method is IJFConfigUIProvider)//提供参数配置界面
            {
                Button btShowCfg = new Button();
                btShowCfg.Text     = "参数配置";
                btShowCfg.Location = new Point(locX, locY);
                tpInitCfg.Controls.Add(btShowCfg);
                btShowCfg.Click += OnButtonClick_ShowCfgUI;
                locY             = btShowCfg.Bottom + 2;
            }

            if (_method is IJFInitializable)//初始参数可序列化对象
            {
                IJFInitializable initor    = _method as IJFInitializable;
                string[]         initNames = initor.InitParamNames;
                if (null != initNames && initNames.Length > 0)
                {
                    isInitParamEditting    = false;
                    btSetSaveInit          = new Button();
                    btSetSaveInit.Text     = "编辑初始化参数";
                    btSetSaveInit.Location = new Point(locX, locY);
                    btSetSaveInit.Click   += OnButtonClick_InitParamSetSave;
                    tpInitCfg.Controls.Add(btSetSaveInit);

                    btCancelInit          = new Button();
                    btCancelInit.Text     = "取消";
                    btCancelInit.Location = new Point(btSetSaveInit.Right + 2, locY);
                    btCancelInit.Click   += OnButtonClick_InitParamCancel;
                    tpInitCfg.Controls.Add(btCancelInit);
                    btCancelInit.Enabled = false;
                    locY = btCancelInit.Bottom + 2;
                    for (int i = 0; i < initNames.Length; i++)
                    {
                        string          initName = initNames[i];
                        JFParamDescribe pd       = initor.GetInitParamDescribe(initName);
                        UcJFParamEdit   ucParam  = new UcJFParamEdit();
                        ucParam.Width    = tpInitCfg.Width - 100;
                        ucParam.Location = new Point(locX, locY);
                        ucParam.SetParamDesribe(pd);
                        ucParam.SetParamValue(initor.GetInitParamValue(initName));
                        ucParam.IsValueReadOnly = true;
                        _lstUcParam.Add(ucParam);
                        tpInitCfg.Controls.Add(ucParam);

                        ucParam.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                        locY           = ucParam.Bottom + 2;
                    }

                    InitParam2UI();
                }
            }
        }
        protected override bool ActionGenuine(out string errorInfo)
        {
            IJFInitializable dev    = null;
            JFDevCellInfo    ci     = null;
            string           axisID = GetInitParamValue("轴ID") as string;

            if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisID))
            {
                errorInfo = "参数项:\"轴ID\" = " + axisID + " 在设备名称表中不存在";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.Axis, axisID, out dev, out ci, out errorInfo))
            {
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }
            JFMotionParam mp = (JFMotionParam)GetInitParamValue("运动参数");

            /*
             * public double vs { get; set; }
             * /// <summary>最大速度</summary>
             * public double vm { get; set; }
             * /// <summary>结束速度</summary>
             * public double ve { get; set; }
             * /// <summary>加速度</summary>
             * public double acc { get; set; }
             * /// <summary>减速度</summary>
             * public double dec { get; set; }
             * /// <summary>s曲线因子(0~1.0)</summary>
             * public double curve { get; set; }
             * /// <summary>加加速</summary>
             * public double jerk { get; set; }
             */
            if (mp.vs < 0)
            {
                errorInfo = "起始速度参数vs < 0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (mp.vm <= 0)
            {
                errorInfo = "运行速度参数vm <= 0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (mp.ve < 0)
            {
                errorInfo = "终点速度参数ve < 0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (mp.acc <= 0)
            {
                errorInfo = "加速度参数acc <= 0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (mp.dec <= 0)
            {
                errorInfo = "减速度参数dec <= 0";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            if (mp.curve < 0 || mp.curve > 1)
            {
                errorInfo = "加速度曲线段系数不在允许范围0~1";
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            IJFModule_Motion md = (dev as IJFDevice_MotionDaq).GetMc(ci.ModuleIndex);
            int errCode         = md.SetMotionParam(ci.ChannelIndex, mp);

            if (errCode < 0)
            {
                errorInfo = "SDK调用出错:" + md.GetErrorInfo(errCode);
                SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError);
                return(false);
            }

            errorInfo = "Success";
            SetOutputParamValue("执行结果", JFWorkCmdResult.Success);
            return(true);
        }
Example #30
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            string chnID     = GetMethodInputValue("光源通道ID") as string;
            int    intensity = (int)GetMethodInputValue("光照强度");

            if (string.IsNullOrEmpty(chnID))
            {
                errorInfo = "输入参数项:\"光源通道ID\" 为空字串";
                return(false);
            }
            if (!JFHubCenter.Instance.MDCellNameMgr.ContainLightChannelName(chnID))
            {
                errorInfo = "输入参数项:\"光源通道ID\"  = " + chnID + " 在设备名称表中不存在";
                return(false);
            }

            if (intensity < 0)
            {
                errorInfo = "输入参数项:\"光照强度\"  = " + intensity + " 为无效值(参数值必须>=0)";
                return(false);
            }

            bool isAutoSwitchMode = (bool)GetInitParamValue("自动切换到开关模式");
            bool isAutoEnable     = (bool)GetInitParamValue("自动使能");


            IJFInitializable dev     = null;
            JFDevCellInfo    ci      = null;
            string           errInfo = null;

            if (!JFCMFunction.CheckDevCellName(JFCMFunction.LightCtrl, chnID, out dev, out ci, out errInfo))
            {
                errorInfo = errInfo;
                return(false);
            }

            int errCode = 0;
            IJFDevice_LightController devLight = dev as IJFDevice_LightController;

            if (typeof(IJFDevice_LightControllerWithTrig).IsAssignableFrom(devLight.GetType())) //如果当前设备带有触发功能
            {
                IJFDevice_LightControllerWithTrig devLT = devLight as IJFDevice_LightControllerWithTrig;
                JFLightWithTrigWorkMode           wm;
                errCode = devLT.GetWorkMode(out wm);
                if (errCode != 0)
                {
                    errorInfo = "获取光源控制器工作模式失败:" + devLT.GetErrorInfo(errCode);
                    return(false);
                }

                if (wm == JFLightWithTrigWorkMode.Trigger) //当前处于触发模式
                {
                    if (!isAutoSwitchMode)
                    {
                        errorInfo = "控制器当前为触发模式";
                        return(false);
                    }

                    errCode = devLT.SetWorkMode(JFLightWithTrigWorkMode.TurnOnOff);
                    if (errCode != 0)
                    {
                        errorInfo = "控制器切换工作模式失败:" + devLT.GetErrorInfo(errCode);
                        return(false);
                    }
                }
            }

            bool isLightChnEnabled = false;

            errCode = devLight.GetLightChannelEnable(ci.ChannelIndex, out isLightChnEnabled);
            if (0 != errCode)
            {
                errorInfo = "获取通道使能状态失败:" + devLight.GetErrorInfo(errCode);
                return(false);
            }
            if (!isLightChnEnabled)
            {
                if (!isAutoEnable)
                {
                    errorInfo = "光源通道未使能";
                    return(false);
                }
                errCode = devLight.SetLightChannelEnable(ci.ChannelIndex, true);
                if (errCode != 0)
                {
                    errorInfo = "光源通道使能失败:" + devLight.GetErrorInfo(errCode);
                    return(false);
                }
            }

            errCode = devLight.SetLightIntensity(ci.ChannelIndex, intensity);
            if (errCode != 0)
            {
                errorInfo = "设置光照强度失败:" + devLight.GetErrorInfo(errCode);
                return(false);
            }
            errorInfo = "Success";
            return(true);
        }